Skip to content

Commit

Permalink
Use scratch as the base image for operator (#2014)
Browse files Browse the repository at this point in the history
  • Loading branch information
swiatekm authored Aug 18, 2023
1 parent 7d2aa56 commit 5d59034
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
16 changes: 16 additions & 0 deletions .chloggen/chore_dockerfile-base-scratch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Use scratch as the base image for operator

# One or more tracking issues related to the change
issues: [2011]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Build the manager binary
FROM golang:1.21 as builder
FROM golang:1.21-alpine as builder

WORKDIR /workspace

RUN apk --no-cache add ca-certificates

# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
Expand Down Expand Up @@ -33,10 +36,14 @@ ARG AUTO_INSTRUMENTATION_GO_VERSION
# Build
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.otelCol=${OTELCOL_VERSION} -X ${VERSION_PKG}.targetAllocator=${TARGETALLOCATOR_VERSION} -X ${VERSION_PKG}.operatorOpAMPBridge=${OPERATOR_OPAMP_BRIDGE_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${AUTO_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${AUTO_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${AUTO_INSTRUMENTATION_DOTNET_VERSION} -X ${VERSION_PKG}.autoInstrumentationGo=${AUTO_INSTRUMENTATION_GO_VERSION} -X ${VERSION_PKG}.autoInstrumentationApacheHttpd=${AUTO_INSTRUMENTATION_APACHE_HTTPD_VERSION}" -a -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
######## Start a new stage from scratch #######
FROM scratch

WORKDIR /

# Copy the certs from the builder
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

COPY --from=builder /workspace/manager .
USER 65532:65532

Expand Down

0 comments on commit 5d59034

Please sign in to comment.