Skip to content

Commit

Permalink
Issue-393 Use Distroless images for Go apps (#396)
Browse files Browse the repository at this point in the history
* Use Distroless Debian11 for Hodometer image

* Use Distroless Debian11 for Hodometer stub receiver image

* Use Distroless static for Hodometer images

* Use nonroot Distroless images for Hodometer

* Use nonroot Distroless images for SCv2 core Go components

* Use Debian-based Distroless image for core Go components

These components are buit with Kafka, which uses librdkafka under the hood.
In turn, this is highly likely to be dynamically linked to a C/C++ runtime,
meaning we need an image which contains this C/C++ dependency.

* Disable CGo for scheduler container build

This successfully allows the scheduler container to start in Compose.

* Change scheduler base image back to static Distroless

* Disable CGo for agent images & use static Distroless image as base

* Disable CGo for scheduler, agent, and proxy scheduler binaries in Makefile

* Add Dockerfile comments re use of specific base images for built binaries

* Use entrypoint instead of cmd in Dockerfiles
  • Loading branch information
agrski committed Aug 11, 2022
1 parent 311dc02 commit fe80928
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion hodometer/Dockerfile.hodometer
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN make build-hodometer

################################################################################

FROM golang:1.18-alpine
FROM gcr.io/distroless/static:nonroot
COPY --from=builder /build/bin/hodometer /bin/hodometer

ARG UID=1000
Expand Down
2 changes: 1 addition & 1 deletion hodometer/Dockerfile.receiver
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN make build-receiver

################################################################################

FROM golang:1.18-alpine
FROM gcr.io/distroless/static:nonroot
COPY --from=builder /build/bin/receiver /bin/receiver

ARG UID=1000
Expand Down
8 changes: 4 additions & 4 deletions scheduler/Dockerfile.agent
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ WORKDIR /build
RUN rm -r apis && mv apis-TEMP apis

# Build the binary
RUN go build -o agent ./cmd/agent/main.go
RUN CGO_ENABLED=0 go build -o agent ./cmd/agent/main.go

# Copy into scratch
FROM golang:alpine
# Copy binary
FROM gcr.io/distroless/static:nonroot
COPY --from=builder /build/agent /bin/agent
CMD ["/bin/agent"]
ENTRYPOINT ["/bin/agent"]
6 changes: 3 additions & 3 deletions scheduler/Dockerfile.modelgateway
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN rm -r apis && mv apis-TEMP apis
# Build the binary
RUN go build -o modelgateway ./cmd/modelgateway/main.go

# Copy into scratch
FROM gcr.io/distroless/base-debian10:latest
# Kafka dependencies necessitate leaving CGo enabled and using a base image with C dependencies
FROM gcr.io/distroless/base-debian11:nonroot
COPY --from=builder /build/modelgateway /bin/modelgateway
CMD ["/bin/modelgateway"]
ENTRYPOINT ["/bin/modelgateway"]
6 changes: 3 additions & 3 deletions scheduler/Dockerfile.pipelinegateway
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN rm -r apis && mv apis-TEMP apis
# Build the binary
RUN go build -o pipelinegateway ./cmd/pipelinegateway/main.go

# Copy into scratch
FROM gcr.io/distroless/base-debian10:latest
# Kafka dependencies necessitate leaving CGo enabled and using a base image with C dependencies
FROM gcr.io/distroless/base-debian11:nonroot
COPY --from=builder /build/pipelinegateway /bin/pipelinegateway
CMD ["/bin/pipelinegateway"]
ENTRYPOINT ["/bin/pipelinegateway"]
8 changes: 4 additions & 4 deletions scheduler/Dockerfile.scheduler
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ WORKDIR /build
RUN rm -r apis && mv apis-TEMP apis

# Build the binary
RUN go build -o scheduler ./cmd/scheduler/main.go
RUN CGO_ENABLED=0 go build -o scheduler ./cmd/scheduler/main.go

# Copy into scratch
FROM golang:alpine
# Copy binary
FROM gcr.io/distroless/static:nonroot
COPY --from=builder /build/scheduler /bin/scheduler
CMD ["/bin/scheduler"]
ENTRYPOINT ["/bin/scheduler"]
6 changes: 3 additions & 3 deletions scheduler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ GO_LDFLAGS := -s -w $(patsubst %,-X %, $(GO_BUILD_VARS))

.PHONY: build-scheduler
build-scheduler: test-go
go build -o bin/scheduler ./cmd/scheduler
CGO_ENABLED=0 go build -o bin/scheduler ./cmd/scheduler

.PHONY: build-proxy
build-proxy: test-go
go build -o bin/proxy ./cmd/proxy
CGO_ENABLED=0 go build -o bin/proxy ./cmd/proxy

.PHONY: build-agent
build-agent: test-go
go build -o bin/agent ./cmd/agent
CGO_ENABLED=0 go build -o bin/agent ./cmd/agent

.PHONY: build-modelgateway
build-modelgateway: test-go
Expand Down

0 comments on commit fe80928

Please sign in to comment.