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

ci: build docker image and healthcheck #629

Closed
wants to merge 10 commits into from
242 changes: 242 additions & 0 deletions .github/workflows/docker-dryrun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
name: Build and Health Check Docker Images

on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
Build:
runs-on: ubuntu-latest
steps:

- uses: actions/[email protected]

- name: Set up JDK 17
uses: actions/[email protected]
with:
java-version: '17'
distribution: 'temurin'

- uses: gradle/[email protected]
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/[email protected]

- name: Set up Docker Buildx
uses: docker/[email protected]

- name: Build main Dockerfile
uses: docker/[email protected]
with:
context: .
file: ./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 lite Dockerfile
uses: docker/[email protected]
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 ultra-lite Dockerfile
uses: docker/[email protected]
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: Run and check Docker image s-pdf:standard without auth
run: |
IMAGE="s-pdf:standard"
AUTH=false
HEALTH_CMD="curl -f http://localhost:8080/api/v1/info/status | grep -q UP && curl -fL http://localhost:8080/ | grep -qv 'Please sign in'"
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)
echo "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)
echo "Health Status: $HEALTH_STATUS"
if [ "$HEALTH_STATUS" = "healthy" ]
then
echo "Container is healthy"
docker rm -f $CONTAINER_ID
break
fi
sleep 5
done
if [ "$HEALTH_STATUS" != "healthy" ]
then
echo "Container has failed to start after 60 seconds"
docker logs $CONTAINER_ID
exit 1
fi

- name: Run and check Docker image s-pdf:standard with auth
run: |
IMAGE="s-pdf:standard"
AUTH=true
HEALTH_CMD="curl -fL http://localhost:8080/ | grep -q 'Please sign in'"
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)
echo "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)
echo "Health Status: $HEALTH_STATUS"
if [ "$HEALTH_STATUS" = "healthy" ]
then
echo "Container is healthy"
docker rm -f $CONTAINER_ID
break
fi
sleep 5
done
if [ "$HEALTH_STATUS" != "healthy" ]
then
echo "Container has failed to start after 60 seconds"
docker logs $CONTAINER_ID
exit 1
fi

- name: Run and check Docker image s-pdf:lite without auth
run: |
IMAGE="s-pdf:lite"
AUTH=false
HEALTH_CMD="curl -f http://localhost:8080/api/v1/info/status | grep -q UP && curl -fL http://localhost:8080/ | grep -qv 'Please sign in'"
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)
echo "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)
echo "Health Status: $HEALTH_STATUS"
if [ "$HEALTH_STATUS" = "healthy" ]
then
echo "Container is healthy"
docker rm -f $CONTAINER_ID
break
fi
sleep 5
done
if [ "$HEALTH_STATUS" != "healthy" ]
then
echo "Container has failed to start after 60 seconds"
docker logs $CONTAINER_ID
exit 1
fi

- name: Run and check Docker image s-pdf:lite with auth
run: |
IMAGE="s-pdf:lite"
AUTH=true
HEALTH_CMD="curl -fL http://localhost:8080/ | grep -q 'Please sign in'"
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)
echo "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)
echo "Health Status: $HEALTH_STATUS"
if [ "$HEALTH_STATUS" = "healthy" ]
then
echo "Container is healthy"
docker rm -f $CONTAINER_ID
break
fi
sleep 5
done
if [ "$HEALTH_STATUS" != "healthy" ]
then
echo "Container has failed to start after 60 seconds"
docker logs $CONTAINER_ID
exit 1
fi

- name: Run and check Docker image s-pdf:ultra-lite without auth
run: |
IMAGE="s-pdf:ultra-lite"
AUTH=false
HEALTH_CMD="curl -f http://localhost:8080/api/v1/info/status | grep -q UP && curl -fL http://localhost:8080/ | grep -qv 'Please sign in'"
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)
echo "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)
echo "Health Status: $HEALTH_STATUS"
if [ "$HEALTH_STATUS" = "healthy" ]
then
echo "Container is healthy"
docker rm -f $CONTAINER_ID
break
fi
sleep 5
done
if [ "$HEALTH_STATUS" != "healthy" ]
then
echo "Container has failed to start after 60 seconds"
docker logs $CONTAINER_ID
exit 1
fi

- name: Run and check Docker image s-pdf:ultra-lite with auth
run: |
IMAGE="s-pdf:ultra-lite"
AUTH=true
HEALTH_CMD="curl -fL http://localhost:8080/ | grep -q 'Please sign in'"
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)
echo "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)
echo "Health Status: $HEALTH_STATUS"
if [ "$HEALTH_STATUS" = "healthy" ]
then
echo "Container is healthy"
docker rm -f $CONTAINER_ID
break
fi
sleep 5
done
if [ "$HEALTH_STATUS" != "healthy" ]
then
echo "Container has failed to start after 60 seconds"
docker logs $CONTAINER_ID
exit 1
fi