-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
82 lines (55 loc) · 1.67 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
FROM --platform=$BUILDPLATFORM golang:1.23.3-bullseye AS builder-base
ARG TARGETOS TARGETARCH
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
apt-get install -y git ca-certificates tzdata && \
update-ca-certificates
ENV USER=application
ENV UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
WORKDIR $GOPATH/src/app
COPY go.mod .
RUN go mod download && go mod verify
COPY . .
# ----------------
FROM builder-base AS builder-test
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH \
go build \
-o /go/bin/main -v cmd/main.go
# ----------------
FROM builder-base AS builder-release
RUN --mount=target=. \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
go build \
-ldflags="-w -s" -a -installsuffix cgo \
-o /go/bin/main -v cmd/main.go
# ----------------
FROM scratch AS base
COPY --from=builder-base /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder-base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder-base /etc/passwd /etc/passwd
COPY --from=builder-base /etc/group /etc/group
COPY --from=builder-base /go/src/app/web /app/web
# ----------------
FROM base AS release
COPY --from=builder-release /go/bin/main /app/cmd/main
WORKDIR /app
ENTRYPOINT [ "/app/cmd/main" ]
EXPOSE 3000
# ----------------
FROM debian:bullseye AS test
COPY --from=base / /
COPY --from=builder-test /go/bin/main /app/cmd/main
WORKDIR /app
ENTRYPOINT [ "/app/cmd/main" ]
EXPOSE 3000
# ---------------- default target
FROM test