Skip to content

Commit 23576c6

Browse files
authored
Re-factor build workflow for fluent-operator. (#1737)
* Re-factor build workflow for fluent-operator. Signed-off-by: Josh Baird <[email protected]> * Split manifest generation. Signed-off-by: Josh Baird <[email protected]> * Split build steps. Signed-off-by: Josh Baird <[email protected]> * Debug SBOM. Signed-off-by: Josh Baird <[email protected]> * Debug SBOM. Signed-off-by: Josh Baird <[email protected]> * Debug SBOM. Signed-off-by: Josh Baird <[email protected]> * Point to fork. Signed-off-by: Josh Baird <[email protected]> * Point to fork. Signed-off-by: Josh Baird <[email protected]> * Add branch. Signed-off-by: Josh Baird <[email protected]> * Debug. Signed-off-by: Josh Baird <[email protected]> * Debug. Signed-off-by: Josh Baird <[email protected]> * Debug. Signed-off-by: Josh Baird <[email protected]> * Debug. Signed-off-by: Josh Baird <[email protected]> * Debug. Signed-off-by: Josh Baird <[email protected]> * Debug. Signed-off-by: Josh Baird <[email protected]> * Remove debug. Signed-off-by: Josh Baird <[email protected]> * Remove debug. Signed-off-by: Josh Baird <[email protected]> --------- Signed-off-by: Josh Baird <[email protected]>
1 parent 86e879c commit 23576c6

File tree

1 file changed

+114
-96
lines changed

1 file changed

+114
-96
lines changed
Lines changed: 114 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Building Fluent Operator image
1+
name: Build/Push Fluent Operator image
22

33
on:
44
push:
@@ -35,67 +35,39 @@ on:
3535
- "pkg/fluentd/utils/**"
3636

3737
env:
38-
DOCKER_REPO: "kubesphere"
39-
DOCKER_IMAGE: "fluent-operator"
40-
GITHUB_IMAGE: "${{ github.repository }}/fluent-operator"
38+
GHCR_REPO: 'ghcr.io/${{ github.repository }}/fluent-operator'
39+
DOCKERHUB_REPO: 'kubesphere/fluent-operator'
4140

4241
permissions:
4342
contents: read
4443
packages: write
4544

45+
concurrency:
46+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
47+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
48+
4649
jobs:
47-
build-image-metadata:
48-
runs-on: ubuntu-latest
49-
name: Build Image Metadata
50+
build:
51+
name: Build image (${{ matrix.platform }})
52+
runs-on: ${{ matrix.runs-on }}
53+
permissions:
54+
actions: read
55+
packages: write
5056
outputs:
51-
IMG_NAME: ${{ steps.set-outputs.outputs.IMAGE_NAME }}
52-
DOCKER_IMG_NAME: ${{ steps.set-outputs.outputs.DOCKER_IMG_NAME }}
53-
version: ${{ steps.image-metadata.outputs.version }}
57+
digest_amd64: ${{ steps.output-digests.outputs.amd64 }}
58+
digest_arm64: ${{ steps.output-digests.outputs.arm64 }}
5459
tags: ${{ steps.image-metadata.outputs.tags }}
55-
labels: ${{ steps.image-metadata.outputs.labels }}
56-
release_tags: ${{ steps.image-tags.outputs.tags }}
60+
strategy:
61+
fail-fast: false
62+
matrix:
63+
platform:
64+
- linux/amd64
65+
- linux/arm64
66+
include:
67+
- runs-on: ubuntu-latest
68+
- runs-on: ubuntu-24.04-arm # Builds arm64 on arm64 hosts
69+
platform: linux/arm64
5770

58-
steps:
59-
- name: Checkout code
60-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
61-
62-
- name: docker metadata
63-
id: image-metadata
64-
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
65-
with:
66-
images: "ghcr.io/${{ env.GITHUB_IMAGE }}"
67-
tags: |
68-
raw,latest
69-
type=ref,event=branch
70-
type=ref,event=pr
71-
type=ref,event=tag
72-
type=semver,pattern={{version}}
73-
type=semver,pattern={{major}}.{{minor}}
74-
75-
- name: docker tags for cloning
76-
id: image-tags
77-
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
78-
with:
79-
tags: |
80-
raw,latest
81-
type=ref,event=branch
82-
type=ref,event=pr
83-
type=ref,event=tag
84-
type=semver,pattern={{version}}
85-
type=semver,pattern={{major}}.{{minor}}
86-
87-
- name: Set outputs
88-
id: set-outputs
89-
run: |
90-
echo "IMAGE_NAME=${{ env.GITHUB_IMAGE }}" >> $GITHUB_OUTPUT
91-
echo "DOCKER_IMG_NAME=${{env.DOCKER_REPO}}/${{ env.DOCKER_IMAGE }}" >> $GITHUB_OUTPUT
92-
93-
operator-build:
94-
runs-on: ubuntu-latest
95-
timeout-minutes: 30
96-
name: Build Image for Fluent Operator
97-
needs:
98-
- build-image-metadata
9971
steps:
10072
- name: Checkout code
10173
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
@@ -109,61 +81,107 @@ jobs:
10981
go-version-file: go.mod
11082
cache-dependency-path: go.sum
11183

112-
- name: Set up QEMU
113-
uses: docker/setup-qemu-action@v3
114-
11584
- name: Set up Docker Buildx
11685
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
86+
with:
87+
platforms: linux/amd64,linux/arm64
11788

118-
- name: Login to GitHub Container Registry
89+
- name: Login to GHCR
11990
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
12091
with:
12192
registry: ghcr.io
12293
username: ${{ github.actor }}
12394
password: ${{ secrets.GITHUB_TOKEN }}
12495

125-
- name: Build and push
96+
- name: Login to Docker Hub
97+
if: github.event_name != 'pull_request'
98+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
99+
with:
100+
registry: docker.io
101+
username: ${{ secrets.REGISTRY_USER }}
102+
password: ${{ secrets.REGISTRY_PASSWORD }}
103+
104+
- name: Configure image tags
105+
id: image-metadata
106+
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
107+
with:
108+
images: |
109+
${{ env.GHCR_REPO }}
110+
${{ github.event_name != 'pull_request' && env.DOCKERHUB_REPO || '' }}
111+
flavor: |
112+
latest=false
113+
tags: |
114+
type=raw,value=latest,enable=${{ github.ref_type == 'tag' }}
115+
type=ref,event=tag
116+
type=semver,pattern={{version}}
117+
type=semver,pattern={{major}}.{{minor}}
118+
type=sha,format=long,prefix=,enable=${{ github.event_name == 'pull_request' }},priority=1000
119+
120+
- name: Build and push image (pull request)
121+
if: github.event_name == 'pull_request'
122+
id: build-pr
126123
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
127124
with:
128125
context: .
129-
file: ./cmd/fluent-manager/Dockerfile
130-
push: true
131-
platforms: linux/amd64,linux/arm64
132-
tags: ${{ needs.build-image-metadata.outputs.tags }}
133-
labels: ${{ needs.build-image-metadata.outputs.labels }}
126+
file: cmd/fluent-manager/Dockerfile
127+
platforms: ${{ matrix.platform }}
128+
labels: ${{ steps.image-metadata.outputs.labels }}
129+
provenance: false
130+
cache-from: type=gha
131+
cache-to: type=gha,mode=max
132+
build-args: |
133+
GO_VERSION=${{ steps.setup-go.outputs.go-version }}
134+
outputs: type=image,"name=${{ env.GHCR_REPO }}",push-by-digest=true,name-canonical=true,push=true
135+
136+
- name: Build and push image (tag)
137+
if: github.event_name != 'pull_request'
138+
id: build-tag
139+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
140+
with:
141+
context: .
142+
file: cmd/fluent-manager/Dockerfile
143+
platforms: ${{ matrix.platform }}
144+
labels: ${{ steps.image-metadata.outputs.labels }}
145+
provenance: false
146+
cache-from: type=gha
147+
cache-to: type=gha,mode=max
134148
build-args: |
135149
GO_VERSION=${{ steps.setup-go.outputs.go-version }}
150+
outputs: type=image,"name=${{ env.GHCR_REPO }},${{ env.DOCKERHUB_REPO }}",push-by-digest=true,name-canonical=true,push=true
136151

137-
scan-operator-image:
138-
name: Scan Docker Image
139-
needs:
140-
- operator-build
141-
- build-image-metadata
142-
uses: ./.github/workflows/scan-docker-image-action.yaml
143-
with:
144-
source_image: "${{ needs.build-image-metadata.outputs.IMG_NAME }}:${{ needs.build-image-metadata.outputs.version }}"
145-
source_registry: ghcr.io
146-
platforms: "['linux/arm64', 'linux/amd64']"
147-
secrets:
148-
registry_username: ${{ github.actor }}
149-
registry_password: ${{ secrets.GITHUB_TOKEN }}
150-
151-
release-image-to-docker-hub:
152-
if: ${{ github.event_name != 'pull_request' }}
153-
name: Release Image to Docker Hub
154-
uses: ./.github/workflows/clone-docker-image-action.yaml
155-
needs:
156-
- operator-build
157-
- scan-operator-image
158-
- build-image-metadata
159-
with:
160-
source_image: "${{ needs.build-image-metadata.outputs.IMG_NAME }}:${{ needs.build-image-metadata.outputs.version }}"
161-
source_registry: ghcr.io
162-
target_image: "${{ needs.build-image-metadata.outputs.DOCKER_IMG_NAME }}"
163-
target_registry: docker.io
164-
tags: ${{ needs.build-image-metadata.outputs.release_tags }}
165-
secrets:
166-
source_registry_username: ${{ github.actor }}
167-
source_registry_token: ${{ secrets.GITHUB_TOKEN }}
168-
target_registry_username: ${{ secrets.REGISTRY_USER }}
169-
target_registry_token: ${{ secrets.REGISTRY_PASSWORD }}
152+
- name: Output image digests
153+
id: output-digests
154+
run: |
155+
platform="${{ matrix.platform }}"
156+
# Convert "linux/amd64" to just amd64 for the output variable name
157+
arch=${platform#linux/}
158+
echo "${arch}=${{ steps.build-pr.outputs.digest || steps.build-tag.outputs.digest }}" >> $GITHUB_OUTPUT
159+
160+
manifest:
161+
name: Publish image manifest
162+
runs-on: ubuntu-latest
163+
needs: [build]
164+
steps:
165+
- name: Login to GHCR
166+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
167+
with:
168+
registry: ghcr.io
169+
username: ${{ github.actor }}
170+
password: ${{ secrets.GITHUB_TOKEN }}
171+
172+
- name: Login to Docker Hub
173+
if: github.event_name != 'pull_request'
174+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
175+
with:
176+
registry: docker.io
177+
username: ${{ secrets.REGISTRY_USER }}
178+
password: ${{ secrets.REGISTRY_PASSWORD }}
179+
180+
- name: Create image manifest
181+
uses: int128/docker-manifest-create-action@b60433fd4312d7a64a56d769b76ebe3f45cf36b4 # v2.1.0
182+
with:
183+
push: true
184+
tags: ${{ needs.build.outputs.tags }} # Includes GHCR and Docker Hub
185+
sources: |
186+
${{ env.GHCR_REPO }}@${{ needs.build.outputs.digest_amd64 }}
187+
${{ env.GHCR_REPO }}@${{ needs.build.outputs.digest_arm64 }}

0 commit comments

Comments
 (0)