Skip to content

Commit e974aea

Browse files
committed
ci: switch image publishing to docker/github-builder
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 6e85d30 commit e974aea

File tree

1 file changed

+43
-144
lines changed

1 file changed

+43
-144
lines changed

.github/workflows/build-and-publish.yml

Lines changed: 43 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -7,161 +7,60 @@ on:
77
- development
88
release:
99
types: [published]
10+
pull_request:
1011

1112
permissions:
1213
contents: read
13-
packages: write
1414

1515
env:
16-
dockerhub: ${{ secrets.DOCKERHUB_NAMESPACE }}/pihole
17-
ghcr: ghcr.io/${{ github.repository_owner }}/pihole
1816
components_branch: ${{ github.event_name == 'release' && 'master' || 'development' }}
1917

2018
jobs:
21-
build:
22-
runs-on: ${{ matrix.runner }}
23-
strategy:
24-
fail-fast: false
25-
matrix:
26-
include:
27-
- platform: linux/amd64
28-
runner: ubuntu-latest
29-
- platform: linux/386
30-
runner: ubuntu-latest
31-
- platform: linux/arm/v6
32-
runner: ubuntu-24.04-arm
33-
- platform: linux/arm/v7
34-
runner: ubuntu-24.04-arm
35-
- platform: linux/arm64
36-
runner: ubuntu-24.04-arm
37-
- platform: linux/riscv64
38-
runner: ubuntu-24.04-arm
39-
19+
build-prepare:
20+
runs-on: ubuntu-24.04
21+
outputs:
22+
components_branch: ${{ env.components_branch }}
4023
steps:
41-
- name: Prepare name for digest up/download
42-
run: |
43-
platform=${{ matrix.platform }}
44-
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
45-
46-
- &checkout-repo
47-
name: Checkout Repo
48-
if: github.event_name != 'schedule'
49-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
50-
51-
- &checkout-dev
52-
name: Checkout dev branch if scheduled
53-
if: github.event_name == 'schedule'
54-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
55-
with:
56-
ref: development
57-
58-
- &docker-meta
59-
name: Docker meta
60-
id: meta
61-
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf #v6.0.0
62-
with:
63-
github-token: ${{ secrets.GITHUB_TOKEN }}
64-
images: |
65-
${{ env.dockerhub }}
66-
${{ env.ghcr }}
67-
flavor: |
68-
latest=${{ startsWith(github.ref, 'refs/tags/') }}
69-
tags: |
70-
type=schedule,pattern=nightly
71-
type=raw,value=nightly,enable=${{ github.event_name == 'push' }}
72-
type=ref,event=tag
24+
# FIXME: can't use env object in reusable workflow inputs: https://github.com/orgs/community/discussions/26671
25+
- run: echo "Exposing env vars for reusable workflow"
7326

