Skip to content

Feat/docs

Feat/docs #34

Workflow file for this run

name: Docker publish
on:
workflow_call:
pull_request:
jobs:
docker-publish:
name: Publish docker
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: 🐳 Prepare Docker
id: prep
env:
REPO_NAME: ghcr.io/${{ github.repository }}
shell: bash
run: |
# If it's a pull request ref, fallback to 'pr-<number>' format
if [[ "$GITHUB_REF_NAME" == *"pull/"* ]]; then
PR_NUMBER=$(echo "$GITHUB_REF_NAME" | grep -oP 'pull/\K[0-9]+')
TAG="pr-${PR_NUMBER}"
else
TAG=$(echo "$GITHUB_REF_NAME" | \
sed 's|:|-|g' | \
tr '[:upper:]' '[:lower:]' | \
sed 's/[^a-z0-9_.-]/-/g' | \
cut -c1-100 | \
sed 's/^[.-]*//' | \
sed 's/[-.]*$//')
fi
REPO_NAME=$(echo $REPO_NAME | tr '[:upper:]' '[:lower:]')
# Docker
echo "docker_image_name=${REPO_NAME}" >> $GITHUB_OUTPUT
echo "docker_image_tag=${TAG}" >> $GITHUB_OUTPUT
echo "docker_image=${REPO_NAME}:${TAG}" >> $GITHUB_OUTPUT
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🐳 Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: 🐳 Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.ref }}
restore-keys: |
${{ runner.os }}-buildx-refs/develop
${{ runner.os }}-buildx-
- name: 🐳 Build image
uses: docker/build-push-action@v6
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
file: Dockerfile
target: web-app-serve
push: false
load: true
provenance: false # XXX: Without this we have untagged images in ghcr.io
tags: ${{ steps.prep.outputs.docker_image }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: 🐳 Docker push
if: github.event_name != 'pull_request'
env:
DOCKER_IMAGE: ${{ steps.prep.outputs.docker_image }}
run: docker push $DOCKER_IMAGE