ci: add a basic smoke test check #49
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Check the Docker image builds for a PR | |
| on: | |
| pull_request: | |
| jobs: | |
| lint_dockerfile: | |
| name: Lint Dockerfile | |
| runs-on: ubuntu-latest | |
| steps: | |
| - | |
| name: Checkout github repository | |
| uses: actions/checkout@v6 | |
| - | |
| name: Lint Dockerfile with hadolint | |
| uses: hadolint/hadolint-action@v3.3.0 | |
| with: | |
| dockerfile: Dockerfile | |
| check_build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - | |
| name: Checkout github repository | |
| uses: actions/checkout@v6 | |
| - | |
| name: Setup Docker buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - | |
| name: Set pull request build arguments | |
| id: pr_meta | |
| run: | | |
| appGitRef=develop | |
| appAddSha=true | |
| echo "appGitRef=$appGitRef" >> "$GITHUB_OUTPUT" | |
| echo "appAddSha=$appAddSha" >> "$GITHUB_OUTPUT" | |
| - | |
| name: Build Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| platforms: linux/amd64 | |
| build-args: | | |
| VERSION_PHP=8.4 | |
| VERSION_COMPOSER=lts | |
| APP_GH_REF=${{ steps.pr_meta.outputs.appGitRef }} | |
| APP_GH_ADD_SHA=${{ steps.pr_meta.outputs.appAddSha }} | |
| tags: librebooking-pr:${{ github.sha }} | |
| load: true | |
| push: false | |
| - | |
| name: Smoke test image | |
| run: | | |
| set -euo pipefail | |
| image_tag="librebooking-pr:${GITHUB_SHA}" | |
| smoke_network="librebooking-smoke-net" | |
| docker network create "${smoke_network}" | |
| docker run --detach \ | |
| --name librebooking-db \ | |
| --network "${smoke_network}" \ | |
| --env MYSQL_ROOT_PASSWORD=root \ | |
| --env MYSQL_DATABASE=librebooking \ | |
| --env MYSQL_USER=librebooking \ | |
| --env MYSQL_PASSWORD=librebooking \ | |
| mysql:8.0 | |
| for attempt in $(seq 1 30); do | |
| if docker exec librebooking-db mysqladmin ping --host 127.0.0.1 --user root --password=root --silent; then | |
| break | |
| fi | |
| if [ "${attempt}" = "30" ]; then | |
| echo "Smoke test failed: MySQL did not become ready" >&2 | |
| docker logs librebooking-db || true | |
| exit 1 | |
| fi | |
| sleep 2 | |
| done | |
| docker create --name librebooking-smoke-src "${image_tag}" >/dev/null | |
| docker cp librebooking-smoke-src:/var/www/html/database_schema /tmp/librebooking-database_schema | |
| docker rm librebooking-smoke-src | |
| cat \ | |
| /tmp/librebooking-database_schema/create-db.sql \ | |
| /tmp/librebooking-database_schema/create-schema.sql \ | |
| /tmp/librebooking-database_schema/create-data.sql \ | |
| | docker exec --interactive librebooking-db mysql --user root --password=root | |
| docker run --detach \ | |
| --name librebooking-smoke \ | |
| --network "${smoke_network}" \ | |
| --publish 18080:8080 \ | |
| --env LB_DATABASE_HOSTSPEC=librebooking-db \ | |
| --env LB_DATABASE_NAME=librebooking \ | |
| --env LB_DATABASE_USER=librebooking \ | |
| --env LB_DATABASE_PASSWORD=librebooking \ | |
| "${image_tag}" | |
| for attempt in $(seq 1 30); do | |
| if curl --silent --show-error --fail --max-time 2 http://127.0.0.1:18080/Web/ >/dev/null; then | |
| echo "Connected to docker image sucessfully" | |
| break | |
| fi | |
| if [ "${attempt}" = "30" ]; then | |
| echo "Smoke test failed: HTTP endpoint did not become ready" >&2 | |
| docker logs librebooking-smoke || true | |
| exit 1 | |
| fi | |
| sleep 2 | |
| done | |
| docker exec librebooking-smoke php -m | grep -E '^(gd|ldap|mysqli|timezonedb)$' | |
| - | |
| name: Dump smoke logs on failure | |
| if: failure() | |
| run: | | |
| docker logs librebooking-smoke || true | |
| docker logs librebooking-db || true | |
| - | |
| name: Cleanup smoke containers | |
| if: always() | |
| run: | | |
| docker rm --force librebooking-smoke >/dev/null 2>&1 || true | |
| docker rm --force librebooking-db >/dev/null 2>&1 || true | |
| docker network rm librebooking-smoke-net >/dev/null 2>&1 || true | |
| rm -rf /tmp/librebooking-database_schema |