blob: 94454507f389f6f5f66ce361ae9cfa91abebf546 [file] [log] [blame]
# 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.21rc3
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'