ci: add a basic smoke test check #71
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: | |
| workflow_dispatch: | |
| 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 | |
| env: | |
| APP_GH_REF: develop | |
| APP_GH_ADD_SHA: "true" | |
| services: | |
| mysql: | |
| image: mysql:8.0 | |
| env: | |
| MYSQL_ROOT_PASSWORD: root | |
| MYSQL_DATABASE: librebooking | |
| MYSQL_USER: librebooking | |
| MYSQL_PASSWORD: librebooking | |
| ports: | |
| - 3306:3306 | |
| options: >- | |
| --health-cmd="mysqladmin ping -h 127.0.0.1 -proot" | |
| --health-interval=10s | |
| --health-timeout=5s | |
| --health-retries=5 | |
| steps: | |
| - | |
| name: Checkout github repository | |
| uses: actions/checkout@v6 | |
| - | |
| name: Setup Docker buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - | |
| name: Build Docker image | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| platforms: linux/amd64 | |
| build-args: | | |
| VERSION_PHP=8.4 | |
| VERSION_COMPOSER=lts | |
| APP_GH_REF=${{ env.APP_GH_REF }} | |
| APP_GH_ADD_SHA=${{ env.APP_GH_ADD_SHA }} | |
| tags: librebooking-pr:${{ github.sha }} | |
| load: true | |
| push: false | |
| - | |
| name: Smoke test image | |
| run: | | |
| set -euo pipefail | |
| lb_image_tag="librebooking-pr:${GITHUB_SHA}" | |
| mysql_service_id="${{ job.services.mysql.id }}" | |
| docker create --name librebooking-smoke-src "${lb_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 \ | |
| | docker exec --interactive "${mysql_service_id}" mysql --user root --password=root | |
| docker run --rm \ | |
| --add-host host.docker.internal:host-gateway \ | |
| "${lb_image_tag}" \ | |
| php /var/www/html/phing-tasks/UpgradeDbTask.php \ | |
| librebooking \ | |
| librebooking \ | |
| host.docker.internal \ | |
| librebooking \ | |
| /var/www/html/database_schema | |
| docker run --detach \ | |
| --name librebooking-smoke \ | |
| --add-host host.docker.internal:host-gateway \ | |
| --publish 18080:8080 \ | |
| --env LB_DATABASE_HOSTSPEC=host.docker.internal \ | |
| --env LB_DATABASE_NAME=librebooking \ | |
| --env LB_DATABASE_USER=librebooking \ | |
| --env LB_DATABASE_PASSWORD=librebooking \ | |
| "${lb_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/; then | |
| echo "Connected to docker image successfully" | |
| break | |
| fi | |
| if [ "${attempt}" = "30" ]; then | |
| echo "Smoke test failed: HTTP endpoint did not become ready" >&2 | |
| docker logs librebooking-smoke || true | |
| docker logs "${{ job.services.mysql.id }}" || true | |
| exit 1 | |
| fi | |
| sleep 2 | |
| done | |
| modules_count=$(docker exec librebooking-smoke php -m | grep -Ec '^(gd|ldap|mysqli|timezonedb)$' || true) | |
| if [ "${modules_count}" -ne 4 ]; then | |
| echo "Smoke test failed: expected 4 required PHP modules (gd, ldap, mysqli, timezonedb), but found ${modules_count}" | |
| docker exec librebooking-smoke php -m || true | |
| exit 1 | |
| fi | |
| - | |
| name: Cleanup smoke container | |
| if: always() | |
| run: | | |
| docker rm --force librebooking-smoke >/dev/null 2>&1 || true | |
| docker rm --force librebooking-smoke-src >/dev/null 2>&1 || true | |
| rm -rf /tmp/librebooking-database_schema |