blob: 526fce6ec243feaecf8cdcb9819deba59e7e3719 [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.19
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'