|
| 1 | +# Custom actions: Cloud SQL alembic migration |
| 2 | + |
| 3 | +This example shows how `skaffold exec` forwards a deploy parameter — a Cloud SQL |
| 4 | +connection URL — as an environment variable (`DATABASE_URL`) into a database |
| 5 | +migration container. This mirrors |
| 6 | +[Google Cloud Deploy: pass parameters to your deployments](https://docs.cloud.google.com/deploy/docs/parameters), |
| 7 | +where deploy parameters are surfaced into the execution environment so that |
| 8 | +predeploy/postdeploy hooks (such as schema migrations) can consume them without |
| 9 | +baking secrets into `skaffold.yaml`. |
| 10 | + |
| 11 | +## Try it |
| 12 | + |
| 13 | +```console |
| 14 | +$ skaffold exec db-migrate \ |
| 15 | + --set DATABASE_URL='postgresql+pg8000://USER:PASS@/APP?unix_sock=/cloudsql/PROJECT:REGION:INSTANCE/.s.PGSQL.5432' |
| 16 | +``` |
| 17 | + |
| 18 | +The `alembic` container will echo: |
| 19 | + |
| 20 | +``` |
| 21 | +alembic upgrade head -> postgresql+pg8000://USER:PASS@/APP?unix_sock=/cloudsql/PROJECT:REGION:INSTANCE/.s.PGSQL.5432 |
| 22 | +``` |
| 23 | + |
| 24 | +In a real project the container image bundles your application and Alembic, and |
| 25 | +the command is `["alembic", "upgrade", "head"]`. Alembic reads `DATABASE_URL` |
| 26 | +to connect to Cloud SQL (typically through the |
| 27 | +[Cloud SQL Auth Proxy](https://cloud.google.com/sql/docs/postgres/sql-proxy) or a |
| 28 | +unix socket under `/cloudsql`). |
| 29 | + |
| 30 | +## Precedence |
| 31 | + |
| 32 | +When the same key is supplied from multiple sources, later entries win: |
| 33 | + |
| 34 | +1. `--env-file` / base env |
| 35 | +2. `--set-value-file` |
| 36 | +3. `--set` (highest priority) |
| 37 | + |
| 38 | +On key collision, deploy parameters override a container's own `env:` entry |
| 39 | +declared in `skaffold.yaml`. |
0 commit comments