Skip to content

Commit

Permalink
feat: use distroless base images for docker (#200)
Browse files Browse the repository at this point in the history
this also drops support for 389 architectures
  • Loading branch information
tbckr authored Dec 29, 2023
1 parent b396da1 commit 456f7f7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
1 change: 0 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ builds:
- windows
- darwin
goarch:
- "386"
- "amd64"
- "arm"
- "arm64"
Expand Down
27 changes: 7 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,16 @@
#
# SPDX-License-Identifier: MIT

ARG IMAGE_1=cgr.dev/chainguard/go:1.21@sha256:f807658ebd070455c2ec930407fb4427c0761f5401c5c84e9b0dac3ee99c1da8
ARG IMAGE_2=cgr.dev/chainguard/static:latest@sha256:a2f525dac2f9ec900283ead64eb88a6037b2989630615ee8de8a2dc7bfcf152b

FROM --platform=$BUILDPLATFORM ${IMAGE_1} as build

WORKDIR /work
ARG BUILDPLATFORM=linux/amd64
ARG BASE_IMAGE_VERSION=golang:1.21
FROM --platform=$BUILDPLATFORM ${BASE_IMAGE_VERSION} as build

WORKDIR /go/src/github.com/tbckr/sgpt
COPY go.mod go.sum ./
RUN go mod download

COPY . .
ARG TARGETOS TARGETARCH TARGETVARIANT
RUN \
if [ "${TARGETARCH}" = "arm" ] && [ -n "${TARGETVARIANT}" ]; then \
export GOARM="${TARGETVARIANT#v}"; \
fi; \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 go build -o sgpt -v ./cmd/sgpt/main.go


FROM ${IMAGE_2}

ENV HOME /home/nonroot
VOLUME /home/nonroot
RUN CGO_ENABLED=0 go build -o sgpt -v ./cmd/sgpt/main.go

COPY --from=build /work/sgpt /sgpt
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /go/src/github.com/tbckr/sgpt/sgpt /sgpt
ENTRYPOINT ["/sgpt"]
8 changes: 3 additions & 5 deletions Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
FROM --platform=$BUILDPLATFORM cgr.dev/chainguard/static:latest@sha256:a2f525dac2f9ec900283ead64eb88a6037b2989630615ee8de8a2dc7bfcf152b

ENV HOME /home/nonroot
VOLUME /home/nonroot

ARG BUILDPLATFORM=linux/amd64
ARG BASE_IMAGE_VERSION=gcr.io/distroless/static-debian12:nonroot
FROM --platform=$BUILDPLATFORM ${BASE_IMAGE_VERSION}
COPY sgpt /sgpt
ENTRYPOINT ["/sgpt"]

0 comments on commit 456f7f7

Please sign in to comment.