Skip to content

Commit c58cd27

Browse files
committed
add smoke test + gated ci
1 parent 6555323 commit c58cd27

5 files changed

Lines changed: 116 additions & 11 deletions

File tree

.github/workflows/docker-publish.yml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,21 @@ env:
2121
REGISTRY: ghcr.io
2222
# github.repository as <account>/<repo>
2323
IMAGE_NAME: ${{ github.repository }}
24+
IMAGE_PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7
2425

2526

2627
jobs:
28+
# gate: don't build or publish anything unless the tests pass
29+
test:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v5
34+
- name: Run tests
35+
run: ./test.sh
36+
2737
build:
38+
needs: test
2839

2940
runs-on: ubuntu-latest
3041
permissions:
@@ -36,20 +47,25 @@ jobs:
3647

3748
steps:
3849
- name: Checkout repository
39-
uses: actions/checkout@v4
50+
uses: actions/checkout@v5
4051

4152
- name: Install Cosign
4253
uses: sigstore/cosign-installer@v3.5.0
4354

55+
- name: Set up QEMU
56+
uses: docker/setup-qemu-action@v4
57+
with:
58+
platforms: ${{ env.IMAGE_PLATFORMS }}
59+
4460
# Workaround: https://github.com/docker/build-push-action/issues/461
4561
- name: Setup Docker buildx
46-
uses: docker/setup-buildx-action@v3
62+
uses: docker/setup-buildx-action@v4
4763

4864
# Login against a Docker registry except on PR
4965
# https://github.com/docker/login-action
5066
- name: Log into registry ${{ env.REGISTRY }}
5167
if: github.event_name != 'pull_request'
52-
uses: docker/login-action@v3
68+
uses: docker/login-action@v4
5369
with:
5470
registry: ${{ env.REGISTRY }}
5571
username: ${{ github.actor }}
@@ -59,12 +75,16 @@ jobs:
5975
# https://github.com/docker/metadata-action
6076
- name: Extract Docker metadata
6177
id: meta
62-
uses: docker/metadata-action@v5
78+
uses: docker/metadata-action@v6
6379
with:
6480
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
6581

