Workflow file for this run
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 Push Docker Image | |
on: | |
release: | |
types: [published] | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 # Use latest version | |
with: | |
fetch-depth: 1 # Shallow clone for faster checkout | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
version: latest | |
buildkitd-flags: --debug | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: arm64,amd64 | |
- name: Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/${{ github.repository }} | |
tags: | | |
type=semver,pattern={{version}},prefix=v | |
type=semver,pattern={{major}}.{{minor}},prefix=v | |
type=raw,value=latest,enable={{is_default_branch}} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# New step: Cache Docker layers | |
- name: Cache Docker layers | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
# New step: Pull previous images for better layer caching | |
- name: Pull previous images for cache | |
run: | | |
docker pull ghcr.io/${{ github.repository }}:latest || true | |
# Optimized build step | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
# Enhanced caching strategy | |
cache-from: | | |
type=local,src=/tmp/.buildx-cache | |
type=registry,ref=ghcr.io/${{ github.repository }}:latest | |
type=gha,scope=buildx-${{ github.workflow }} | |
cache-to: | | |
type=local,dest=/tmp/.buildx-cache-new,mode=max | |
type=gha,scope=buildx-${{ github.workflow }},mode=max | |
# Optional build arguments for better performance | |
build-args: | | |
BUILDKIT_INLINE_CACHE=1 | |
# Output more build info for debugging | |
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=Arcane Docker Image | |
# Move cache to prevent cache growth issues | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |