mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
34 lines
1.1 KiB
Bash
Executable File
34 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# Copyright (c) 2021 Gitpod GmbH. All rights reserved.
|
|
# Licensed under the GNU Affero General Public License (AGPL).
|
|
# See License-AGPL.txt in the project root for license information.
|
|
|
|
# This scipt connects via Google's cloud_sql_proxy to a database and runs the db-migrations
|
|
|
|
# ENV variables for configuration:
|
|
# * GOOGLE_APPLICATION_CREDENTIALS_DATA: contents of the crendetials files that cloud_sql_proxy uses for authentication
|
|
# * GCP_DATABASE: database name
|
|
# * DB_PASSWORD: database password
|
|
|
|
# Example usage:
|
|
# docker run --rm \
|
|
# --env GOOGLE_APPLICATION_CREDENTIALS_DATA='...' \
|
|
# --env GCP_DATABASE="gitpod-foobar:europe-west1:gitpod-foobar-baz" \
|
|
# --env DB_PASSWORD="..." \
|
|
# gcr.io/gitpod-core-dev/build/db-migrations:x1 /app/migrate_gcp.sh
|
|
|
|
set -euo pipefail
|
|
|
|
echo "$GOOGLE_APPLICATION_CREDENTIALS_DATA" > /tmp/gcp.json
|
|
|
|
# start the proxy and background it
|
|
GOOGLE_APPLICATION_CREDENTIALS=/tmp/gcp.json cloud_sql_proxy -instances="$GCP_DATABASE=tcp:3306" &
|
|
proxy_pid=$!
|
|
|
|
# run db-migrations
|
|
DB_PORT=3306 /app/migrate.sh
|
|
|
|
# stop the proxy
|
|
kill $proxy_pid
|
|
wait $proxy_pid
|