docker-hoster/.github/workflows/build-publish.yaml

94 lines
2.9 KiB
YAML

name: 'Build & Publish Container Image'
on:
push:
pull_request:
permissions:
contents: 'read'
jobs:
test-scripts:
runs-on: 'ubuntu-latest'
steps:
- name: 'Checkout Repository 🛎️'
uses: 'actions/checkout@v3'
- name: 'Test 🧪'
run: 'ruby .github/workflows/scripts/test/get-image-tags.unit.rb'
container-build:
needs: 'test-scripts'
runs-on: 'ubuntu-latest'
steps:
- name: 'Checkout Repository 🛎️'
uses: 'actions/checkout@v3'
- uses: 'docker/setup-buildx-action@v2'
- name: 'Get image tag names 🏷️'
id: 'tag-image'
run: |
echo "image_tags=$(
.github/workflows/scripts/get-image-tags.rb \
"${{ github.repository }}" \
"${{ github.ref_name }}" \
"${{ github.ref_type }}" \
"${{ github.event.repository.default_branch }}" \
)" >> "$GITHUB_OUTPUT"
- name: 'Set up QEMU 🦅'
id: 'qemu'
uses: 'docker/setup-qemu-action@v2'
with:
platforms: 'arm64'
- name: 'Set target build platforms 📝'
id: 'target-platforms'
run: |
echo "target_platforms=linux/amd64,linux/${{ steps.qemu.outputs.platforms }}/v8" >> "$GITHUB_OUTPUT"
- name: 'Build container 🐳'
id: 'build'
uses: 'docker/build-push-action@v3'
with:
file: 'Dockerfile'
tags: '${{ steps.tag-image.outputs.image_tags }}'
platforms: '${{ steps.target-platforms.outputs.target_platforms }}'
cache-from: 'type=gha'
cache-to: 'type=gha,mode=max'
outputs:
image_tags: '${{ steps.tag-image.outputs.image_tags }}'
qemu_platforms: '${{ steps.qemu.outputs.platforms }}'
docker_platforms: '${{ steps.target-platforms.outputs.target_platforms }}'
publish:
needs:
- 'container-build'
if: contains(needs.container-build.outputs.image_tags, ':latest')
runs-on: 'ubuntu-latest'
permissions:
packages: 'write'
steps:
- name: 'Checkout Repository 🛎️'
uses: 'actions/checkout@v3'
- uses: 'docker/setup-buildx-action@v2'
- name: 'Login to GitHub Container Registry 🔑'
uses: 'docker/login-action@v2'
with:
registry: 'ghcr.io'
username: '${{ github.repository_owner }}'
password: '${{ secrets.GITHUB_TOKEN }}'
- name: 'Set up QEMU 🦅'
uses: 'docker/setup-qemu-action@v2'
with:
platforms: '${{ needs.container-build.outputs.qemu_platforms }}'
- name: 'Publish to Registry 💨'
uses: 'docker/build-push-action@v3'
with:
file: 'Dockerfile'
push: true
tags: '${{ needs.container-build.outputs.image_tags }}'
platforms: '${{ needs.container-build.outputs.docker_platforms }}'
cache-from: 'type=gha'