diff options
| author | Jamal Carvalho <jamal@golang.org> | 2021-11-30 21:17:33 +0000 |
|---|---|---|
| committer | Jamal Carvalho <jamal@golang.org> | 2021-12-01 17:43:20 +0000 |
| commit | 30aa45b8a04e98bc592ff0db1d6256bcee9b4d30 (patch) | |
| tree | 952c2c870bc05f204bfe78b1a03057a3d1561610 /deploy | |
| parent | de0e75cef33dbf22bda84dc22fcf86405000ae3b (diff) | |
| download | go-x-pkgsite-30aa45b8a04e98bc592ff0db1d6256bcee9b4d30.tar.xz | |
deploy: add migrate build config
This config will be used to run golang-migrate commands
from Cloud Build.
Change-Id: Ia389f772160748dc3f507bdd73fc6233f22afe86
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/367936
Trust: Jamal Carvalho <jamal@golang.org>
Run-TryBot: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Diffstat (limited to 'deploy')
| -rw-r--r-- | deploy/migrate.yaml | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/deploy/migrate.yaml b/deploy/migrate.yaml new file mode 100644 index 00000000..cd7f118b --- /dev/null +++ b/deploy/migrate.yaml @@ -0,0 +1,39 @@ +# Copyright 2021 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +# Run a migrate command on a database + +# Required substitions +# _ENV environment (dev, staging, or prod) +# _CMD command to migrate + +timeout: 1800s +steps: + - id: Prepare + name: gcr.io/cloud-builders/gcloud + entrypoint: deploy/prepare.sh + args: + - $PROJECT_ID + - id: Migrate + name: golang:1.17.3 + entrypoint: bash + dir: private + args: + - -c + - | + source devtools/lib.sh + go install -tags postgres github.com/golang-migrate/migrate/v4/cmd/migrate@v4.15.1 + go install github.com/GoogleCloudPlatform/cloudsql-proxy/cmd/cloud_sql_proxy@v1.27.0 + name=$(database_name $_ENV) + port=$(database_port $_ENV) + cloud_sql_proxy -instances=$PROJECT_ID:us-central1:${name}=tcp:${port} & sleep 1 + migrate \ + -source file:../migrations \ + -database "postgres://cloudbuild@127.0.0.1:${port}/${name}?sslmode=disable&password=$$PASSWORD" \ + "$_CMD" + secretEnv: ['PASSWORD'] +availableSecrets: + secretManager: + - versionName: projects/$PROJECT_ID/secrets/cloudbuild-database-password/versions/latest + env: 'PASSWORD' |
