Skip to content

Commit bdd7eac

Browse files
committed
add test.sh + gate ci behind tests
1 parent 85baeb1 commit bdd7eac

4 files changed

Lines changed: 122 additions & 10 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

get-version.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ export DIRVISH_VERSION=$(docker run --rm -t "$IMG" dpkg --list dirvish | grep '^
66
[ -z "$DEBIAN_VERSION" ] && exit 1
77

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

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

test.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/sh
2+
# Automated smoke test for the dirvish container.
3+
# dirvish is a backup scheduler (not a network server), so the meaningful
4+
# check is: the container comes up, the runit-managed services (cron +
5+
# postfix) are running, and dirvish itself is functional (parses a master.conf
6+
# and reports its version).
7+
set -e
8+
9+
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
10+
IMG=dirvish-test
11+
CN=dirvish-test-run
12+
13+
cleanup() { docker rm -f "$CN" >/dev/null 2>&1 || true; }
14+
trap cleanup EXIT
15+
16+
fail() { echo "FAIL: $1"; exit 1; }
17+
18+
echo ">> building image"
19+
docker build -t "$IMG" "$SCRIPT_DIR"
20+
21+
echo ">> starting container"
22+
docker rm -f "$CN" >/dev/null 2>&1 || true
23+
# mount the repo's dirvish config so entrypoint drops a master.conf into
24+
# /etc/dirvish (dirvish needs one even to answer --version)
25+
docker run -d --name "$CN" -v "$SCRIPT_DIR/config/dirvish:/config:ro" "$IMG" >/dev/null
26+
27+
echo ">> waiting for runit services to come up (up to 60s)"
28+
up=0
29+
for _ in $(seq 1 30); do
30+
if docker exec "$CN" sv status /container/config/runit/cron 2>/dev/null | grep -q '^run:' \
31+
&& docker exec "$CN" sv status /container/config/runit/postfix 2>/dev/null | grep -q '^run:' \
32+
&& docker exec "$CN" sh -c "ps aux | grep -q '[s]bin/master'" 2>/dev/null; then
33+
up=1; break
34+
fi
35+
sleep 2
36+
done
37+
[ "$up" = 1 ] || fail "runit services did not reach 'run' state in time"
38+
39+
echo ">> assert: container is running"
40+
[ "$(docker inspect -f '{{.State.Running}}' "$CN")" = true ] || fail "container not running"
41+
echo "ok - container running"
42+
43+
echo ">> assert: runsvdir is PID 1"
44+
docker exec "$CN" sh -c "ps -o comm= -p 1 | grep -q runsvdir" || fail "runsvdir is not PID 1"
45+
echo "ok - runsvdir supervising"
46+
47+
echo ">> assert: runit reports cron service running"
48+
docker exec "$CN" sv status /container/config/runit/cron | grep -q '^run:' || fail "cron service not running"
49+
echo "ok - cron service up"
50+
51+
echo ">> assert: runit reports postfix service running"
52+
docker exec "$CN" sv status /container/config/runit/postfix | grep -q '^run:' || fail "postfix service not running"
53+
echo "ok - postfix service up"
54+
55+
echo ">> assert: cron process present"
56+
docker exec "$CN" sh -c "ps aux | grep -q '[/]usr/sbin/cron'" || fail "cron process not running"
57+
echo "ok - cron running"
58+
59+
echo ">> assert: postfix master process present"
60+
docker exec "$CN" sh -c "ps aux | grep -q '[s]bin/master'" || fail "postfix master not running"
61+
echo "ok - postfix master running"
62+
63+
echo ">> assert: dirvish parses master.conf and reports its version"
64+
ver=$(docker exec "$CN" dirvish --version 2>&1) || fail "dirvish --version exited non-zero (got: $ver)"
65+
echo "$ver" | grep -qi 'dirvish version' || fail "dirvish did not report a version (got: $ver)"
66+
echo "ok - dirvish version: $(echo "$ver" | tr -d '\r' | head -1)"
67+
68+
echo ""
69+
echo "ALL TESTS PASSED"

0 commit comments

Comments
 (0)