Build and Publish Docker Images #414
This file contains hidden or 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 Publish Docker Images | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "23 0 * * *" | |
jobs: | |
buildmatrix: | |
name: Create Build Matrix | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.2' | |
- name: Cache Setup | |
id: cache | |
uses: actions/cache@v4 | |
with: | |
path: .github/matrix.cache/ | |
key: ${{ runner.os }}-matrix-${{ github.run_id }} | |
restore-keys: | | |
${{ runner.os }}-matrix- | |
- name: Set up matrix | |
id: set-matrix | |
run: | | |
php .github/matrix.php >> $GITHUB_OUTPUT | |
build: | |
needs: buildmatrix | |
name: Build Docker Image for ${{ matrix.release.type }} | |
runs-on: ubuntu-22.04 # see dokuwiki/docker#27 | |
if: ${{ needs.buildmatrix.outputs.matrix != '[]' }} | |
strategy: | |
matrix: ${{fromJson(needs.buildmatrix.outputs.matrix)}} | |
fail-fast: false | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v4 | |
- | |
name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- | |
name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: splitbrain | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- | |
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: | | |
# Initialize tag arrays | |
TAGS=() | |
# DockerHub Tags | |
if [[ "${{ matrix.release.type }}" == "master" ]]; then | |
TAGS+=("dokuwiki/dokuwiki:master") | |
else | |
TAGS+=("dokuwiki/dokuwiki:${{ matrix.release.date }}") | |
TAGS+=("dokuwiki/dokuwiki:${{ matrix.release.type }}") | |
if [[ "${{ matrix.release.type }}" == "stable" ]]; then | |
TAGS+=("dokuwiki/dokuwiki:latest") | |
fi | |
fi | |
# GitHub Packages Tags | |
if [[ "${{ matrix.release.type }}" == "master" ]]; then | |
TAGS+=("ghcr.io/dokuwiki/dokuwiki:master") | |
else | |
TAGS+=("ghcr.io/dokuwiki/dokuwiki:${{ matrix.release.date }}") | |
TAGS+=("ghcr.io/dokuwiki/dokuwiki:${{ matrix.release.type }}") | |
if [[ "${{ matrix.release.type }}" == "stable" ]]; then | |
TAGS+=("ghcr.io/dokuwiki/dokuwiki:latest") | |
fi | |
fi | |
# Convert array to multiline string for GitHub Actions | |
{ | |
echo "tags<<EOF" | |
printf "%s\n" "${TAGS[@]}" | |
echo "EOF" | |
} >> $GITHUB_OUTPUT | |
- | |
name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
cache-from: type=gha, scope=${{ github.workflow }} | |
cache-to: type=gha, scope=${{ github.workflow }} | |
tags: ${{ steps.docker_tags.outputs.tags }} | |
build-args: | | |
DOKUWIKI_VERSION=${{ matrix.release.type == 'master' && 'master' || matrix.release.date }} | |
workflow-keepalive: | |
if: github.event_name == 'schedule' | |
runs-on: ubuntu-latest | |
permissions: | |
actions: write | |
steps: | |
- uses: liskin/gh-workflow-keepalive@v1 | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |