Skip to content

Fix container build

Fix container build #6

name: Build and Push Docker Image to GHCR
on:
push:
branches:
- main # Trigger on pushes to the main branch
workflow_dispatch: # Allow manual triggering
jobs:
build_and_push:
name: Build and Push Docker Image
runs-on: ubuntu-latest # Using ubuntu-latest for simplicity, consistent with Dockerfile's base image
permissions:
contents: read
packages: write # Necessary for pushing to GHCR
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all # Enable building for multiple platforms
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare Docker Tags
id: docker_tags
run: |
# Define the image name based on the GitHub repository
IMAGE_NAME="ghcr.io/${{ github.repository }}"
# Use a simple 'latest' tag for pushes to main, or a custom tag for workflow_dispatch if desired.
# For a more robust setup, you might use:
# - A version tag from a Git tag (e.g., if on: push: tags: )
# - A short commit SHA for development builds
TAGS="${IMAGE_NAME}:latest"
# If you want to use the branch name as a tag (e.g., ghcr.io/user/repo:main)
# if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
# TAGS="${IMAGE_NAME}:main,${TAGS}"
# fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: . # Build context is the current directory
platforms: linux/amd64,linux/arm64 # Building for common architectures
push: true
tags: ${{ steps.docker_tags.outputs.tags }}
# You might need build-args if your Dockerfile relies on them.
# For example, if you want to pass DOKUWIKI_VERSION:
# build-args: |
# DOKUWIKI_VERSION=stable
# Or if you want it dynamic based on a variable:
# build-args: |
# DOKUWIKI_VERSION=${{ env.DOKUWIKI_VERSION_ARG }}
cache-from: type=gha, scope=${{ github.workflow }}
cache-to: type=gha, mode=max, scope=${{ github.workflow }} # Use mode=max for better caching