Skip to content

Commit 5c19148

Browse files
committed
CI: test images (using goss) before publishing
1 parent 6c3ab8a commit 5c19148

11 files changed

+182
-71
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
name: "Build & test Docker image"
3+
description: "Builds a Docker image, then runs tests (goss)"
4+
5+
inputs:
6+
image:
7+
description: "Image name (subdir containing Dockerfile)"
8+
required: true
9+
version:
10+
description: "Image version/tag"
11+
required: true
12+
target:
13+
description: "Dockerfile target to build"
14+
required: false
15+
default: final
16+
build-args:
17+
description: "Build arguments to pass along to Docker"
18+
required: false
19+
context:
20+
description: "Build context path (defaults to the image path)"
21+
required: false
22+
23+
runs:
24+
using: "composite"
25+
steps:
26+
- name: Install Goss
27+
shell: bash
28+
run: |
29+
curl -sS -L https://github.com/goss-org/goss/releases/latest/download/goss-linux-amd64 -o /usr/local/bin/goss
30+
curl -sS -L https://github.com/goss-org/goss/releases/latest/download/dgoss -o /usr/local/bin/dgoss
31+
chmod +x /usr/local/bin/goss /usr/local/bin/dgoss
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
with:
35+
driver-opts: network=host
36+
- name: Build base image (if needed)
37+
id: build-base
38+
uses: ./.github/actions/prebuild-base
39+
with:
40+
image: ${{ inputs.image }}
41+
build-args: ${{ inputs.build-args }}
42+
- name: Build image
43+
uses: docker/build-push-action@v6
44+
with:
45+
context: ${{ inputs.context != '' && inputs.context || format('./{0}/', inputs.image) }}
46+
file: ./${{ inputs.image }}/Dockerfile
47+
load: true
48+
tags: ${{ inputs.image }}:${{ inputs.version }}
49+
target: ${{ inputs.target }}
50+
build-args: ${{ inputs.build-args }}
51+
build-contexts: ${{ steps.build-base.outputs.build-context }}
52+
cache-from: type=gha
53+
cache-to: type=gha,mode=max
54+
- name: Run goss tests
55+
shell: bash
56+
run: |
57+
./tests/run-tests.sh ${{ inputs.image }}:${{ inputs.version }} ${{ inputs.target }}

.github/workflows/build-and-publish-matomo.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@
22
name: Build & Publish Matomo
33

44
on:
5-
schedule:
6-
- cron: "0 0 1,15 * *" # Every 2 weeks
7-
push:
8-
branches:
9-
- main
10-
paths:
5+
pull_request:
6+
paths: &watch_paths
117
- '.github/actions/**'
128
- '.github/workflows/build-and-publish-matomo.yml'
13-
- '.github/workflows/internal-build-and-publish.yml'
9+
- '.github/workflows/internal-build-test-and-publish.yml'
1410
- 'common/**'
1511
- 'matomo/**'
12+
push:
13+
branches:
14+
- main
15+
paths: *watch_paths
16+
schedule:
17+
- cron: "0 0 1,15 * *" # Every 2 weeks
1618
workflow_dispatch:
1719

1820
jobs:
19-
build-and-publish:
20-
uses: ./.github/workflows/internal-build-and-publish.yml
21+
build-test-and-publish:
22+
uses: ./.github/workflows/internal-build-test-and-publish.yml
2123
with:
2224
image: matomo
2325
version: latest
2426
context: .
27+
run-tests: false

.github/workflows/build-and-publish-nuxt-base.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22
name: Build & Publish Nuxt Base
33

44
on:
5-
schedule:
6-
- cron: "0 0 1,15 * *" # Every 2 weeks
7-
push:
8-
branches:
9-
- main
10-
paths:
5+
pull_request:
6+
paths: &watch_paths
117
- '.github/actions/**'
128
- '.github/workflows/build-and-publish-nuxt-base.yml'
13-
- '.github/workflows/internal-build-and-publish.yml'
9+
- '.github/workflows/internal-build-test-and-publish.yml'
1410
- 'common/**'
1511
- 'nuxt-base/**'
12+
- 'tests/nuxt-base/**'
13+
- 'tests/run-tests.sh'
14+
push:
15+
branches:
16+
- main
17+
paths: *watch_paths
18+
schedule:
19+
- cron: "0 0 1,15 * *" # Every 2 weeks
1620
workflow_dispatch:
1721

