build #14
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 | |
concurrency: | |
group: build-${{ github.ref }} | |
cancel-in-progress: true | |
on: | |
schedule: | |
- cron: '0 6 */7 * *' | |
push: | |
branches: | |
- dev | |
tags: | |
- 'v*' | |
paths-ignore: | |
- '**.md' | |
env: | |
DOCKERHUB_SLUG: k44sh/stunnel | |
GHCR_SLUG: ghcr.io/k44sh/stunnel | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- | |
name: Checkout | |
id: checkout | |
uses: actions/checkout@v3 | |
- | |
name: Variables | |
id: vars | |
run: | | |
echo "container_name=stunnel" >> $GITHUB_OUTPUT | |
echo "timeout=120" >> $GITHUB_OUTPUT | |
- | |
name: Cache Docker | |
id: cache | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.docker-cache | |
key: ${{ runner.os }}-docker-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-docker- | |
- | |
name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: | | |
${{ env.DOCKERHUB_SLUG }} | |
${{ env.GHCR_SLUG }} | |
tags: | | |
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/dev' }} | |
type=raw,value=edge,enable=${{ github.event_name == 'schedule' }} | |
type=match,pattern=v(.*),group=1 | |
labels: | | |
org.opencontainers.image.title=Stunnel Docker | |
org.opencontainers.image.url=https://github.com/k44sh/stunnel | |
org.opencontainers.image.source=https://github.com/k44sh/stunnel | |
org.opencontainers.image.documentation=https://github.com/k44sh/stunnel | |
org.opencontainers.image.description=Stunnel Docker image based on Alpine Linux | |
org.opencontainers.image.licenses=MIT | |
org.opencontainers.image.vendor=k44sh | |
- | |
name: Set up QEMU | |
id: set-qemu | |
uses: docker/setup-qemu-action@v2 | |
- | |
name: Set up Docker Buildx | |
id: set-buildx | |
uses: docker/setup-buildx-action@v2 | |
- | |
name: Login to DockerHub | |
id: login-dh | |
if: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/dev' || github.event_name == 'schedule' }} | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- | |
name: Login to GHCR | |
id: login-ghcr | |
if: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/dev' || github.event_name == 'schedule' }} | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- | |
name: Build Prod | |
id: build-prod | |
if: ${{ startsWith(github.ref, 'refs/tags/v') || github.event_name == 'schedule' }} | |
uses: docker/bake-action@v2 | |
with: | |
files: | | |
./docker-bake.hcl | |
${{ steps.meta.outputs.bake-file }} | |
targets: image-prod | |
push: true | |
set: | | |
*.cache-from=type=gha | |
*.cache-to=type=gha,mode=max | |
- | |
name: Build Dev | |
id: build-dev | |
if: ${{ github.ref == 'refs/heads/dev' }} | |
uses: docker/bake-action@v2 | |
with: | |
files: | | |
./docker-bake.hcl | |
${{ steps.meta.outputs.bake-file }} | |
targets: image-dev | |
push: true | |
set: | | |
*.cache-from=type=gha | |
*.cache-to=type=gha,mode=max | |
- | |
name: Run Test | |
id: test | |
if: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/dev' || github.event_name == 'schedule' }} | |
run: | | |
docker run --rm -d --name ${{ steps.vars.outputs.container_name }} ${{ env.DOCKERHUB_SLUG }}:${{ steps.meta.outputs.version }} | |
for i in $(seq ${{ steps.vars.outputs.timeout }}); do | |
status=$(docker inspect -f '{{ .State.Health.Status }}' ${{ steps.vars.outputs.container_name }} 2>/dev/null) | |
if [[ $? -eq 0 ]]; then | |
if [[ "${status}" == "healthy" ]]; then | |
docker logs ${{ steps.vars.outputs.container_name }} | |
echo -e "\n✅ The container is \e[1;32mhealthy\e[0m after \e[1;5m${i}\e[0m seconds\n" | |
docker stop ${{ steps.vars.outputs.container_name }} >/dev/null 2>&1 | |
exit 0 | |
elif [[ "${status}" == "unhealthy" ]]; then | |
echo -e "❌ The container is \e[1;33munhealthy\e[0m" | |
docker stop ${{ steps.vars.outputs.container_name }} >/dev/null 2>&1 | |
exit 1 | |
elif [[ "${status}" == "starting" ]]; then | |
echo "... starting" | |
else | |
echo -e "❓ The container is in \e[1;31munknown\e[0m state ($status)" | |
docker stop ${{ steps.vars.outputs.container_name }} >/dev/null 2>&1 | |
exit 1 | |
fi | |
else | |
echo -e "❌ \e[1;31mDocker error\e[0m" | |
docker logs ${{ steps.vars.outputs.container_name }} | |
exit 1 | |
fi | |
sleep 1 | |
done | |
- | |
name: Check Manifest | |
id: manifest | |
if: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/dev' || github.event_name == 'schedule' }} | |
run: | | |
docker buildx imagetools inspect ${{ env.DOCKERHUB_SLUG }}:${{ steps.meta.outputs.version }} | |
docker buildx imagetools inspect ${{ env.GHCR_SLUG }}:${{ steps.meta.outputs.version }} | |
- | |
name: Inspect Image | |
id: inspect | |
if: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/dev' || github.event_name == 'schedule' }} | |
run: | | |
docker pull ${{ env.DOCKERHUB_SLUG }}:${{ steps.meta.outputs.version }} | |
docker image inspect ${{ env.DOCKERHUB_SLUG }}:${{ steps.meta.outputs.version }} | |
docker pull ${{ env.GHCR_SLUG }}:${{ steps.meta.outputs.version }} | |
docker image inspect ${{ env.GHCR_SLUG }}:${{ steps.meta.outputs.version }} |