From 9c91d38a12d0027896d68a56c8155965fa6abdbd Mon Sep 17 00:00:00 2001 From: Jeff Mesnil Date: Thu, 26 Sep 2024 11:16:08 +0200 Subject: [PATCH] Add smoke-test shell script Smoke test is always run (on PR and commits to main) The image is pushed to the container registry only when a new tag is pushed to the repository Signed-off-by: Jeff Mesnil --- .github/workflows/publish-release.yml | 22 ++++++++- scripts/smoke-test.sh | 64 +++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 2 deletions(-) create mode 100755 scripts/smoke-test.sh diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 36bae2a..7964a9e 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -8,14 +8,20 @@ name: Build and push WildFly Docker images on: push: + branches: + - "main" tags: - "*" + pull_request: + branches: + - "main" jobs: image: env: # Put the "latest" tag on this JDK version JDK_VERSION_FOR_LATEST: 21 + IMAGE_TEST: wildfly-test:latest strategy: matrix: include: @@ -50,14 +56,26 @@ jobs: uses: docker/setup-qemu-action@v3.2.0 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3.6.1 + - name: Build WildFly images + id: docker_build + uses: docker/build-push-action@v6.7.0 + with: + load: true + tags: ${{ env.IMAGE_TEST }} + - name: Smoke Test + run: | + ./scripts/smoke-test.sh ${{ env.IMAGE_TEST }} - name: Docker Login to Quay.io + if: startsWith(github.event.ref, 'refs/tags/') uses: docker/login-action@v3.3.0 with: registry: ${{ secrets.REGISTRY }} username: ${{ secrets.REGISTRY_USER }} password: ${{ secrets.REGISTRY_PASSWORD }} - - name: Build and push JDK images - id: docker_build + - name: Push WildFly images to container registry + # Only push to the container registry when a new tag is pushed to the repository + id: docker_push + if: startsWith(github.event.ref, 'refs/tags/') uses: docker/build-push-action@v6.7.0 with: push: true diff --git a/scripts/smoke-test.sh b/scripts/smoke-test.sh new file mode 100755 index 0000000..52ff490 --- /dev/null +++ b/scripts/smoke-test.sh @@ -0,0 +1,64 @@ +WILDFLY_IMAGE=$1 + +check_http_status() { + response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8080/") + if [ "$response" -eq 200 ]; then + echo "Success! Received a 200 OK response." + return 0 + fi + return 1 +} + +check_wildfly_up_and_running() { + # wait until WildFLy is up and running + max_time=120 + retry_interval=5 + + start_time=$(date +%s) + while true; do + current_time=$(date +%s) + elapsed_time=$(( current_time - start_time )) + if [ $elapsed_time -ge $max_time ]; then + echo "Failed to get WildFly up and running within $max_time seconds." + return 1 + fi + docker container logs ${CONTAINER_ID} | grep WFLYSRV0025 + if [ $? -eq 0 ]; then + echo "Success! WildFly is up and running." + return 0 + fi + sleep $retry_interval + done +} + +check_wildfly_version() { + docker container logs ${CONTAINER_ID} | grep WFLYSRV0025 | grep ${WILDFLY_VERSION} + if [ $? -eq 0 ]; then + echo "Success! WildFly is using version ${WILDFLY_VERSION}." + return 0 + fi + return 1 +} + +WILDFLY_VERSION=$(grep "ENV WILDFLY_VERSION" Dockerfile | rev | cut -d' ' -f1 | rev) + +docker run --rm -p 8080:8080 ${WILDFLY_IMAGE} & +sleep 2 +CONTAINER_ID=$(docker ps -l -q) + +if ! check_wildfly_up_and_running; then + echo "WildFly did not boot up properly." + exit 1 +fi + +if ! check_http_status; then + echo "WildFly did not reply to the HTTP request." + exit 1 +fi + +if ! check_wildfly_version; then + echo "WildFly did not use the expected ${WILDFY_VERSION} version." + exit 1 +fi + +docker kill ${CONTAINER_ID} \ No newline at end of file