-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
47 lines (31 loc) · 1.23 KB
/
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
44
45
46
47
# syntax = docker/dockerfile:experimental
FROM --platform=$BUILDPLATFORM golang:1.16-alpine as builder
LABEL maintainer="Antonio Mika <me@antoniomika.me>"
ENV CGO_ENABLED 0
ARG VERSION=dev
ARG COMMIT=none
ARG DATE=unknown
ARG REPOSITORY=unknown
WORKDIR /app
RUN --mount=type=bind,target=/cache,from=antoniomika/go-starter-build-cache \
mkdir -p /go/pkg/ && cp -R /cache/mod/ /go/pkg/ || true && \
mkdir -p /root/.cache/ && cp -R /cache/go-build/ /root/.cache/ || true
COPY . .
RUN go generate ./...
RUN go test ./...
FROM scratch as build-cache
LABEL maintainer="Antonio Mika <me@antoniomika.me>"
COPY --from=builder /go/pkg/mod /mod
COPY --from=builder /root/.cache/go-build /go-build
FROM builder as build-image
ARG TARGETOS
ARG TARGETARCH
ENV GOOS=${TARGETOS} GOARCH=${TARGETARCH}
RUN go build -o /go/bin/app -ldflags="-s -w -X github.com/${REPOSITORY}/cmd.Version=${VERSION} -X github.com/${REPOSITORY}/cmd.Commit=${COMMIT} -X github.com/${REPOSITORY}/cmd.Date=${DATE}"
FROM scratch as release
LABEL maintainer="Antonio Mika <me@antoniomika.me>"
WORKDIR /app
COPY --from=build-image /app/deploy/ /app/deploy/
COPY --from=build-image /app/README* /app/LICENSE* /app/
COPY --from=build-image /go/bin/ /app/
ENTRYPOINT ["/app/app"]