Skip to content

Commit

Permalink
Merge pull request #217 from jmesnil/test
Browse files Browse the repository at this point in the history
Add smoke-test shell script
  • Loading branch information
jmesnil authored Sep 26, 2024
2 parents 1b3178f + 9c91d38 commit 8ac1300
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -50,14 +56,26 @@ jobs:
uses: docker/[email protected]
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Build WildFly images
id: docker_build
uses: docker/[email protected]
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/[email protected]
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/[email protected]
with:
push: true
Expand Down
64 changes: 64 additions & 0 deletions scripts/smoke-test.sh
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 8ac1300

Please sign in to comment.