Skip to content

Commit 5eece6b

Browse files
authored
Merge pull request #399 from dokku/388-exercise-every-documented-task-example-offline-validation-integration
test: exercise every documented task example
2 parents f5458af + 49749f5 commit 5eece6b

16 files changed

Lines changed: 738 additions & 39 deletions

.github/workflows/test.yml

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,48 @@ jobs:
6565
- name: install dokku maintenance plugin
6666
run: sudo dokku plugin:install https://github.com/dokku/dokku-maintenance.git maintenance
6767
- name: run integration tests (shard ${{ matrix.shard }} of 4)
68-
run: sudo DOKKU_TEST_SHARD=${{ matrix.shard }} DOKKU_TEST_SHARDS=4 go test -v -count=1 -timeout 20m -run TestIntegration ./tasks/
68+
run: sudo DOKKU_TEST_SHARD=${{ matrix.shard }} DOKKU_TEST_SHARDS=4 go test -v -count=1 -timeout 20m -run TestIntegration -skip TestIntegrationTaskExamples ./tasks/
69+
70+
task-examples-test:
71+
name: task-examples-test
72+
runs-on: ubuntu-24.04
73+
strategy:
74+
fail-fast: false
75+
matrix:
76+
shard: [1, 2, 3, 4]
77+
steps:
78+
- uses: actions/checkout@v7
79+
- uses: actions/setup-go@v7
80+
with:
81+
go-version-file: go.mod
82+
- name: enable docker legacy link support
83+
run: |
84+
sudo mkdir -p /etc/systemd/system/docker.service.d
85+
printf '[Service]\nEnvironment="DOCKER_KEEP_DEPRECATED_LEGACY_LINKS_ENV_VARS=1"\n' | sudo tee /etc/systemd/system/docker.service.d/legacy-links.conf
86+
sudo systemctl daemon-reload
87+
sudo systemctl restart docker
88+
- name: install dokku
89+
run: |
90+
sudo mkdir -p /etc/apt/keyrings
91+
curl -fsSL https://packagecloud.io/dokku/dokku/gpgkey | sudo gpg --dearmor -o /etc/apt/keyrings/dokku-archive-keyring.gpg
92+
echo "deb [signed-by=/etc/apt/keyrings/dokku-archive-keyring.gpg] https://packagecloud.io/dokku/dokku/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/dokku.list
93+
sudo apt-get update -qq
94+
sudo DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true apt-get install -qq -y dokku=0.38.22
95+
sudo dokku plugin:install-dependencies --core
96+
- name: install dokku redis plugin
97+
run: sudo dokku plugin:install https://github.com/dokku/dokku-redis.git redis
98+
- name: install dokku http-auth plugin
99+
run: sudo dokku plugin:install https://github.com/dokku/dokku-http-auth.git http-auth
100+
- name: install dokku global-cert plugin
101+
run: sudo dokku plugin:install https://github.com/dokku-community/dokku-global-cert.git global-cert
102+
- name: install dokku letsencrypt plugin
103+
run: sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git --committish 0.25.0 letsencrypt
104+
- name: install dokku acl plugin
105+
run: sudo dokku plugin:install https://github.com/dokku-community/dokku-acl.git acl
106+
- name: install dokku maintenance plugin
107+
run: sudo dokku plugin:install https://github.com/dokku/dokku-maintenance.git maintenance
108+
- name: apply documented task examples (shard ${{ matrix.shard }} of 4)
109+
run: sudo DOKKU_TEST_SHARD=${{ matrix.shard }} DOKKU_TEST_SHARDS=4 go test -v -count=1 -timeout 30m -run '^TestIntegrationTaskExamples$' ./tasks/
69110

70111
scheduler-k3s-test:
71112
name: scheduler-k3s-test
@@ -93,6 +134,34 @@ jobs:
93134
run: sudo dokku scheduler-k3s:initialize --server-ip 127.0.0.1
94135
- name: run scheduler-k3s integration tests
95136
run: sudo DOKKU_TEST_SCHEDULER_K3S=1 go test -v -count=1 -timeout 30m -run '^TestIntegrationSchedulerK3s' ./tasks/
137+
- name: apply scheduler-k3s documented examples
138+
run: sudo DOKKU_TEST_SCHEDULER_K3S=1 go test -v -count=1 -timeout 30m -run '^TestIntegrationTaskExamples/dokku_scheduler_k3s' ./tasks/
139+
140+
letsencrypt-example-test:
141+
name: letsencrypt-example-test
142+
runs-on: ubuntu-24.04
143+
steps:
144+
- uses: actions/checkout@v7
145+
- uses: actions/setup-go@v7
146+
with:
147+
go-version-file: go.mod
148+
- name: install dokku
149+
run: |
150+
sudo mkdir -p /etc/apt/keyrings
151+
curl -fsSL https://packagecloud.io/dokku/dokku/gpgkey | sudo gpg --dearmor -o /etc/apt/keyrings/dokku-archive-keyring.gpg
152+
echo "deb [signed-by=/etc/apt/keyrings/dokku-archive-keyring.gpg] https://packagecloud.io/dokku/dokku/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/dokku.list
153+
sudo apt-get update -qq
154+
sudo DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true apt-get install -qq -y dokku=0.38.22
155+
sudo dokku plugin:install-dependencies --core
156+
- name: stand up the pebble ACME server
157+
run: |
158+
git clone --depth 1 https://github.com/dokku/dokku-letsencrypt.git /tmp/dokku-letsencrypt
159+
docker build -t letest-lego:latest /tmp/dokku-letsencrypt/tests/lego
160+
mkdir -p /tmp/letest-host
161+
LETEST_HOST_DIR=/tmp/letest-host docker compose -f /tmp/dokku-letsencrypt/tests/docker-compose.yml up -d --wait
162+
PLUGIN_SRC=/tmp/dokku-letsencrypt bash /tmp/dokku-letsencrypt/tests/setup-native.sh
163+
- name: apply the letsencrypt documented example
164+
run: sudo DOKKU_TEST_LETSENCRYPT=1 go test -v -count=1 -timeout 20m -run '^TestIntegrationTaskExamples/dokku_letsencrypt$' ./tasks/
96165