74-
- &login-dockerhub
75-
name: Login to Docker Hub
76-
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 #v4.0.0
77-
with:
78-
registry: docker.io
27+
build:
28+
uses: docker/github-builder/.github/workflows/build.yml@v1
29+
needs:
30+
- build-prepare
31+
permissions:
32+
contents: read # same as global permissions
33+
id-token: write # for signing attestation(s) with GitHub OIDC Token
34+
packages: write # required to push to GHCR
35+
with:
36+
setup-qemu: true
37+
cache: true
38+
cache-scope: build
39+
context: src
40+
output: image
41+
build-args: |
42+
PIHOLE_DOCKER_TAG={{meta.version}}
43+
FTL_BRANCH=${{ needs.build-prepare.outputs.components_branch }}
44+
CORE_BRANCH=${{ needs.build-prepare.outputs.components_branch }}
45+
WEB_BRANCH=${{ needs.build-prepare.outputs.components_branch }}
46+
PADD_BRANCH=${{ needs.build-prepare.outputs.components_branch }}
47+
platforms: linux/amd64,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64,linux/riscv64
48+
push: ${{ github.event_name != 'pull_request' }}
49+
set-meta-labels: true
50+
meta-images: |
51+
pihole/pihole
52+
ghcr.io/${{ github.repository_owner }}/pihole
53+
meta-tags: |
54+
type=schedule,pattern=nightly
55+
type=raw,value=nightly,enable=${{ github.event_name == 'push' }}
56+
type=ref,event=tag
57+
meta-flavor: |
58+
latest=${{ startsWith(github.ref, 'refs/tags/') }}
59+
secrets:
60+
registry-auths: |
61+
- registry: docker.io
7962
username: ${{ secrets.DOCKERHUB_USER }}
8063
password: ${{ secrets.DOCKERHUB_PASS }}
81-
82-
- &login-ghcr
83-
name: Login to GitHub Container Registry
84-
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 #v4.0.0
85-
with:
86-
registry: ghcr.io
64+
- registry: ghcr.io
8765
username: ${{ github.repository_owner }}
8866
password: ${{ secrets.GITHUB_TOKEN }}
89-
90-
- name: Set up QEMU
91-
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a #v4.0.0
92-
with:
93-
platforms: ${{ matrix.platform}}
94-
95-
- &setup-buildx
96-
name: Set up Docker Buildx
97-
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd #v4.0.0
98-
with:
99-
# Buildx version 0.31.1 broke our publish workflow, this need to be revised when 0.32.0 is released
100-
# https://github.com/docker/buildx/releases/tag/v0.31.1
101-
version: v0.31.0
102-
103-
- name: Build container and push by digest
104-
id: build
105-
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 #v7.0.0
106-
with:
107-
context: ./src/
108-
platforms: ${{ matrix.platform }}
109-
build-args: |
110-
PIHOLE_DOCKER_TAG=${{ steps.meta.outputs.version }}
111-
FTL_BRANCH=${{ env.components_branch }}
112-
CORE_BRANCH=${{ env.components_branch }}
113-
WEB_BRANCH=${{ env.components_branch }}
114-
PADD_BRANCH=${{ env.components_branch }}
115-
labels: ${{ steps.meta.outputs.labels }}
116-
outputs: |
117-
type=image,name=${{ env.dockerhub }},push-by-digest=true,name-canonical=true,push=true
118-
119-
- name: Export digests
120-
run: |
121-
mkdir -p /tmp/digests
122-
digest_docker="${{ steps.build.outputs.digest }}"
123-
touch "/tmp/digests/${digest_docker#sha256:}"
124-
125-
- name: Upload digest
126-
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f #v7.0.0
127-
with:
128-
name: digests-${{ env.PLATFORM_PAIR }}
129-
path: /tmp/digests/*
130-
if-no-files-found: error
131-
retention-days: 1
132-
133-
# Merge all the digests into a single file
134-
# If we would push immediately above, the individual runners would overwrite each other's images
135-
# https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
136-
merge-and-deploy:
137-
runs-on: ubuntu-latest
138-
needs:
139-
- build
140-
steps:
141-
- *checkout-repo
142-
- *checkout-dev
143-
144-
- name: Download digests
145-
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c #v8.0.1
146-
with:
147-
path: /tmp/digests
148-
pattern: digests-*
149-
merge-multiple: true
150-
151-
- *setup-buildx
152-
- *docker-meta
153-
- *login-dockerhub
154-
- *login-ghcr
155-
156-
- name: Create manifest list and push (DockerHub and GitHub Container Registry)
157-
working-directory: /tmp/digests
158-
run: |
159-
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
160-
$(printf '${{ env.dockerhub }}@sha256:%s ' *)
161-
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
162-
$(printf '${{ env.ghcr }}@sha256:%s ' *)
163-
164-
- name: Inspect images
165-
run: |
166-
docker buildx imagetools inspect ${{ env.dockerhub }}:${{ steps.meta.outputs.version }}
167-
docker buildx imagetools inspect ${{ env.ghcr }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)