1822
jobs:
19-
build-and-publish:
20-
uses: ./.github/workflows/internal-build-and-publish.yml
23+
build-test-and-publish:
24+
uses: ./.github/workflows/internal-build-test-and-publish.yml
2125
strategy:
2226
matrix:
2327
version:

.github/workflows/build-and-publish-payload-base.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22
name: Build & Publish Payload Base
33

44
on:
5-
schedule:
6-
- cron: "0 0 1,15 * *" # Every 2 weeks
7-
push:
8-
branches:
9-
- main
10-
paths:
5+
pull_request:
6+
paths: &watch_paths
117
- '.github/actions/**'
128
- '.github/workflows/build-and-publish-payload-base.yml'
13-
- '.github/workflows/internal-build-and-publish.yml'
9+
- '.github/workflows/internal-build-test-and-publish.yml'
1410
- 'common/**'
1511
- 'payload-base/**'
12+
- 'tests/payload-base/**'
13+
- 'tests/run-tests.sh'
14+
push:
15+
branches:
16+
- main
17+
paths: *watch_paths
18+
schedule:
19+
- cron: "0 0 1,15 * *" # Every 2 weeks
1620
workflow_dispatch:
1721

1822
jobs:
19-
build-and-publish:
20-
uses: ./.github/workflows/internal-build-and-publish.yml
23+
build-test-and-publish:
24+
uses: ./.github/workflows/internal-build-test-and-publish.yml
2125
strategy:
2226
matrix:
2327
version:

.github/workflows/build-and-publish-php-base.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22
name: Build & Publish PHP Base
33

44
on:
5-
schedule:
6-
- cron: "0 0 1,15 * *" # Every 2 weeks
7-
push:
8-
branches:
9-
- main
10-
paths:
5+
pull_request:
6+
paths: &watch_paths
117
- '.github/actions/**'
128
- '.github/workflows/build-and-publish-php-base.yml'
13-
- '.github/workflows/internal-build-and-publish.yml'
9+
- '.github/workflows/internal-build-test-and-publish.yml'
1410
- 'common/**'
1511
- 'php-base/**'
12+
- 'tests/php-base/**'
13+
- 'tests/run-tests.sh'
14+
push:
15+
branches:
16+
- main
17+
paths: *watch_paths
18+
schedule:
19+
- cron: "0 0 1,15 * *" # Every 2 weeks
1620
workflow_dispatch:
1721

1822
jobs:
19-
build-and-publish:
20-
uses: ./.github/workflows/internal-build-and-publish.yml
23+
build-test-and-publish:
24+
uses: ./.github/workflows/internal-build-test-and-publish.yml
2125
strategy:
2226
matrix:
2327
version:

.github/workflows/build-and-publish-test-nats.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@
22
name: Build & Publish Test NATS
33

44
on:
5-
schedule:
6-
- cron: "0 0 1,15 * *" # Every 2 weeks
7-
push:
8-
branches:
9-
- main
10-
paths:
5+
pull_request:
6+
paths: &watch_paths
117
- '.github/actions/**'
128
- '.github/workflows/build-and-publish-test-nats.yml'
13-
- '.github/workflows/internal-build-and-publish.yml'
9+
- '.github/workflows/internal-build-test-and-publish.yml'
1410
- 'test-nats/**'
11+
push:
12+
branches:
13+
- main
14+
paths: *watch_paths
15+
schedule:
16+
- cron: "0 0 1,15 * *" # Every 2 weeks
1517
workflow_dispatch:
1618

1719
jobs:
18-
build-and-publish:
19-
uses: ./.github/workflows/internal-build-and-publish.yml
20+
build-test-and-publish:
21+
uses: ./.github/workflows/internal-build-test-and-publish.yml
2022
with:
2123
image: test-nats
2224
version: latest
25+
run-tests: false

.github/workflows/build-and-publish-test-postgis.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@
22
name: Build & Publish Test Postgis
33

