Skip to content
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

Add smoke-test shell script #217

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/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
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}
Loading