-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
43 lines (30 loc) · 1010 Bytes
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Image used to build binaries.
ARG BUILDER_IMAGE=golang:1.20-alpine
# Image used as base image.
ARG BASE_IMAGE=gcr.io/distroless/static
# Use builder image to build binaries.
FROM ${BUILDER_IMAGE} AS builder
# Configure golang module proxy URI.
ARG GOPROXY=proxy.golang.org
# Set separate workdir for builder image.
WORKDIR /workspace
# Install in build dependencies.
RUN apk add --no-cache gcc git make musl-dev
# Bring in golang dependencies to cache these layers.
COPY go.mod go.mod
COPY go.sum go.sum
RUN --mount=type=ssh env GOPROXY=${GOPROXY} go mod download -x || true
# Copy everything into builder image.
COPY . .
# Build binaries.
RUN --mount=type=ssh make GOPROXY=${GOPROXY} all
# Use base image.
FROM ${BASE_IMAGE} AS base
# Use empty image as backing base image.
FROM scratch
# Copy everything into backing base image from base image.
COPY --from=base . .
# Set workdir for base image.
WORKDIR /
# Copy binaries into base image.
COPY --from=builder /workspace/BUILD/ /usr/local/bin/