97166
bats-test:
98167
name: bats-test

docs/tasks/dokku_git_from_archive.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,21 @@ Supported.
2121

2222
## Examples
2323

24-
### Deploy a tar archive
24+
### Deploy a tar.gz archive
2525

2626
```yaml
2727
dokku_git_from_archive:
2828
app: node-js-app
29-
archive_url: https://example.com/release-1.0.0.tar
29+
archive_url: https://github.com/dokku/smoke-test-app/archive/refs/heads/master.tar.gz
30+
archive_type: tar.gz
3031
```
3132
3233
### Deploy a zip archive with author metadata
3334
3435
```yaml
3536
dokku_git_from_archive:
3637
app: node-js-app
37-
archive_url: https://example.com/release-1.0.0.zip
38+
archive_url: https://github.com/dokku/smoke-test-app/archive/refs/heads/master.zip
3839
archive_type: zip
3940
git_username: deploy-bot
4041
git_email: deploy@example.com

docs/tasks/dokku_git_from_image.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@ Partial - the image reference is written to the companion vars-file.
2626
```yaml
2727
dokku_git_from_image:
2828
app: node-js-app
29-
image: dokku/node-js-app:latest
29+
image: dokku/smoke-test-app:dockerfile
3030
```
3131
32-
### Deploy from an image with a build directory and git author
32+
### Deploy from an image with git author metadata
3333
3434
```yaml
3535
dokku_git_from_image:
3636
app: node-js-app
37-
image: dokku/node-js-app:latest
38-
build_dir: /app
37+
image: dokku/smoke-test-app:dockerfile
3938
git_username: dokku
4039
git_email: dokku@example.com
4140
```

docs/tasks/dokku_git_property.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ dokku_git_property:
3838
value: "true"
3939
```
4040
41-
### Setting the rev env var globally
41+
### Setting the rev env var for an app
4242
4343
```yaml
4444
dokku_git_property:
45-
app: ""
46-
global: true
45+
app: node-js-app
4746
property: rev-env-var
4847
value: GIT_REV
4948
```

docs/tasks/dokku_git_sync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dokku_git_sync:
4141
dokku_git_sync:
4242
app: hello-world
4343
remote: https://github.com/dokku/smoke-test-app.git
44-
git_ref: main
44+
git_ref: master
4545
build: true
4646
build_if_changes: false
4747
skip_deploy_branch: false

docs/tasks/dokku_haproxy_property.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ Supported.
2020

2121
## Examples
2222

23-
### Setting the letsencrypt email for an app
23+
### Setting the letsencrypt email globally
2424

2525
```yaml
2626
dokku_haproxy_property:
27-
app: node-js-app
27+
app: ""
28+
global: true
2829
property: letsencrypt-email
2930
value: admin@example.com
3031
```
@@ -39,11 +40,12 @@ dokku_haproxy_property:
3940
value: INFO
4041
```
4142
42-
### Clearing the letsencrypt email for an app
43+
### Clearing the letsencrypt email globally
4344
4445
```yaml
4546
dokku_haproxy_property:
46-
app: node-js-app
47+
app: ""
48+
global: true
4749
property: letsencrypt-email
4850
state: absent
4951
```

docs/tasks/dokku_traefik_property.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ Supported.
2020

2121
## Examples
2222

23-
### Setting the letsencrypt email for an app
23+
### Setting the letsencrypt email globally
2424

2525
```yaml
2626
dokku_traefik_property:
27-
app: node-js-app
27+
app: ""
28+
global: true
2829
property: letsencrypt-email
2930
value: admin@example.com
3031
```
@@ -39,11 +40,12 @@ dokku_traefik_property:
3940
value: INFO
4041
```
4142
42-
### Clearing the letsencrypt email for an app
43+
### Clearing the letsencrypt email globally
4344
4445
```yaml
4546
dokku_traefik_property:
46-
app: node-js-app
47+
app: ""
48+
global: true
4749
property: letsencrypt-email
4850
state: absent
4951
```

docs/writing-tasks.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ make docs
216216
This runs `go generate generate/docs.go`, which writes one `docs/tasks/<task>.md` per registered
217217
task plus the `docs/tasks/README.md` index. Commit the regenerated files alongside your code.
218218

219+
Because the examples are published as-is, they are also tested. `TestAllTaskExamplesValidate`
220+
(`tasks/main_test.go`) decodes every example offline, applies the field defaults, and runs the
221+
task's `Validate()`, so a snippet that would fail `docket validate` cannot ship - it runs as part of
222+
`make test`. `TestIntegrationTaskExamples` (`tasks/example_integration_test.go`) then applies every
223+
example against a live Dokku under `make test-integration`. Write examples that are actually
224+
runnable: reference real resources (a reachable image or archive, not a placeholder URL), and if a
225+
task needs a prerequisite the shared placeholder apps do not provide - a backing service, a deployed
226+
app, a plugin, a cluster - or its documented value cannot apply verbatim (a secret or inline PEM),
227+
declare it in the driver's `exampleIntegrationPolicy` rather than leaving the example unapplied.
228+
219229
## See also
220230

221231
- [Tasks](tasks/README.md) - the generated reference for every task

0 commit comments

Comments
 (0)