Skip to content

Build and Push Multi-arch Docker Images #17

Build and Push Multi-arch Docker Images

Build and Push Multi-arch Docker Images #17

Workflow file for this run

name: Build and Push Multi-arch Docker Images
permissions:
contents: read
packages: write
on:
workflow_dispatch:
inputs:
services:
description: "Comma-separated list of services to build (e.g., caddy,i2pd-tools). Leave empty to auto-detect."
required: false
type: string
default: ""
jobs:
setup-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up matrix
id: set-matrix
run: |
if [ -n "${{ github.event.inputs.services }}" ]; then
echo "Using provided services: ${{ github.event.inputs.services }}"
SERVICES=$(echo "${{ github.event.inputs.services }}" | tr ',' '\n' | xargs -I {} echo '"{}"' | jq -s '.')
else
echo "Auto-detecting folders with Dockerfiles..."
SERVICES=$(find . -maxdepth 2 -name Dockerfile -type f | cut -d/ -f2 | sort -u | jq -R . | jq -s '.')
fi
MATRIX=$(echo "$SERVICES" | jq -c '{service: .}')
echo "Matrix: $MATRIX"
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
build:
needs: setup-matrix
runs-on: ubuntu-latest
strategy:
matrix: ${{fromJson(needs.setup-matrix.outputs.matrix)}}
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
sparse-checkout: |
${{ matrix.service }}
sparse-checkout-cone-mode: true
- name: Init Submodules
run: |
git submodule update --init --recursive ${{ matrix.service }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker images
uses: docker/build-push-action@v4
with:
context: ${{ matrix.service }}
file: ${{ matrix.service }}/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.service }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max