Skip to content

Commit 3b22fcd

Browse files
committed
CI: test images (using goss) before publishing
1 parent adee4c1 commit 3b22fcd

File tree

6 files changed

+98
-2
lines changed

6 files changed

+98
-2
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
20+
runs:
21+
using: "composite"
22+
steps:
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
with:
26+
driver-opts: network=host
27+
- name: Install Goss
28+
shell: bash
29+
run: |
30+
curl -sS -L https://github.com/goss-org/goss/releases/latest/download/goss-linux-amd64 -o /usr/local/bin/goss
31+
curl -sS -L https://github.com/goss-org/goss/releases/latest/download/dgoss -o /usr/local/bin/dgoss
32+
chmod +x /usr/local/bin/goss /usr/local/bin/dgoss
33+
- name: Build base image (if needed)
34+
id: build-base
35+
uses: ./.github/actions/prebuild-base
36+
with:
37+
image: ${{ inputs.image }}
38+
build-args: ${{ inputs.build-args }}
39+
- name: Build image
40+
uses: docker/build-push-action@v6
41+
with:
42+
context: ./${{ inputs.image }}/
43+
file: ./${{ inputs.image }}/Dockerfile
44+
load: true
45+
tags: ${{ inputs.image }}:${{ inputs.version }}
46+
target: ${{ inputs.target }}
47+
build-args: ${{ inputs.build-args }}
48+
build-contexts: ${{ steps.build-base.outputs.build-context }}
49+
cache-from: type=gha
50+
cache-to: type=gha,mode=max
51+
- name: Run goss tests
52+
shell: bash
53+
run: |
54+
./tests/run-tests.sh ${{ inputs.image }}:${{ inputs.version }} ${{ inputs.target }}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ on:
1212
- '.github/workflows/build-and-publish-nuxt-base.yml'
1313
- 'common/**'
1414
- 'nuxt-base/**'
15+
- 'tests/nuxt-base/**'
16+
- 'tests/run-tests.sh'
1517
workflow_dispatch:
1618

1719
jobs:
@@ -37,6 +39,14 @@ jobs:
3739
steps:
3840
- name: Checkout
3941
uses: actions/checkout@v5
42+
- name: Build & test
43+
uses: ./.github/actions/build-and-test
44+
with:
45+
image: ${{ env.image }}
46+
version: ${{ matrix.info.version }}
47+
target: ${{ matrix.info.target }}
48+
build-args: |
49+
ALPINE_VERSION=${{ matrix.info.alpine }}
4050
- name: Build & publish
4151
uses: ./.github/actions/build-and-publish
4252
with:

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ on:
1212
- '.github/workflows/build-and-publish-payload-base.yml'
1313
- 'common/**'
1414
- 'payload-base/**'
15+
- 'tests/payload-base/**'
16+
- 'tests/run-tests.sh'
1517
workflow_dispatch:
1618

1719
jobs:
@@ -33,6 +35,13 @@ jobs:
3335
steps:
3436
- name: Checkout
3537
uses: actions/checkout@v5
38+
- name: Build & test
39+
uses: ./.github/actions/build-and-test
40+
with:
41+
image: ${{ env.image }}
42+
version: ${{ matrix.info.version }}
43+
build-args: |
44+
ALPINE_VERSION=${{ matrix.info.alpine }}
3645
- name: Build & publish
3746
uses: ./.github/actions/build-and-publish
3847
with:

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ on:
1212
- '.github/workflows/build-and-publish-php-base.yml'
1313
- 'common/**'
1414
- 'php-base/**'
15+
- 'tests/php-base/**'
16+
- 'tests/run-tests.sh'
1517
workflow_dispatch:
1618

1719
jobs:
@@ -64,6 +66,15 @@ jobs:
6466
steps:
6567
- name: Checkout
6668
uses: actions/checkout@v5
69+
- name: Build & test
70+
uses: ./.github/actions/build-and-test
71+
with:
72+
image: ${{ env.image }}
73+
version: ${{ matrix.info.version }}
74+
target: ${{ matrix.info.target }}
75+
build-args: |
76+
ALPINE_VERSION=${{ matrix.info.alpine }}
77+
PHP_VERSION=${{ matrix.info.php }}
6778
- name: Build & publish
6879
uses: ./.github/actions/build-and-publish
6980
with:

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ on:
1212
- '.github/workflows/build-and-publish-web-base.yml'
1313
- 'common/**'
1414
- 'web-base/**'
15+
- 'tests/web-base/**'
16+
- 'tests/run-tests.sh'
1517
workflow_dispatch:
1618

1719
jobs:
@@ -35,6 +37,14 @@ jobs:
3537
steps:
3638
- name: Checkout
3739
uses: actions/checkout@v5
40+
- name: Build & test
41+
uses: ./.github/actions/build-and-test
42+
with:
43+
image: ${{ env.image }}
44+
version: ${{ matrix.info.version }}
45+
target: ${{ matrix.info.target }}
46+
build-args: |
47+
ALPINE_VERSION=3.22
3848
- name: Build & publish
3949
uses: ./.github/actions/build-and-publish
4050
with:

tests/run-tests.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
set -euo pipefail
44
shopt -s nullglob
55

6+
# Note: drop the "tag" from the name
67
IMAGE_NAME=$1
8+
SUITE_NAME=${IMAGE_NAME%%:*}
79
IMAGE_TARGET=$2
810

911
run_test() {
1012
echo "Running ${1}…"
1113
pushd "$1" > /dev/null
1214

13-
tempdir=$(mktemp -d /tmp/${IMAGE_NAME}.XXXXXX)
15+
tempdir=$(mktemp -d /tmp/${SUITE_NAME}.XXXXXX)
1416
[ -d ../../common-files ] && cp -r ../../common-files/* "$tempdir"
1517
[ -d files ] && cp -rf files/* "$tempdir"
1618

@@ -47,6 +49,6 @@ dgoss_run() {
4749
2> >(grep -v -e '^INFO: ' >&2)
4850
}
4951

50-
for test in tests/$IMAGE_NAME/$IMAGE_TARGET/*; do
52+
for test in tests/$SUITE_NAME/$IMAGE_TARGET/*; do
5153
run_test "$test"
5254
done

0 commit comments

Comments
 (0)