Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TypeORM accessible #4792

Merged
merged 1 commit into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions components/gitpod-db/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ packages:
srcs:
- migrate.sh
- migrate_gcp.sh
- typeorm.sh
- typeorm_gcp.sh
deps:
- :migrations
argdeps:
Expand Down
2 changes: 2 additions & 0 deletions components/gitpod-db/leeway.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ RUN wget https://storage.googleapis.com/cloudsql-proxy/v1.23.0/cloud_sql_proxy.l
FROM node:12.18.3-slim
COPY migrate.sh /app/migrate.sh
COPY migrate_gcp.sh /app/migrate_gcp.sh
COPY typeorm.sh /app/typeorm.sh
COPY typeorm_gcp.sh /app/typeorm_gcp.sh
RUN mkdir /home/jenkins && chown -R 10000 /home/jenkins
COPY --from=proxy /bin/cloud_sql_proxy /bin/cloud_sql_proxy
COPY --from=proxy /etc/ssl/certs/ /etc/ssl/certs/
Expand Down
3 changes: 1 addition & 2 deletions components/gitpod-db/migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@

set -euo pipefail

yarn --cwd /app/node_modules/@gitpod/gitpod-db run wait-for-db
yarn --cwd /app/node_modules/@gitpod/gitpod-db typeorm migrations:run
/app/typeorm.sh migrations:run
13 changes: 1 addition & 12 deletions components/gitpod-db/migrate_gcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,4 @@

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
/app/typeorm_gcp.sh migrations:run
9 changes: 9 additions & 0 deletions components/gitpod-db/typeorm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/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.

set -euo pipefail

yarn --cwd /app/node_modules/@gitpod/gitpod-db run wait-for-db
yarn --cwd /app/node_modules/@gitpod/gitpod-db typeorm "$@"
33 changes: 33 additions & 0 deletions components/gitpod-db/typeorm_gcp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/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 typeorm, e.g. to run or revert 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/typeorm_gcp.sh migrations:run

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/typeorm.sh "$@"

# stop the proxy
kill $proxy_pid
wait $proxy_pid