Skip to content

Commit 6210d1d

Browse files
ci: add a basic smoke test check
This runs the docker image and attempts to connect to it.
1 parent dd43033 commit 6210d1d

1 file changed

Lines changed: 89 additions & 12 deletions

File tree

.github/workflows/build_pull_request.yml

Lines changed: 89 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Check the Docker image builds for a PR
22

33
on:
4+
workflow_dispatch:
45
pull_request:
56

67
jobs:
@@ -19,22 +20,31 @@ jobs:
1920

2021
check_build:
2122
runs-on: ubuntu-latest
23+
env:
24+
APP_GH_REF: develop
25+
APP_GH_ADD_SHA: "true"
26+
services:
27+
mysql:
28+
image: mysql:8.0
29+
env:
30+
MYSQL_ROOT_PASSWORD: root
31+
MYSQL_DATABASE: librebooking
32+
MYSQL_USER: librebooking
33+
MYSQL_PASSWORD: librebooking
34+
ports:
35+
- 3306:3306
36+
options: >-
37+
--health-cmd="mysqladmin ping -h 127.0.0.1 -proot"
38+
--health-interval=10s
39+
--health-timeout=5s
40+
--health-retries=5
2241
steps:
2342
-
2443
name: Checkout github repository
2544
uses: actions/checkout@v6
2645
-
2746
name: Setup Docker buildx
2847
uses: docker/setup-buildx-action@v4
29-
-
30-
name: Set pull request build arguments
31-
id: pr_meta
32-
run: |
33-
appGitRef=develop
34-
appAddSha=true
35-
36-
echo "appGitRef=$appGitRef" >> "$GITHUB_OUTPUT"
37-
echo "appAddSha=$appAddSha" >> "$GITHUB_OUTPUT"
3848
-
3949
name: Build Docker image
4050
uses: docker/build-push-action@v7
@@ -44,7 +54,74 @@ jobs:
4454
build-args: |
4555
VERSION_PHP=8.4
4656
VERSION_COMPOSER=lts
47-
APP_GH_REF=${{ steps.pr_meta.outputs.appGitRef }}
48-
APP_GH_ADD_SHA=${{ steps.pr_meta.outputs.appAddSha }}
49-
load: false
57+
APP_GH_REF=${{ env.APP_GH_REF }}
58+
APP_GH_ADD_SHA=${{ env.APP_GH_ADD_SHA }}
59+
tags: librebooking-pr:${{ github.sha }}
60+
load: true
5061
push: false
62+
-
63+
name: Smoke test image
64+
run: |
65+
set -euo pipefail
66+
lb_image_tag="librebooking-pr:${GITHUB_SHA}"
67+
mysql_service_id="${{ job.services.mysql.id }}"
68+
69+
docker create --name librebooking-smoke-src "${lb_image_tag}" >/dev/null
70+
docker cp librebooking-smoke-src:/var/www/html/database_schema /tmp/librebooking-database_schema
71+
docker rm librebooking-smoke-src
72+
73+
cat \
74+
/tmp/librebooking-database_schema/create-db.sql \
75+
/tmp/librebooking-database_schema/create-schema.sql \
76+
| docker exec --interactive "${mysql_service_id}" mysql --user root --password=root
77+
78+
docker run --rm \
79+
--add-host host.docker.internal:host-gateway \
80+
"${lb_image_tag}" \
81+
php /var/www/html/phing-tasks/UpgradeDbTask.php \
82+
librebooking \
83+
librebooking \
84+
host.docker.internal \
85+
librebooking \
86+
/var/www/html/database_schema
87+
88+
docker run --detach \
89+
--name librebooking-smoke \
90+
--add-host host.docker.internal:host-gateway \
91+
--publish 18080:8080 \
92+
--env LB_DATABASE_HOSTSPEC=host.docker.internal \
93+
--env LB_DATABASE_NAME=librebooking \
94+
--env LB_DATABASE_USER=librebooking \
95+
--env LB_DATABASE_PASSWORD=librebooking \
96+
"${lb_image_tag}"
97+
98+
for attempt in $(seq 1 30); do
99+
if curl --silent --show-error --fail --max-time 2 http://127.0.0.1:18080/Web/; then
100+
echo "Connected to docker image successfully"
101+
break
102+
fi
103+
104+
if [ "${attempt}" = "30" ]; then
105+
echo "Smoke test failed: HTTP endpoint did not become ready" >&2
106+
docker logs librebooking-smoke || true
107+
docker logs "${{ job.services.mysql.id }}" || true
108+
exit 1
109+
fi
110+
111+
sleep 2
112+
done
113+
114+
modules_count=$(docker exec librebooking-smoke php -m | grep -Ec '^(gd|ldap|mysqli|timezonedb)$' || true)
115+
if [ "${modules_count}" -ne 4 ]; then
116+
echo "Smoke test failed: expected 4 required PHP modules (gd, ldap, mysqli, timezonedb), but found ${modules_count}"
117+
docker exec librebooking-smoke php -m || true
118+
exit 1
119+
fi
120+
121+
-
122+
name: Cleanup smoke container
123+
if: always()
124+
run: |
125+
docker rm --force librebooking-smoke >/dev/null 2>&1 || true
126+
docker rm --force librebooking-smoke-src >/dev/null 2>&1 || true
127+
rm -rf /tmp/librebooking-database_schema

0 commit comments

Comments
 (0)