Docker Multi #403
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: Docker Multi | |
| on: | |
| schedule: | |
| - cron: '29 2 * * *' | |
| push: | |
| branches: [ "main" ] | |
| tags: [ 'v*.*.*' ] | |
| pull_request: | |
| branches: [ "main" ] | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install cosign | |
| if: github.event_name != 'pull_request' | |
| uses: sigstore/[email protected] | |
| with: | |
| cosign-release: 'v2.2.4' | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log into GHCR | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build, push, and sign each Dockerfile | |
| env: | |
| REGISTRY: ${{ env.REGISTRY }} | |
| IMAGE_NAME: ${{ env.IMAGE_NAME }} | |
| PUSH: ${{ github.event_name != 'pull_request' }} | |
| run: | | |
| for dockerfile in $(find . -mindepth 2 -maxdepth 2 -name Dockerfile); do | |
| dir=$(dirname "$dockerfile") | |
| name=$(basename "$dir") | |
| image="${REGISTRY}/shaman007/${name}:latest" | |
| echo "Building ${image} from ${dir}" | |
| docker buildx build "$dir" \ | |
| --platform linux/amd64,linux/arm64 \ | |
| --tag "$image" \ | |
| --provenance=false \ | |
| --cache-from type=gha \ | |
| --cache-to type=gha,mode=max \ | |
| --build-arg BUILDKIT_INLINE_CACHE=1 \ | |
| $([[ "${{ github.event_name }}" != 'pull_request' ]] && echo --push) | |
| # Get the manifest digest from buildx (more reliable than skopeo+tag race) | |
| digest=$(docker buildx imagetools inspect "$image" --format '{{json .Manifest.Digest}}' | tr -d '"') | |
| ref="${image%%:*}@$digest" | |
| echo "Signing $ref" | |
| cosign sign --yes "$ref" | |
| done |