Skip to content

Commit c8a5b4b

Browse files
committed
Enhance Docker configuration: update .dockerignore to exclude additional files and directories, optimize Dockerfile build command with new flags for reduced binary size, and improve GitHub Actions workflow by adding Go module caching and conditional platform support for Docker builds.
1 parent e53bb84 commit c8a5b4b

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

.dockerignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
22
# Ignore build and test binaries.
33
bin/
4+
5+
# Git and GitHub files
6+
.git
7+
.github
8+
.gitignore
9+
10+
# Documentation
11+
*.md
12+
README*
13+
CHANGELOG*
14+
LICENSE*
15+
16+
# Test files
17+
*_test.go
18+
testdata/
19+
tests/
20+
coverage.*
21+
cover.*
22+
23+
# Development files
24+
Makefile
25+
.dockerignore
26+
27+
# Config samples (not needed in runtime)
28+
config/samples/
29+
30+
# Temporary files
31+
*.tmp
32+
*.log
33+
.DS_Store
34+
35+
# IDE files
36+
.vscode/
37+
.idea/
38+
*.swp
39+
*.swo
40+
41+
# Chart development
42+
charts/*/tests/

.github/workflows/docker-publish.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,16 @@ jobs:
3333
with:
3434
go-version: ${{ env.GO_VERSION }}
3535

36+
- name: Cache Go modules
37+
uses: actions/cache@v4
38+
with:
39+
path: ~/go/pkg/mod
40+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
41+
restore-keys: |
42+
${{ runner.os }}-go-
43+
3644
- name: Run tests
45+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
3746
run: make test
3847

3948
- name: Set up QEMU
@@ -69,7 +78,7 @@ jobs:
6978
uses: docker/build-push-action@v6
7079
with:
7180
context: .
72-
platforms: linux/amd64,linux/arm64
81+
platforms: ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags/') && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
7382
push: ${{ github.event_name != 'pull_request' }}
7483
tags: ${{ steps.meta.outputs.tags }}
7584
labels: ${{ steps.meta.outputs.labels }}
@@ -88,7 +97,7 @@ jobs:
8897
env:
8998
DIGEST: ${{ steps.build.outputs.digest }}
9099
run: |
91-
echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign --yes {}@${DIGEST}
100+
echo "${{ steps.meta.outputs.tags }}" | xargs -I {} -P 4 cosign sign --yes {}@${DIGEST}
92101
93102
# Separate job for PR validation
94103
validate:

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ COPY pkg/ pkg/
2222
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
2323
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
2424
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
25-
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
25+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} \
26+
go build -a -ldflags="-w -s" -trimpath -o manager cmd/main.go
2627

2728
# Use distroless as minimal base image to package the manager binary
2829
# Refer to https://github.com/GoogleContainerTools/distroless for more details

0 commit comments

Comments
 (0)