From 707b7b5413df5099ec9f1cb73939e55e904658f8 Mon Sep 17 00:00:00 2001 From: Aaron Schlesinger <70865+arschles@users.noreply.github.com> Date: Thu, 5 Dec 2019 10:49:56 -0800 Subject: [PATCH] Fixing the build failures from a missing GCS Key (#1480) * Fixing the build failures from a missing GCS Key Accidentally introduced in https://github.com/gomods/athens/pull/1428 * Adding a TODO to the drone build * adding a step to test the Athens server startup * Adding the JSONKey back to the default config * use temporary image * Switching back to the old env var for the GCS JSON Key cc/ @marwan-at-work * removing the ServiceAccount. we want to stick with JSONKey * reverting to original key fetching code * fixing build err * bumping chart ver --- .drone.yml | 3 ++- charts/athens-proxy/Chart.yaml | 2 +- charts/athens-proxy/templates/deployment.yaml | 2 +- config.dev.toml | 9 +++++++-- pkg/config/gcp.go | 6 +++--- pkg/stash/with_gcs_test.go | 4 ++-- pkg/storage/gcp/gcp.go | 4 ++-- pkg/storage/gcp/gcp_test.go | 9 ++++++--- 8 files changed, 24 insertions(+), 15 deletions(-) diff --git a/.drone.yml b/.drone.yml index dfb14a4e..cdab1e94 100644 --- a/.drone.yml +++ b/.drone.yml @@ -33,6 +33,7 @@ steps: # end to end test - ./main & # run the just-built athens server - sleep 3 # wait for it to spin up + - curl localhost:3000 - mkdir -p ~/happy - mkdir -p ~/emptygopath # ensure the gopath has no modules cached. - cd ~/happy @@ -153,7 +154,7 @@ services: ports: - 6379 - name: athens-proxy - image: gomods/athens:canary + image: gomods/athens-dev:221c451 # temporary to make the build pass, revert to gomods/athens:canary after merge. pull: always ports: - 3000 diff --git a/charts/athens-proxy/Chart.yaml b/charts/athens-proxy/Chart.yaml index c988c0c6..1365d6d5 100644 --- a/charts/athens-proxy/Chart.yaml +++ b/charts/athens-proxy/Chart.yaml @@ -1,5 +1,5 @@ name: athens-proxy -version: 0.4.0 +version: 0.4.1 appVersion: 0.7.0 description: The proxy server for Go modules icon: https://raw.githubusercontent.com/gomods/athens/master/docs/static/banner.png diff --git a/charts/athens-proxy/templates/deployment.yaml b/charts/athens-proxy/templates/deployment.yaml index 953200ff..8aeb109f 100644 --- a/charts/athens-proxy/templates/deployment.yaml +++ b/charts/athens-proxy/templates/deployment.yaml @@ -101,7 +101,7 @@ spec: - name: ATHENS_STORAGE_GCP_BUCKET value: {{ .Values.storage.gcp.bucket | quote }} {{- if .Values.storage.gcp.serviceAccount }} - - name: ATHENS_STORAGE_GCP_SERVICE_ACCOUNT + - name: ATHENS_STORAGE_GCP_JSON_KEY value: {{ .Values.storage.gcp.serviceAccount | b64enc | quote }} {{- end }} {{- else if eq .Values.storage.type "minio" }} diff --git a/config.dev.toml b/config.dev.toml index d0b6e96c..f2c72e4b 100755 --- a/config.dev.toml +++ b/config.dev.toml @@ -301,14 +301,19 @@ SingleFlightType = "memory" # Env override: ATHENS_STORAGE_GCP_BUCKET Bucket = "MY_GCP_BUCKET" - # ServiceAccount is a base64 encoded service account + # JSONKey is a base64 encoded service account # key that allows Athens to be run outside of GCP # but still be able to access GCS. If you are # running Athens inside GCP, you will most # likely not need this as GCP figures out # internal authentication between products for you. + # + # NOTE: This config value is deprecated in favor of + # ServiceAccount above. Athens will check for it, + # but please do not rely on it being available forever. + # # Env override: ATHENS_STORAGE_GCP_JSON_KEY - ServiceAccount = "" + JSONKey = "" [Storage.Minio] # Endpoint for Minio storage diff --git a/pkg/config/gcp.go b/pkg/config/gcp.go index 81d41cfc..36321a12 100644 --- a/pkg/config/gcp.go +++ b/pkg/config/gcp.go @@ -2,7 +2,7 @@ package config // GCPConfig specifies the properties required to use GCP as the storage backend type GCPConfig struct { - ProjectID string `envconfig:"GOOGLE_CLOUD_PROJECT"` - Bucket string `validate:"required" envconfig:"ATHENS_STORAGE_GCP_BUCKET"` - ServiceAccount string `envconfig:"ATHENS_STORAGE_GCP_SERVICE_ACCOUNT"` + ProjectID string `envconfig:"GOOGLE_CLOUD_PROJECT"` + Bucket string `validate:"required" envconfig:"ATHENS_STORAGE_GCP_BUCKET"` + JSONKey string `envconfig:"ATHENS_STORAGE_GCP_JSON_KEY"` } diff --git a/pkg/stash/with_gcs_test.go b/pkg/stash/with_gcs_test.go index 57b8a564..89b97da1 100644 --- a/pkg/stash/with_gcs_test.go +++ b/pkg/stash/with_gcs_test.go @@ -121,7 +121,7 @@ func getTestConfig() *config.GCPConfig { return nil } return &config.GCPConfig{ - Bucket: "athens_drone_stash_bucket", - ServiceAccount: creds, + Bucket: "athens_drone_stash_bucket", + JSONKey: creds, } } diff --git a/pkg/storage/gcp/gcp.go b/pkg/storage/gcp/gcp.go index a2524f00..e7429845 100644 --- a/pkg/storage/gcp/gcp.go +++ b/pkg/storage/gcp/gcp.go @@ -49,8 +49,8 @@ func New(ctx context.Context, gcpConf *config.GCPConfig, timeout time.Duration) func newClient(ctx context.Context, gcpConf *config.GCPConfig, timeout time.Duration) (*Storage, error) { const op errors.Op = "gcp.newClient" opts := []option.ClientOption{} - if gcpConf.ServiceAccount != "" { - key, err := base64.StdEncoding.DecodeString(gcpConf.ServiceAccount) + if gcpConf.JSONKey != "" { + key, err := base64.StdEncoding.DecodeString(gcpConf.JSONKey) if err != nil { return nil, errors.E(op, fmt.Errorf("could not decode base64 json key: %v", err)) } diff --git a/pkg/storage/gcp/gcp_test.go b/pkg/storage/gcp/gcp_test.go index a1db8698..b074d20c 100644 --- a/pkg/storage/gcp/gcp_test.go +++ b/pkg/storage/gcp/gcp_test.go @@ -51,6 +51,9 @@ func getStorage(t testing.TB) *Storage { bucketName := randomBucketName(os.Getenv("DRONE_PULL_REQUEST")) cfg := getTestConfig(bucketName) if cfg == nil { + // Don't fail if there's no test config, so that these tests don't + // fail when you run them locally + t.Log("No GCS Config found") t.SkipNow() } @@ -72,9 +75,9 @@ func getTestConfig(bucket string) *config.GCPConfig { return nil } return &config.GCPConfig{ - Bucket: bucket, - ServiceAccount: creds, - ProjectID: os.Getenv("GCS_PROJECT_ID"), + Bucket: bucket, + JSONKey: creds, + ProjectID: os.Getenv("GCS_PROJECT_ID"), } }