ci: build docker image and healthcheck #2
This file contains 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: Build and Health Check Docker Images | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
Build: | |
strategy: | |
matrix: | |
image: ['s-pdf:standard', 's-pdf:standard with auth', 's-pdf:ultra-lite', 's-pdf:ultra-lite with auth', 's-pdf:lite', 's-pdf:lite with auth'] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3.5.2 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3.11.0 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- uses: gradle/gradle-build-action@v2.4.2 | |
with: | |
gradle-version: 7.6 | |
arguments: clean build | |
- name: Make Gradle wrapper executable | |
run: chmod +x gradlew | |
- name: Get version number | |
id: versionNumber | |
run: echo "::set-output name=versionNumber::$(./gradlew printVersion --quiet | tail -1)" | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2.1.0 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2.5.0 | |
- name: Build main Dockerfile | |
uses: docker/build-push-action@v4.0.0 | |
with: | |
context: . | |
dockerfile: ./Dockerfile | |
push: false | |
load: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
tags: s-pdf:standard | |
build-args: | |
VERSION_TAG=${{ steps.versionNumber.outputs.versionNumber }} | |
platforms: linux/amd64 | |
- name: Build Dockerfile-ultra-lite | |
uses: docker/build-push-action@v4.0.0 | |
with: | |
context: . | |
file: ./Dockerfile-ultra-lite | |
push: false | |
load: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
tags: s-pdf:ultra-lite | |
build-args: | |
VERSION_TAG=${{ steps.versionNumber.outputs.versionNumber }} | |
platforms: linux/amd64 | |
- name: Build Dockerfile-lite | |
uses: docker/build-push-action@v4.0.0 | |
with: | |
context: . | |
file: ./Dockerfile-lite | |
push: false | |
load: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
tags: s-pdf:lite | |
build-args: | |
VERSION_TAG=${{ steps.versionNumber.outputs.versionNumber }} | |
platforms: linux/amd64 | |
# - name: Build main Dockerfile | |
# uses: docker/build-push-action@v4.0.0 | |
# with: | |
# context: . | |
# dockerfile: ./Dockerfile | |
# push: false | |
# cache-from: type=gha | |
# cache-to: type=gha,mode=max | |
# tags: s-pdf:standard | |
# build-args: | |
# VERSION_TAG=${{ steps.versionNumber.outputs.versionNumber }} | |
# platforms: linux/arm64 | |
# - name: Build Dockerfile-ultra-lite | |
# uses: docker/build-push-action@v4.0.0 | |
# with: | |
# context: . | |
# file: ./Dockerfile-ultra-lite | |
# push: false | |
# cache-from: type=gha | |
# cache-to: type=gha,mode=max | |
# tags: s-pdf:ultra-lite | |
# build-args: | |
# VERSION_TAG=${{ steps.versionNumber.outputs.versionNumber }} | |
# platforms: linux/arm64 | |
# - name: Build Dockerfile-lite | |
# uses: docker/build-push-action@v4.0.0 | |
# with: | |
# context: . | |
# file: ./Dockerfile-lite | |
# push: false | |
# cache-from: type=gha | |
# cache-to: type=gha,mode=max | |
# tags: s-pdf:lite | |
# build-args: | |
# VERSION_TAG=${{ steps.versionNumber.outputs.versionNumber }} | |
# platforms: linux/arm64 | |
- name: Run and check Docker image ${{ matrix.image }} | |
run: | | |
IMAGE=${{ matrix.image }} | |
AUTH=false | |
HEALTH_CMD="curl -f http://localhost:8080/api/v1/status | grep -q UP && curl -fL http://localhost:8080/ | grep -qv 'Please sign in'" | |
if [[ $IMAGE == *"with auth"* ]]; then | |
AUTH=true | |
HEALTH_CMD="curl -fL http://localhost:8080/ | grep -q 'Please sign in'" | |
IMAGE=${IMAGE% with auth} | |
fi | |
CONTAINER_ID=$(docker run -d -e DOCKER_ENABLE_SECURITY=$AUTH -e SECURITY_ENABLE_LOGIN=$AUTH --health-cmd="$HEALTH_CMD" --health-interval=5s --health-timeout=5s --health-retries=6 $IMAGE) | |
for i in {1..12} | |
do | |
HEALTH_STATUS=$(docker inspect --format='{{.State.Health.Status}}' $CONTAINER_ID) | |
if [ "$HEALTH_STATUS" = "healthy" ] | |
then | |
echo "Container is healthy" | |
docker rm -f $CONTAINER_ID | |
break | |
fi | |
sleep 5 | |
done | |
if [ "$HEALTH_STATUS" != "healthy" ] | |
then | |
exit 1 | |
fi |