-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDockerfile
39 lines (33 loc) · 964 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
#syntax=docker/dockerfile:1.4
ARG GO_VERSION=1.18
FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.1.0 AS xx
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base
RUN apk add --no-cache git
COPY --from=xx / /
WORKDIR /src
FROM base AS build
ARG TARGETPLATFORM
ENV CGO_ENABLED=0
COPY go.mod .
COPY *.go .
RUN --mount=target=/go/pkg/mod,type=cache \
--mount=target=/root/.cache,type=cache \
xx-go build -ldflags="-w -s" -o ./main ./...
FROM base AS test
ARG TESTFLAGS
COPY go.mod .
COPY *.go .
RUN --mount=target=/go/pkg/mod,type=cache \
--mount=target=/root/.cache,type=cache \
CGO_ENABLED=0 xx-go test -test.v ${TESTFLAGS} ./...
FROM base AS test-noroot
RUN mkdir /go/pkg && chmod 0777 /go/pkg
USER 1000:1000
COPY go.mod .
COPY *.go .
RUN --mount=target=/tmp/.cache,type=cache \
CGO_ENABLED=0 GOCACHE=/tmp/gocache xx-go test -test.v ./...
FROM scratch
WORKDIR /app
COPY --from=build /src/main /app/main
ENTRYPOINT ["/app/main"]