Skip to content

Commit a0eb221

Browse files
authored
Optimize Docker builds: Add .dockerignore, improve caching, and enhance Dockerfile structure (#164)
## Summary - Add `.dockerignore` file to exclude unnecessary files from Docker context - Update GitHub Actions workflows with scoped cache configuration for better cache hits - Enhance Dockerfile with better layer organization and inline optimization comments - Update to more recent/secure base images where applicable
1 parent ba42a56 commit a0eb221

File tree

6 files changed

+57
-12
lines changed

6 files changed

+57
-12
lines changed

.dockerignore

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
1-
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2-
# Ignore build and test binaries.
1+
# Version control
2+
.git
3+
.gitignore
4+
5+
# Documentation
6+
*.md
7+
docs/
8+
9+
# Tests
10+
*_test.go
11+
internal/testhelpers
12+
internal/tests
13+
14+
# Development
15+
.env
16+
.env.*
17+
*.log
18+
skaffold.yaml
19+
skaffold.example.env
20+
21+
# Build artifacts
322
bin/
423
helm/
524
internal/demo
25+
26+
# IDE
27+
.vscode
28+
.idea
29+
*.swp
30+
31+
# CI/CD
32+
.github
33+
.goreleaser.yml
34+
.goreleaser.main.yml
35+
36+
# Go
37+
go.work
38+
go.work.sum

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
check-latest: true
3636

3737
- name: Set up Docker Buildx
38-
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
38+
uses: docker/setup-buildx-action@v3
3939

4040
- name: Login to Docker Hub
4141
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
@@ -51,6 +51,7 @@ jobs:
5151
args: release
5252
env:
5353
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
BUILDKIT_INLINE_CACHE: 1
5455

5556
helm:
5657
needs: release

.github/workflows/test-integration.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,25 @@ jobs:
3434
- name: Build worker-controller image
3535
run: |
3636
skaffold build --profile worker-controller --push=false
37+
env:
38+
DOCKER_BUILDKIT: 1
39+
BUILDKIT_PROGRESS: plain
3740

3841
- name: Build helloworld worker image
3942
run: |
4043
skaffold build --profile helloworld-worker --push=false
44+
env:
45+
DOCKER_BUILDKIT: 1
46+
BUILDKIT_PROGRESS: plain
4147

4248
# Verify that the demo worker patch applies successfully and builds.
4349
- name: Build helloworld worker image patch
4450
run: |
4551
git apply internal/demo/helloworld/changes/no-version-gate.patch
4652
skaffold build --profile helloworld-worker --push=false
53+
env:
54+
DOCKER_BUILDKIT: 1
55+
BUILDKIT_PROGRESS: plain
4756

4857
test-integration:
4958
name: Run Integration Tests

.goreleaser.main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ dockers:
4242
use: buildx
4343
build_flag_templates:
4444
- --platform=linux/amd64
45+
- --cache-from=type=gha,scope=amd64
46+
- --cache-to=type=gha,mode=max,scope=amd64
4547
- --label=org.opencontainers.image.title={{ .ProjectName }}
4648
- --label=org.opencontainers.image.description=Temporal Worker Controller for Kubernetes
4749
- --label=org.opencontainers.image.url=https://github.com/temporalio/temporal-worker-controller
@@ -63,6 +65,8 @@ dockers:
6365
use: buildx
6466
build_flag_templates:
6567
- --platform=linux/arm64
68+
- --cache-from=type=gha,scope=arm64
69+
- --cache-to=type=gha,mode=max,scope=arm64
6670
- --label=org.opencontainers.image.title={{ .ProjectName }}
6771
- --label=org.opencontainers.image.description=Temporal Worker Controller for Kubernetes
6872
- --label=org.opencontainers.image.url=https://github.com/temporalio/temporal-worker-controller

Dockerfile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
# Build the manager binary
21
FROM golang:1.25 AS builder
32
ARG TARGETOS
43
ARG TARGETARCH
54

65
WORKDIR /workspace
7-
# Copy the Go Modules manifests
8-
COPY go.mod go.mod
9-
COPY go.sum go.sum
10-
# cache deps before building and copying source so that we don't need to re-download as much
11-
# and so that source changes don't invalidate our downloaded layer
6+
7+
COPY go.mod go.sum ./
128
RUN go mod download
139

14-
# Copy the go source
1510
COPY cmd/main.go cmd/main.go
1611
COPY api/ api/
1712
COPY internal/k8s internal/k8s
@@ -20,7 +15,6 @@ COPY internal/controller internal/controller
2015
COPY internal/planner internal/planner
2116
COPY internal/defaults internal/defaults
2217

23-
# Build
2418
# the GOARCH has not a default value to allow the binary be built according to the host where the command
2519
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
2620
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,

Dockerfile.goreleaser

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
FROM gcr.io/distroless/static-debian12:nonroot
22

3-
COPY temporal-worker-controller /usr/local/bin/temporal-worker-controller
3+
WORKDIR /app
4+
5+
COPY --chown=nonroot:nonroot temporal-worker-controller /usr/local/bin/temporal-worker-controller
6+
7+
USER nonroot
48

59
ENTRYPOINT ["temporal-worker-controller"]

0 commit comments

Comments
 (0)