Skip to content

Commit 93b98ca

Browse files
chore: refactor to multi-stage Dockerfile
1 parent 63ad4e7 commit 93b98ca

File tree

4 files changed

+20
-54
lines changed

4 files changed

+20
-54
lines changed
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,22 @@ COPY cmd/ cmd/
2121
COPY internal/ internal/
2222

2323
# Build
24-
# the GOARCH has not a default value to allow the binary be built according to the host where the command
25-
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
26-
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
27-
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
28-
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/manager/main.go
24+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -o /workspace ./...
2925

3026
################################################################################
3127

32-
# Use distroless as minimal base image to package the manager binary
33-
# Refer to https://github.com/GoogleContainerTools/distroless for more details
34-
FROM gcr.io/distroless/static:nonroot
35-
28+
# Ref: https://github.com/GoogleContainerTools/distroless
29+
FROM gcr.io/distroless/static:nonroot AS manager
3630
WORKDIR /
3731
COPY --from=builder /workspace/manager .
3832
USER 65532:65532
39-
4033
ENTRYPOINT ["/manager"]
34+
35+
################################################################################
36+
37+
# Ref: https://github.com/GoogleContainerTools/distroless
38+
FROM gcr.io/distroless/static:nonroot AS webhook
39+
WORKDIR /
40+
COPY --from=builder /workspace/webhook .
41+
USER 65532:65532
42+
ENTRYPOINT ["/webhook"]

build/Dockerfile.webhook

Lines changed: 0 additions & 40 deletions
This file was deleted.

docker-bake.hcl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ group "default" {
4747

4848
target "operator" {
4949
inherits = ["_common"]
50-
dockerfile = "build/Dockerfile.operator"
50+
dockerfile = "Dockerfile"
51+
target = "manager"
5152
labels = {
5253
# Ref: https://github.com/opencontainers/image-spec/blob/v1.0/annotations.md
5354
"org.opencontainers.image.title" = "Slurm Operator"
@@ -66,7 +67,8 @@ target "operator" {
6667

6768
target "webhook" {
6869
inherits = ["_common"]
69-
dockerfile = "build/Dockerfile.webhook"
70+
dockerfile = "Dockerfile"
71+
target = "webhook"
7072
labels = {
7173
# Ref: https://github.com/opencontainers/image-spec/blob/v1.0/annotations.md
7274
"org.opencontainers.image.title" = "Slurm Operator Webhook"

helm/slurm-operator/skaffold.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ profiles:
1212
- image: slinky.slurm.net/slurm-operator
1313
context: ../../
1414
docker:
15-
dockerfile: ./build/Dockerfile.operator
15+
dockerfile: Dockerfile
16+
target: manager
1617
- image: slinky.slurm.net/slurm-operator-webhook
1718
context: ../../
1819
docker:
19-
dockerfile: ./build/Dockerfile.webhook
20+
dockerfile: Dockerfile
21+
target: webhook
2022
deploy:
2123
helm:
2224
releases:

0 commit comments

Comments
 (0)