44
on:
5-
schedule:
6-
- cron: "0 0 1,15 * *" # Every 2 weeks
7-
push:
8-
branches:
9-
- main
10-
paths:
5+
pull_request:
6+
paths: &watch_paths
117
- '.github/actions/**'
128
- '.github/workflows/build-and-publish-test-postgis.yml'
13-
- '.github/workflows/internal-build-and-publish.yml'
9+
- '.github/workflows/internal-build-test-and-publish.yml'
1410
- 'test-postgis/**'
11+
push:
12+
branches:
13+
- main
14+
paths: *watch_paths
15+
schedule:
16+
- cron: "0 0 1,15 * *" # Every 2 weeks
1517
workflow_dispatch:
1618

1719
jobs:
18-
build-and-publish:
19-
uses: ./.github/workflows/internal-build-and-publish.yml
20+
build-test-and-publish:
21+
uses: ./.github/workflows/internal-build-test-and-publish.yml
2022
with:
2123
image: test-postgis
2224
version: latest
25+
run-tests: false

.github/workflows/build-and-publish-web-base.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22
name: Build & Publish Web Base
33

44
on:
5-
schedule:
6-
- cron: "0 0 1,15 * *" # Every 2 weeks
7-
push:
8-
branches:
9-
- main
10-
paths:
5+
pull_request:
6+
paths: &watch_paths
117
- '.github/actions/**'
128
- '.github/workflows/build-and-publish-web-base.yml'
13-
- '.github/workflows/internal-build-and-publish.yml'
9+
- '.github/workflows/internal-build-test-and-publish.yml'
1410
- 'common/**'
1511
- 'web-base/**'
12+
- 'tests/web-base/**'
13+
- 'tests/run-tests.sh'
14+
push:
15+
branches:
16+
- main
17+
paths: *watch_paths
18+
schedule:
19+
- cron: "0 0 1,15 * *" # Every 2 weeks
1620
workflow_dispatch:
1721

1822
jobs:
19-
build-and-publish:
20-
uses: ./.github/workflows/internal-build-and-publish.yml
23+
build-test-and-publish:
24+
uses: ./.github/workflows/internal-build-test-and-publish.yml
2125
strategy:
2226
matrix:
2327
version:

.github/workflows/internal-build-and-publish.yml renamed to .github/workflows/internal-build-test-and-publish.yml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
name: Build & Publish
2+
name: Build, Test & Publish
33

44
#
5-
# Internal workflow to build and publish a package
5+
# Internal workflow to build, test and publish a package
66
#
77

88
on:
@@ -29,11 +29,40 @@ on:
2929
description: Build context path (defaults to the image's path)
3030
type: string
3131
required: false
32+
run-tests:
33+
description: Whether to run tests or not
34+
required: false
35+
default: true
36+
type: boolean
3237

3338
jobs:
39+
build-and-test:
40+
name: Build & Test
41+
runs-on: ubuntu-latest
42+
services:
43+
registry:
44+
image: registry:2
45+
ports:
46+
- 5000:5000
47+
steps:
48+
- name: Checkout
49+
if: inputs.run-tests
50+
uses: actions/checkout@v5
51+
- name: Build & test
52+
if: inputs.run-tests
53+
uses: ./.github/actions/build-and-test
54+
with:
55+
image: ${{ inputs.image }}
56+
version: ${{ inputs.version }}
57+
target: ${{ inputs.target }}
58+
build-args: ${{ inputs.build-args }}
59+
context: ${{ inputs.context }}
60+
3461
build-and-publish:
35-
if: (github.ref == 'refs/heads/main' && github.event_name == 'push') || github.event_name == 'workflow_dispatch'
3662
needs: build-and-test
63+
if: >
64+
github.event_name != 'pull_request' &&
65+
(github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch')
3766
name: Build & Publish
3867
runs-on: ubuntu-latest
3968
services:

.github/workflows/lint.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ name: Lint
33

44
on:
55
pull_request:
6-
types: [opened, synchronize, reopened, ready_for_review]
7-
branches:
8-
- main
96
push:
107
branches:
118
- main
9+
workflow_dispatch:
1210

1311
jobs:
1412
lint:

0 commit comments

Comments
 (0)