- Dev branch: GHCR only (ghcr.io/host-uk/*) - Main branch + tags: GHCR + Docker Hub (lthn/*) - Requires DOCKERHUB_USERNAME and DOCKERHUB_TOKEN secrets Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
205 lines
6.2 KiB
YAML
205 lines
6.2 KiB
YAML
# Host UK Container Images
|
|
#
|
|
# Dev branch: ghcr.io/host-uk/{core-dev,server-php}:dev
|
|
# Tags/Main: ghcr.io/host-uk/{core-dev,server-php}:latest + lthn/{core-dev,server-php}:latest
|
|
|
|
name: Build Images
|
|
|
|
on:
|
|
push:
|
|
branches: [dev, main]
|
|
tags: ['v*']
|
|
pull_request:
|
|
branches: [dev, main]
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
GHCR_REGISTRY: ghcr.io
|
|
|
|
jobs:
|
|
# ============================================================
|
|
# Build Docker Images
|
|
# ============================================================
|
|
docker:
|
|
name: Docker (${{ matrix.image }})
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
image:
|
|
- developer
|
|
- server-php
|
|
include:
|
|
- image: developer
|
|
ghcr_name: core-dev
|
|
dockerhub_name: core-dev
|
|
- image: server-php
|
|
ghcr_name: server-php
|
|
dockerhub_name: server-php
|
|
|
|
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 GHCR
|
|
if: github.event_name != 'pull_request'
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.GHCR_REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Login to Docker Hub
|
|
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Determine if release build
|
|
id: release
|
|
run: |
|
|
if [[ "${{ github.ref }}" == "refs/heads/main" ]] || [[ "${{ github.ref }}" == refs/tags/v* ]]; then
|
|
echo "is_release=true" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "is_release=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Extract metadata (GHCR only - dev builds)
|
|
if: steps.release.outputs.is_release == 'false'
|
|
id: meta-dev
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: |
|
|
${{ env.GHCR_REGISTRY }}/host-uk/${{ matrix.ghcr_name }}
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
flavor: |
|
|
latest=false
|
|
|
|
- name: Extract metadata (GHCR + Docker Hub - release builds)
|
|
if: steps.release.outputs.is_release == 'true'
|
|
id: meta-release
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: |
|
|
${{ env.GHCR_REGISTRY }}/host-uk/${{ matrix.ghcr_name }}
|
|
lthn/${{ matrix.dockerhub_name }}
|
|
tags: |
|
|
# main branch -> latest
|
|
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
|
|
# Semver tags (v1.0.0 -> 1.0.0, 1.0, 1, latest)
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
|
|
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
|
|
flavor: |
|
|
latest=false
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: ./${{ matrix.image }}
|
|
platforms: linux/amd64,linux/arm64
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
tags: ${{ steps.meta-dev.outputs.tags || steps.meta-release.outputs.tags }}
|
|
labels: ${{ steps.meta-dev.outputs.labels || steps.meta-release.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
# ============================================================
|
|
# Build LinuxKit Images (only on tags)
|
|
# ============================================================
|
|
linuxkit:
|
|
name: LinuxKit (${{ matrix.image }}-${{ matrix.arch }})
|
|
runs-on: ubuntu-latest
|
|
needs: docker
|
|
if: startsWith(github.ref, 'refs/tags/v')
|
|
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
image: [developer, server-php]
|
|
arch: [amd64, arm64]
|
|
format: [qcow2-bios, iso-bios]
|
|
include:
|
|
- image: developer
|
|
output_name: core-dev
|
|
- image: server-php
|
|
output_name: server-php
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install LinuxKit
|
|
run: |
|
|
curl -fsSL "https://github.com/linuxkit/linuxkit/releases/download/v1.5.3/linuxkit-linux-amd64" -o linuxkit
|
|
chmod +x linuxkit
|
|
sudo mv linuxkit /usr/local/bin/
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Login to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.GHCR_REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build LinuxKit Image
|
|
run: |
|
|
mkdir -p dist
|
|
linuxkit build \
|
|
--format ${{ matrix.format }} \
|
|
--name ./dist/${{ matrix.output_name }}-${{ matrix.arch }} \
|
|
./${{ matrix.image }}/linuxkit.yml
|
|
|
|
- name: Upload Artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: ${{ matrix.output_name }}-${{ matrix.arch }}-${{ matrix.format }}
|
|
path: ./dist/*
|
|
|
|
# ============================================================
|
|
# Release LinuxKit Images
|
|
# ============================================================
|
|
release-linuxkit:
|
|
name: Release LinuxKit Images
|
|
runs-on: ubuntu-latest
|
|
needs: linuxkit
|
|
if: startsWith(github.ref, 'refs/tags/v')
|
|
permissions:
|
|
contents: write
|
|
|
|
steps:
|
|
- name: Download all artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
path: ./dist
|
|
merge-multiple: true
|
|
|
|
- name: Generate checksums
|
|
run: |
|
|
cd dist
|
|
sha256sum * > checksums.txt
|
|
|
|
- name: Upload to Release
|
|
uses: softprops/action-gh-release@v1
|
|
with:
|
|
files: |
|
|
dist/*
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|