Repository navigation
feat: set up core postgres tables #6308
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
Merged
The head ref may contain hidden characters: "\u{1F4BD}\u{1F4CB}"
+374
−63
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
another-rex marked this conversation as resolved.
Resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| FROM golang:1.27.1-alpine@sha256:8a5910f31396cd4d89662f56c68b3ae31d374308270a1c3bd96672ee5ed43414 AS GO_BUILD | ||
|
|
||
| ARG GOOSE_VERSION=3.28.0 | ||
| ARG CLOUD_SQL_PROXY_VERSION=2.26.0 | ||
| WORKDIR /build/ | ||
| RUN GOBIN=$(pwd) go install \ | ||
| -tags='no_clickhouse no_libsql no_mssql no_mysql no_redshift no_sqlite3 no_turso no_vertica no_ydb' \ | ||
| github.com/pressly/goose/v3/cmd/goose@v${GOOSE_VERSION} | ||
| RUN GOBIN=$(pwd) go install \ | ||
| github.com/GoogleCloudPlatform/cloud-sql-proxy/v2@v${CLOUD_SQL_PROXY_VERSION} | ||
|
|
||
| FROM gcr.io/google.com/cloudsdktool/google-cloud-cli:alpine@sha256:786a1537df13c54289a46507b22a411f6c71154ae0293d12adce4b9358acca63 | ||
|
|
||
| COPY --from=GO_BUILD /build/goose /usr/bin/goose | ||
| COPY --from=GO_BUILD /build/cloud-sql-proxy /usr/bin/cloud-sql-proxy | ||
| COPY entrypoint.bash /builder/entrypoint.bash | ||
| RUN chmod +x /builder/entrypoint.bash | ||
|
|
||
| ENTRYPOINT ["/builder/entrypoint.bash"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Goose Cloud Builder Image | ||
|
|
||
| Used for running PostgreSQL schema migrations (`goose`) via Cloud SQL Auth Proxy (`cloud-sql-proxy`) in Cloud Build (`build-and-stage.yaml` and `deploy-prod.yaml`). Contains `goose`, `cloud-sql-proxy`, and `gcloud`. | ||
|
|
||
| To build and push the builder image, run from this directory: | ||
| ```bash | ||
| gcloud builds submit --project=oss-vdb --config=cloudbuild.yaml | ||
| ``` | ||
|
|
||
| Afterwards, it can be used in Cloud Build as: | ||
| ```yaml | ||
| steps: | ||
| - name: gcr.io/oss-vdb/goose | ||
| env: ['CLOUDSQL_INSTANCE=oss-vdb-test:us-central1:osv-db'] | ||
| args: ['up'] | ||
| dir: go/internal/database/postgres/migrations | ||
| ``` | ||
|
|
||
| When `CLOUDSQL_INSTANCE` is set, the entrypoint starts `cloud-sql-proxy --auto-iam-authn` in the background, waits for its readiness probe, connects as the active Cloud Build IAM user (`deployment@oss-vdb.iam`) with `role=cloudsqlsuperuser`, and runs `goose`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # In this directory, run the following command to build this builder: | ||
| # $ gcloud builds submit . --project=oss-vdb --config=cloudbuild.yaml | ||
| substitutions: | ||
| _GOOSE_VERSION: 3.28.0 | ||
| _CLOUD_SQL_PROXY_VERSION: 2.26.0 | ||
| steps: | ||
| - name: 'gcr.io/cloud-builders/docker' | ||
| args: | ||
| - build | ||
| - --build-arg | ||
| - GOOSE_VERSION=${_GOOSE_VERSION} | ||
| - --build-arg | ||
| - CLOUD_SQL_PROXY_VERSION=${_CLOUD_SQL_PROXY_VERSION} | ||
| - --tag | ||
| - gcr.io/${PROJECT_ID}/goose:${_GOOSE_VERSION} | ||
| - --tag | ||
| - gcr.io/${PROJECT_ID}/goose:latest | ||
| - . | ||
| - name: 'gcr.io/${PROJECT_ID}/goose:${_GOOSE_VERSION}' | ||
| args: ['version'] | ||
| images: | ||
| - 'gcr.io/${PROJECT_ID}/goose:${_GOOSE_VERSION}' | ||
| - 'gcr.io/${PROJECT_ID}/goose:latest' | ||
| tags: ['cloud-builders-community'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| #!/bin/bash | ||
| # | ||
| # Goose + Cloud SQL Auth Proxy cloud builder entry point. | ||
| set -euo pipefail | ||
|
|
||
| if [[ "${1:-}" == "version" || "${1:-}" == "-version" || "${1:-}" == "--version" ]]; then | ||
| goose -version | ||
| cloud-sql-proxy --version | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [[ -n "${CLOUDSQL_INSTANCE:-}" ]]; then | ||
| active_account=$(gcloud auth list --filter=status:ACTIVE --format="value(account)" 2> /dev/null) | ||
| if [[ -z "${active_account}" ]]; then | ||
| echo "No active gcloud account found for Cloud SQL IAM authentication." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Starting cloud-sql-proxy for ${CLOUDSQL_INSTANCE}..." | ||
| cloud-sql-proxy "${CLOUDSQL_INSTANCE}" \ | ||
| --port=5432 \ | ||
| --auto-iam-authn \ | ||
| --health-check \ | ||
| --http-port=9090 & | ||
| PROXY_PID=$! | ||
| trap 'kill "${PROXY_PID}" 2>/dev/null || true' EXIT | ||
|
|
||
| ready=false | ||
| for _ in {1..30}; do | ||
| if ! kill -0 "${PROXY_PID}" 2>/dev/null; then | ||
| echo "cloud-sql-proxy exited unexpectedly." | ||
| wait "${PROXY_PID}" || true | ||
| exit 1 | ||
| fi | ||
| if curl -sf http://127.0.0.1:9090/readiness >/dev/null 2>&1; then | ||
| ready=true | ||
| break | ||
| fi | ||
| sleep 1 | ||
| done | ||
|
|
||
| if [[ "${ready}" != "true" ]]; then | ||
| echo "Timed out waiting for cloud-sql-proxy readiness." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Cloud SQL IAM service account usernames omit the .gserviceaccount.com suffix. | ||
| db_user="${PGUSER:-${active_account%.gserviceaccount.com}}" | ||
| db_name="${PGDATABASE:-osv}" | ||
| export GOOSE_DRIVER="${GOOSE_DRIVER:-postgres}" | ||
| export GOOSE_DBSTRING="${GOOSE_DBSTRING:-host=127.0.0.1 port=5432 user=${db_user} dbname=${db_name} sslmode=disable options=-crole=cloudsqlsuperuser}" | ||
| fi | ||
|
|
||
| echo "Running: goose $*" | ||
| goose "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.