Skip to content

Commit 4575757

Browse files
committed
feat: enhance Docker build process with caching and multi-architecture support
- Added local BuildKit cache configuration to improve build performance. - Introduced new Docker tasks for building and pushing images with registry caching. - Updated GitHub Actions workflow to support multi-architecture builds for amd64 and arm64 platforms. - Cleaned up Dockerfile by removing unnecessary package installation.
1 parent 5c0bb8e commit 4575757

4 files changed

Lines changed: 73 additions & 25 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,17 @@ jobs:
3939
build-image:
4040
needs: release
4141
if: needs.release.outputs.new_release_published == 'true'
42-
runs-on: ubuntu-latest
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
include:
46+
- platform: linux/amd64
47+
runner: ubuntu-latest
48+
suffix: amd64
49+
- platform: linux/arm64
50+
runner: ubuntu-24.04-arm
51+
suffix: arm64
52+
runs-on: ${{ matrix.runner }}
4353
steps:
4454
- name: Checkout
4555
uses: actions/checkout@v4
@@ -57,37 +67,46 @@ jobs:
5767
username: ${{ github.actor }}
5868
password: ${{ secrets.GITHUB_TOKEN }}
5969

60-
- name: Set build platforms
61-
run: echo "platforms=linux/amd64,linux/arm64" >> $GITHUB_OUTPUT
62-
id: platforms
63-
64-
- name: Extract metadata and set tags
65-
id: meta
66-
uses: docker/metadata-action@v5
67-
with:
68-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
69-
tags: |
70-
type=raw,value=v${{ needs.release.outputs.new_release_version }}
71-
type=raw,value=${{ needs.release.outputs.new_release_version }}
72-
type=raw,value=latest
73-
7470
- name: Build and push Docker image
7571
uses: docker/build-push-action@v5
7672
with:
7773
context: .
7874
file: ./Dockerfile
7975
push: true
80-
tags: ${{ steps.meta.outputs.tags }}
81-
labels: ${{ steps.meta.outputs.labels }}
82-
platforms: ${{ steps.platforms.outputs.platforms }}
76+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${{ needs.release.outputs.new_release_version }}-${{ matrix.suffix }}
77+
platforms: ${{ matrix.platform }}
8378
build-args: |
8479
VERSION=v${{ needs.release.outputs.new_release_version }}
85-
# GHA cache + registry cache (сохраняется между runs, переживает eviction)
8680
cache-from: |
87-
type=gha
88-
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
81+
type=gha,scope=${{ matrix.suffix }}
82+
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.suffix }}
8983
cache-to: |
90-
type=gha,mode=max
91-
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
92-
# Отключаем attestation для ускорения (опционально)
84+
type=gha,scope=${{ matrix.suffix }},mode=max
85+
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.suffix }},mode=max
9386
provenance: false
87+
88+
merge-manifest:
89+
needs: [release, build-image]
90+
if: needs.release.outputs.new_release_published == 'true'
91+
runs-on: ubuntu-latest
92+
steps:
93+
- name: Log in to Container Registry
94+
uses: docker/login-action@v3
95+
with:
96+
registry: ${{ env.REGISTRY }}
97+
username: ${{ github.actor }}
98+
password: ${{ secrets.GITHUB_TOKEN }}
99+
100+
- name: Set up Docker Buildx
101+
uses: docker/setup-buildx-action@v3
102+
103+
- name: Create and push multi-arch manifest
104+
run: |
105+
VERSION="${{ needs.release.outputs.new_release_version }}"
106+
IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
107+
docker buildx imagetools create \
108+
-t "${IMAGE}:v${VERSION}" \
109+
-t "${IMAGE}:${VERSION}" \
110+
-t "${IMAGE}:latest" \
111+
"${IMAGE}:v${VERSION}-amd64" \
112+
"${IMAGE}:v${VERSION}-arm64"

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ temp/
4747
# Go workspace file
4848
go.work
4949
go.work.sum
50+
51+
# Docker BuildKit local cache
52+
.docker-cache/

‎Dockerfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM golang:1.25-alpine AS builder
44

55
WORKDIR /workspace
66

7-
RUN apk add --no-cache git make
7+
RUN apk add --no-cache git
88

99
COPY go.mod go.sum ./
1010
RUN --mount=type=cache,target=/go/pkg/mod \

‎Taskfile.yml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,32 @@ tasks:
9595
cmds:
9696
- go build -o bin/manager main.go
9797

98+
docker:
99+
desc: Build operator image with local BuildKit cache
100+
cmds:
101+
- |
102+
docker buildx create --use --name dataflow 2>/dev/null || docker buildx use dataflow
103+
docker buildx build \
104+
--cache-from type=local,src=.docker-cache \
105+
--cache-to type=local,dest=.docker-cache,mode=max \
106+
-t {{.IMG}} \
107+
--load \
108+
.
109+
110+
docker:push:
111+
desc: Build and push with registry cache (CI-like)
112+
cmds:
113+
- |
114+
docker buildx create --use --name dataflow 2>/dev/null || docker buildx use dataflow
115+
REGISTRY="${REGISTRY:?set REGISTRY}"
116+
IMAGE="${IMAGE:?set IMAGE}"
117+
docker buildx build \
118+
--cache-from type=registry,ref="${REGISTRY}/${IMAGE}:buildcache-amd64" \
119+
--cache-to type=registry,ref="${REGISTRY}/${IMAGE}:buildcache-amd64",mode=max \
120+
-t {{.IMG}} \
121+
--push \
122+
.
123+
98124
run:
99125
desc: Run a controller from your host
100126
deps: [manifests, generate, fmt, vet]

0 commit comments

Comments
 (0)