diff --git a/builders/build.yaml b/builders/build.yaml index 410541ea7..106f323ad 100644 --- a/builders/build.yaml +++ b/builders/build.yaml @@ -115,30 +115,30 @@ steps: - 'build-apiserver' # -# app-sync +# appsync # -- id: 'build-app-sync' +- id: 'build-appsync' name: 'golang:1.15.2' args: - 'go' - 'build' - '-trimpath' - '-ldflags=-s -w -X=${_REPO}/pkg/buildinfo.BuildID=${BUILD_ID} -X=${_REPO}/pkg/buildinfo.BuildTag=${_TAG} -extldflags=-static' - - '-o=./bin/app-sync' - - './cmd/app-sync' + - '-o=./bin/appsync' + - './cmd/appsync' waitFor: - 'download-modules' -- id: 'dockerize-app-sync' +- id: 'dockerize-appsync' name: 'docker:19' args: - 'build' - '--file=builders/service.dockerfile' - - '--tag=gcr.io/${PROJECT_ID}/${_REPO}/app-sync:${_TAG}' - - '--build-arg=SERVICE=app-sync' + - '--tag=gcr.io/${PROJECT_ID}/${_REPO}/appsync:${_TAG}' + - '--build-arg=SERVICE=appsync' - '.' waitFor: - - 'build-app-sync' + - 'build-appsync' # # cleanup @@ -296,7 +296,7 @@ steps: images: - 'gcr.io/${PROJECT_ID}/${_REPO}/adminapi:${_TAG}' - 'gcr.io/${PROJECT_ID}/${_REPO}/apiserver:${_TAG}' -- 'gcr.io/${PROJECT_ID}/${_REPO}/app-sync:${_TAG}' +- 'gcr.io/${PROJECT_ID}/${_REPO}/appsync:${_TAG}' - 'gcr.io/${PROJECT_ID}/${_REPO}/cleanup:${_TAG}' - 'gcr.io/${PROJECT_ID}/${_REPO}/e2e-runner:${_TAG}' - 'gcr.io/${PROJECT_ID}/${_REPO}/enx-redirect:${_TAG}' diff --git a/builders/deploy.yaml b/builders/deploy.yaml index a76b53e16..fab285a2a 100644 --- a/builders/deploy.yaml +++ b/builders/deploy.yaml @@ -65,9 +65,9 @@ steps: - '-' # -# app-sync +# appsync # -- id: 'deploy-app-sync' +- id: 'deploy-appsync' name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:307.0.0-alpine' args: - 'bash' @@ -75,12 +75,12 @@ steps: - 'pipefail' - '-c' - |- - gcloud run deploy "app-sync" \ + gcloud run deploy "appsync" \ --quiet \ --project "${PROJECT_ID}" \ --platform "managed" \ --region "${_REGION}" \ - --image "gcr.io/${PROJECT_ID}/${_REPO}/app-sync:${_TAG}" \ + --image "gcr.io/${PROJECT_ID}/${_REPO}/appsync:${_TAG}" \ --no-traffic waitFor: - '-' diff --git a/builders/promote.yaml b/builders/promote.yaml index fea8f4222..4e937e17b 100644 --- a/builders/promote.yaml +++ b/builders/promote.yaml @@ -63,9 +63,9 @@ steps: - '-' # -# app-sync +# appsync # -- id: 'promote-app-sync' +- id: 'promote-appsync' name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:307.0.0-alpine' args: - 'bash' @@ -73,7 +73,7 @@ steps: - 'pipefail' - '-c' - |- - gcloud run services update-traffic "app-sync" \ + gcloud run services update-traffic "appsync" \ --quiet \ --project "${PROJECT_ID}" \ --platform "managed" \ diff --git a/cmd/app-sync/main.go b/cmd/appsync/main.go similarity index 100% rename from cmd/app-sync/main.go rename to cmd/appsync/main.go diff --git a/pkg/controller/appsync/appsync.go b/pkg/controller/appsync/appsync.go index 33c6ede40..9be0d16b9 100644 --- a/pkg/controller/appsync/appsync.go +++ b/pkg/controller/appsync/appsync.go @@ -33,8 +33,8 @@ const playStoreHost = `play.google.com/store/apps/details` // HandleSync performs the logic to sync mobile apps. func (c *Controller) HandleSync() http.Handler { type AppSyncResult struct { - OK bool `json:"ok"` - Errors []error `json:"errors,omitempty"` + OK bool `json:"ok"` + Errors []string `json:"errors,omitempty"` } return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -48,9 +48,19 @@ func (c *Controller) HandleSync() http.Handler { // If there are any errors, return them if merr := c.syncApps(ctx, apps); merr != nil { if errs := merr.WrappedErrors(); len(errs) > 0 { + // Convert error messages to strings to they appear correctly in JSON. + // See here for more information: + // + // https://stackoverflow.com/questions/44989924/golang-error-types-are-empty-when-encoded-to-json + // + errMsgs := make([]string, len(errs)) + for i, err := range errs { + errMsgs[i] = err.Error() + } + c.h.RenderJSON(w, http.StatusInternalServerError, &AppSyncResult{ OK: false, - Errors: errs, + Errors: errMsgs, }) return } @@ -69,7 +79,6 @@ func (c *Controller) syncApps(ctx context.Context, apps *clients.AppsResponse) * appsByRealm := map[uint][]*database.MobileApp{} for _, app := range apps.Apps { - realm, err := c.findRealmForApp(app, realms) if err != nil { merr = multierror.Append(merr, fmt.Errorf("unable to lookup realm for region %q: %w", app.Region, err)) diff --git a/terraform/service_appsync.tf b/terraform/service_appsync.tf index 4b620412c..6cd9857ad 100644 --- a/terraform/service_appsync.tf +++ b/terraform/service_appsync.tf @@ -102,7 +102,7 @@ resource "google_cloud_run_service" "appsync" { service_account_name = google_service_account.appsync.email containers { - image = "gcr.io/${var.project}/github.com/google/exposure-notifications-verification-server/app-sync:initial" + image = "gcr.io/${var.project}/github.com/google/exposure-notifications-verification-server/appsync:initial" resources { limits = {