Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit e6555f7

Browse files
floriankochFlorian Koch
andauthored
improvement: - use a distroless base image (#125)
- Add a debug image Signed-off-by: Florian Koch <flo@ctrl.wtf> Co-authored-by: Florian Koch <flo@ctrl.wtf>
1 parent 915c16d commit e6555f7

File tree

3 files changed

+78
-9
lines changed

3 files changed

+78
-9
lines changed

Dockerfile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,12 @@ COPY third_party/ third_party/
5959
# build metacontroller binary
6060
RUN make bins
6161

62-
# Use debian as minimal base image to package the final binary
63-
FROM debian:stretch-slim
62+
# Use a distroless image
63+
# Sort the instructions to be more effective for caching
6464

65-
WORKDIR /
66-
67-
RUN apt-get update && \
68-
apt-get install --no-install-recommends -y ca-certificates && \
69-
rm -rf /var/lib/apt/lists/*
70-
71-
COPY --from=builder /go/src/openebs.io/metac/metac /usr/bin/
65+
FROM gcr.io/distroless/base-debian10:nonroot
7266

67+
WORKDIR /
68+
USER nonroot:nonroot
7369
CMD ["/usr/bin/metac"]
70+
COPY --from=builder --chown=nonroot /go/src/openebs.io/metac/metac /usr/bin/

Dockerfile.debug

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Tester image
2+
FROM golang:1.13.5 as tester
3+
4+
WORKDIR /go/src/openebs.io/metac/
5+
6+
# copy go modules manifests
7+
COPY go.mod go.mod
8+
COPY go.sum go.sum
9+
10+
# copy build manifests
11+
COPY Makefile Makefile
12+
13+
# ensure vendoring is up-to-date by running make vendor in your local
14+
# setup
15+
#
16+
# we cache the vendored dependencies before building and copying source
17+
# so that we don't need to re-download when source changes don't invalidate
18+
# our downloaded layer
19+
RUN make vendor
20+
21+
# copy build manifests
22+
COPY . .
23+
24+
RUN make integration-test
25+
26+
# Build metac binary
27+
FROM golang:1.13.5 as builder
28+
29+
WORKDIR /go/src/openebs.io/metac/
30+
31+
# copy go modules manifests
32+
COPY go.mod go.mod
33+
COPY go.sum go.sum
34+
35+
# copy build manifests
36+
COPY Makefile Makefile
37+
38+
# ensure vendoring is up-to-date by running make vendor in your local
39+
# setup
40+
#
41+
# we cache the vendored dependencies before building and copying source
42+
# so that we don't need to re-download when source changes don't invalidate
43+
# our downloaded layer
44+
RUN make vendor
45+
46+
# copy source files
47+
COPY *.go ./
48+
COPY apis/ apis/
49+
COPY client/ client/
50+
COPY config/ config/
51+
COPY hack/ hack/
52+
COPY controller/ controller/
53+
COPY dynamic/ dynamic/
54+
COPY hooks/ hooks/
55+
COPY server/ server/
56+
COPY start/ start/
57+
COPY third_party/ third_party/
58+
59+
# build metacontroller binary
60+
RUN make bins
61+
62+
# Use a distroless image
63+
# Sort the instructions to be more effective for caching
64+
65+
FROM gcr.io/distroless/base-debian10:debug-nonroot
66+
67+
WORKDIR /
68+
USER nonroot:nonroot
69+
CMD ["/usr/bin/metac"]
70+
COPY --from=builder --chown=nonroot /go/src/openebs.io/metac/metac /usr/bin/

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ vendor: go.mod go.sum
7171
.PHONY: image
7272
image:
7373
docker build -t $(REGISTRY)/$(IMG_NAME):$(PACKAGE_VERSION) .
74+
docker build -t $(REGISTRY)/$(IMG_NAME):$(PACKAGE_VERSION)_debug -f Dockerfile.debug .
7475

7576
.PHONY: push
7677
push: image
7778
docker push $(REGISTRY)/$(IMG_NAME):$(PACKAGE_VERSION)
79+
docker push $(REGISTRY)/$(IMG_NAME):$(PACKAGE_VERSION)_debug
7880

7981
.PHONY: unit-test
8082
unit-test: generated_files

0 commit comments

Comments
 (0)