6682
- name: Extract Docker Version Tag
67-
id: docker_version_tag
83+
id: docker_version_tag
84+
env:
85+
# rebuild on code changes (push / manual run); only the nightly
86+
# schedule dedups on the version tag to skip identical rebuilds
87+
FORCE_REBUILD: ${{ github.event_name != 'schedule' && '1' || '' }}
6888
run: |
6989
./get-version.sh $(echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:" | tr '[:upper:]' '[:lower:]') | sed 's/^/tag=/g' >> $GITHUB_OUTPUT
7090
@@ -77,12 +97,12 @@ jobs:
7797
- name: Build and push Docker image with tag
7898
if: ${{ !endsWith(steps.docker_version_tag.outputs.tag, 'latest') }}
7999
id: build-and-push-tagged
80-
uses: docker/build-push-action@v5
100+
uses: docker/build-push-action@v7
81101
with:
82102
context: .
83103
push: ${{ github.event_name != 'pull_request' }}
84104
tags: ${{ steps.docker_version_tag.outputs.tag }}
85-
platforms: linux/amd64,linux/arm64,linux/arm/v7
105+
platforms: ${{ env.IMAGE_PLATFORMS }}
86106
labels: ${{ steps.meta.outputs.labels }}
87107
cache-from: type=gha
88108
cache-to: type=gha,mode=max
@@ -100,7 +120,7 @@ jobs:
100120

101121
- name: Build Docker Latest Tag
102122
if: ${{ !endsWith(steps.docker_version_tag.outputs.tag, 'latest') }}
103-
id: docker_latest_tag
123+
id: docker_latest_tag
104124
run: |
105125
echo "tag=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" | tr '[:upper:]' '[:lower:]' >> $GITHUB_OUTPUT
106126
@@ -109,12 +129,12 @@ jobs:
109129
- name: Build and push Docker image as latest
110130
if: ${{ !endsWith(steps.docker_version_tag.outputs.tag, 'latest') }}
111131
id: build-and-push-latest
112-
uses: docker/build-push-action@v5
132+
uses: docker/build-push-action@v7
113133
with:
114134
context: .
115135
push: ${{ github.event_name != 'pull_request' }}
116136
tags: ${{ steps.docker_latest_tag.outputs.tag }}
117-
platforms: linux/amd64,linux/arm64,linux/arm/v7
137+
platforms: ${{ env.IMAGE_PLATFORMS }}
118138
labels: ${{ steps.meta.outputs.labels }}
119139
cache-from: type=gha
120140
cache-to: type=gha,mode=max

.github/workflows/test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v5
13+
14+
- name: Run smoke tests
15+
run: ./test.sh

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[ -z "$DOCKER_REGISTRY" ] && echo "error please specify docker-registry DOCKER_REGISTRY" && exit 1
44
IMG="$DOCKER_REGISTRY/$(basename $(cat .git/config | tr ' ' '\n' | grep github.com))"
55

6-
PLATFORM="linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6"
6+
PLATFORM="linux/amd64,linux/arm64,linux/arm/v7"
77

88
TAG=$(./get-version.sh)
99

get-version.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ export PHPMYADMIN_VERSION=$(docker run --rm -t get-version ls /var/www/html/phpm
77
[ -z "$DEBIAN_VERSION" ] && exit 1
88

99
export IMGTAG=$(echo "$1""d$DEBIAN_VERSION-a$APACHE_VERSION-p$PHPMYADMIN_VERSION")
10+
# FORCE_REBUILD (set by the workflow for push / manual runs) rebuilds even if
11+
# the versioned image already exists, so code/config changes get republished.
12+
# the nightly schedule leaves it unset and keeps deduping on the version tag.
13+
if [ -n "$FORCE_REBUILD" ]; then
14+
echo "$IMGTAG"
15+
exit 0
16+
fi
17+
1018
export IMAGE_EXISTS=$(docker pull "$IMGTAG" 2>/dev/null >/dev/null; echo $?)
1119

1220
# return latest, if container is already available :)

test.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
# Automated smoke test for the phpmyadmin container.
3+
# Builds the image, runs it, waits for apache to come up on port 80 and
4+
# asserts that the phpMyAdmin app page actually renders (not just apache).
5+
set -e
6+
7+
IMG=phpmyadmin-test
8+
CN=phpmyadmin-test-run
9+
10+
cleanup() { docker rm -f "$CN" >/dev/null 2>&1 || true; }
11+
trap cleanup EXIT
12+
13+
fail() { echo "FAIL: $1"; exit 1; }
14+
15+
# raw HTTP GET over bash /dev/tcp (base image has neither wget nor curl)
16+
http_get() {
17+
docker exec "$CN" bash -c '
18+
p="$1"
19+
exec 3<>/dev/tcp/127.0.0.1/80
20+
printf "GET %s HTTP/1.0\r\nHost: localhost\r\n\r\n" "$p" >&3
21+
cat <&3
22+
' _ "$1"
23+
}
24+
25+
echo ">> building image"
26+
docker build -t "$IMG" .
27+
28+
echo ">> starting container"
29+
docker rm -f "$CN" >/dev/null 2>&1 || true
30+
docker run -d --name "$CN" \
31+
-e DISABLE_TLS=disable \
32+
-e SECRET=testblowfishsecret0123456789abcd \
33+
"$IMG" >/dev/null
34+
35+
echo ">> waiting for apache to listen on 80 (up to 120s)"
36+
up=0
37+
for _ in $(seq 1 60); do
38+
if docker exec "$CN" bash -c 'exec 3<>/dev/tcp/127.0.0.1/80' 2>/dev/null; then up=1; break; fi
39+
sleep 2
40+
done
41+
[ "$up" = 1 ] || fail "apache did not start listening on 80 in time"
42+
43+
echo ">> assert: container is running"
44+
[ "$(docker inspect -f '{{.State.Running}}' "$CN")" = true ] || fail "container not running"
45+
echo "ok - container running"
46+
47+
echo ">> assert: HTTP GET / returns a status line"
48+
status=$(http_get / | head -1 | tr -d '\r')
49+
echo "$status" | grep -q '^HTTP/' || fail "no HTTP status line (got: $status)"
50+
echo "ok - status line: $status"
51+
52+
echo ">> assert: served HTML contains phpMyAdmin"
53+
http_get /phpmyadmin/ | grep -q 'phpMyAdmin' || fail "phpMyAdmin app page did not render"
54+
echo "ok - phpMyAdmin page rendered"
55+
56+
echo ">> assert: no PHP Fatal in apache error log"
57+
docker exec "$CN" tail -n 200 /var/log/apache2/error.log 2>/dev/null | grep -i 'PHP Fatal' \
58+
&& fail "PHP Fatal error found in apache error log" || true
59+
echo "ok - no PHP Fatal in error log"
60+
61+
echo ""
62+
echo "ALL TESTS PASSED"

0 commit comments

Comments
 (0)