-
Notifications
You must be signed in to change notification settings - Fork 32
ci: add a basic smoke test check #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| name: Check the Docker image builds for a PR | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| pull_request: | ||
|
|
||
| jobs: | ||
|
|
@@ -19,22 +20,31 @@ jobs: | |
|
|
||
| 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: 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@v7 | ||
|
|
@@ -44,7 +54,74 @@ jobs: | |
| 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 }} | ||
| load: false | ||
| 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 \ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same remark as above
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without a database Librebooking will give an error message when trying to access it. |
||
| --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 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would curl the In a future release, I would investigate the utilization of web page test automation tools, such as Playwright. Please note that upstream could benefit from such tools.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is Playwright looks interesting. I would like a LOT more actual testing of the app in the upstream project. |
||
| 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 | ||
JohnVillalovos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
JohnVillalovos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| docker rm --force librebooking-smoke-src >/dev/null 2>&1 || true | ||
| rm -rf /tmp/librebooking-database_schema | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given what you are testing, I am not sure you needto create the database
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without a database Librebooking will give an error message when trying to access it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is odd.
When I run librebooking without any sql container, I don't have any issue.
Please note that the URL is
http://localhost:8080when I run from my laptopThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But when you go to http://localhost:8080/Web/ it will give a 500 😢 if no SQL.
All that is testing is
.htaccessis working.