Skip to content

Instantly share code, notes, and snippets.

@milosgajdos
Created December 16, 2022 20:02
Show Gist options
  • Save milosgajdos/ac242bccd588a9d88323de301040b7a6 to your computer and use it in GitHub Desktop.
Save milosgajdos/ac242bccd588a9d88323de301040b7a6 to your computer and use it in GitHub Desktop.
Dockerfile
# build stage
FROM --platform=${BUILDPLATFORM} golang:1.19-alpine3.17 AS build
RUN apk add --no-cache git build-base ca-certificates
ENV CGO_ENABLED=0
ENV GO111MODULE=auto
ARG GIT_VERSION
ARG TARGETOS
ARG TARGETARCH
ARG PKG=github.com/milosgajdos/bkexp
WORKDIR /app
COPY go.mod ./
COPY go.sum ./
RUN go mod download
COPY . ./
RUN --mount=type=cache,target=/root/.cache/go-build \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -ldflags "-X ${PKG}/version.version=${GIT_VERSION}" -o /app/bkexp
# runtime stage
FROM scratch as binary
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build /app/bkexp /bkexp
ENTRYPOINT ["/bkexp"]
CMD ["--help"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment