Skip to content

Commit a45a2e5

Browse files
docs(examples): deploy-params, cloudsql-alembic, and playwright-verify samples
Adds runnable samples demonstrating deploy-parameter injection, each mirrored under integration/examples/ per the repo's sample conventions: - custom-actions-deploy-params: a busybox show-params action that prints the deploy parameters forwarded by `skaffold exec --set`. - custom-actions-cloudsql-migration: an alembic migration custom action that receives a Cloud SQL DATABASE_URL via --set on `skaffold exec`. - verify-playwright-smoke: a Playwright smoke test run by `skaffold verify` that targets a SERVICE_URL supplied via --set, matching Cloud Deploy auto-passing the Cloud Run service URL into verify containers.
1 parent eaa5fc8 commit a45a2e5

20 files changed

Lines changed: 410 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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`.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: skaffold/v4beta14
2+
kind: Config
3+
metadata:
4+
name: cloudsql-migration-demo
5+
customActions:
6+
- name: db-migrate
7+
containers:
8+
- name: alembic
9+
# busybox keeps this sample runnable. In a real project, swap it for your
10+
# migrations image and run the real command, e.g.:
11+
# image: your-registry/myapp-migrations:latest
12+
# command: ["alembic", "upgrade", "head"]
13+
# alembic reads the Cloud SQL connection string from DATABASE_URL, which
14+
# is supplied as a deploy parameter via `--set` (never hard-coded here).
15+
image: busybox
16+
command: ["sh", "-c"]
17+
args:
18+
- 'echo "alembic upgrade head -> ${DATABASE_URL}"'
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Custom actions: deploy parameters
2+
3+
This example demonstrates how `skaffold exec` forwards deploy parameters
4+
— values supplied on the command line with `--set` or `--set-value-file`
5+
— as environment variables into every container of the invoked custom
6+
action. This mirrors [Google Cloud Deploy: pass parameters to your deployments](https://docs.cloud.google.com/deploy/docs/parameters).
7+
8+
## Try it
9+
10+
```console
11+
$ skaffold exec show-params \
12+
--set TF_VAR_bucket=my-bkt \
13+
--set REGION=us-central1
14+
```
15+
16+
The `printer` container will echo:
17+
18+
```
19+
TF_VAR_bucket=my-bkt
20+
REGION=us-central1
21+
```
22+
23+
## Precedence
24+
25+
When the same key appears in multiple sources, later entries win:
26+
27+
1. `--verify-env-file` / base env
28+
2. `--set-value-file`
29+
3. `--set` (highest priority)
30+
31+
On key collision, deploy parameters override a container's own `env:`
32+
entry declared in `skaffold.yaml`.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: skaffold/v4beta14
2+
kind: Config
3+
metadata:
4+
name: deploy-params-demo
5+
customActions:
6+
- name: show-params
7+
containers:
8+
- name: printer
9+
image: busybox
10+
command: ["sh", "-c"]
11+
args:
12+
- 'echo "TF_VAR_bucket=${TF_VAR_bucket}"; echo "REGION=${REGION}"'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM mcr.microsoft.com/playwright:v1.44.0-jammy
2+
3+
WORKDIR /smoke
4+
5+
COPY package.json playwright.config.ts ./
6+
RUN npm install
7+
8+
COPY tests ./tests
9+
10+
# SERVICE_URL is injected at run time by `skaffold verify --set SERVICE_URL=...`
11+
# and consumed as the Playwright baseURL.
12+
CMD ["npx", "playwright", "test"]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Verify: Playwright smoke test with a service URL
2+
3+
This example shows how `skaffold verify` forwards a deploy parameter — the URL of
4+
a freshly deployed service — as an environment variable (`SERVICE_URL`) into a
5+
verify container that runs a [Playwright](https://playwright.dev) smoke test.
6+
7+
This mirrors
8+
[Google Cloud Deploy](https://docs.cloud.google.com/deploy/docs/parameters),
9+
which automatically passes the Cloud Run service URL into verify containers so
10+
post-deploy smoke tests can target the revision that was just rolled out.
11+
12+
## Layout
13+
14+
- `Dockerfile` — builds the `smoke-tests` image from the official Playwright base,
15+
bundling the test sources.
16+
- `playwright.config.ts` — uses `process.env.SERVICE_URL` as the Playwright
17+
`baseURL`.
18+
- `tests/smoke.spec.ts` — a minimal smoke test that requests `/` and asserts a
19+
successful response.
20+
21+
## Try it
22+
23+
`skaffold verify` runs the verify container from the built image; build first and
24+
pipe the resulting tags into `verify`:
25+
26+
```console
27+
$ skaffold build -q | skaffold verify \
28+
--set SERVICE_URL=https://my-service-abc-uc.a.run.app
29+
```
30+
31+
The `playwright` container runs `npx playwright test` against
32+
`SERVICE_URL`. Supplying a different `--set SERVICE_URL=...` retargets the smoke
33+
test without changing `skaffold.yaml`.
34+
35+
## Precedence
36+
37+
When the same key is supplied from multiple sources, later entries win:
38+
39+
1. `--env-file` / base env
40+
2. `--set-value-file`
41+
3. `--set` (highest priority)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "verify-playwright-smoke",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"test": "playwright test"
7+
},
8+
"devDependencies": {
9+
"@playwright/test": "^1.44.0"
10+
}
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from '@playwright/test';
2+
3+
// baseURL comes from the SERVICE_URL deploy parameter, injected as an environment
4+
// variable by `skaffold verify --set SERVICE_URL=...`. This mirrors Google Cloud
5+
// Deploy, which automatically passes the Cloud Run service URL into verify
6+
// containers so post-deploy smoke tests can target the freshly deployed revision.
7+
export default defineConfig({
8+
testDir: './tests',
9+
use: {
10+
baseURL: process.env.SERVICE_URL,
11+
},
12+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: skaffold/v4beta14
2+
kind: Config
3+
metadata:
4+
name: playwright-smoke-demo
5+
build:
6+
artifacts:
7+
- image: smoke-tests
8+
docker:
9+
dockerfile: Dockerfile
10+
verify:
11+
- name: smoke-test
12+
container:
13+
name: playwright
14+
image: smoke-tests
15+
# SERVICE_URL is supplied as a deploy parameter via `--set` and injected
16+
# as an environment variable into this container. Playwright reads it as
17+
# the baseURL (see playwright.config.ts). This mirrors Google Cloud Deploy,
18+
# which automatically passes the Cloud Run service URL into verify tasks.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
// A minimal smoke test: hit the root of the deployed service (baseURL ==
4+
// SERVICE_URL) and assert it responds successfully. Extend with real
5+
// user-facing assertions for your application.
6+
test('service responds on /', async ({ page }) => {
7+
const response = await page.goto('/');
8+
expect(response, 'no response from SERVICE_URL').not.toBeNull();
9+
expect(response!.ok()).toBeTruthy();
10+
});

0 commit comments

Comments
 (0)