-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
71 lines (62 loc) · 1.81 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
ARG GO_VERSION=1.17
FROM --platform=$BUILDPLATFORM crazymax/goreleaser-xx:latest AS goreleaser-xx
FROM --platform=$BUILDPLATFORM pratikimprowise/upx:3.96 AS upx
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base
COPY --from=goreleaser-xx / /
COPY --from=upx / /
ENV CGO_ENABLED=0
ENV GO111MODULE=auto
RUN apk --update add --no-cache git
WORKDIR /src
FROM base AS vendored
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/go/pkg/mod \
go mod tidy && go mod download
FROM vendored AS bin
ARG TARGETPLATFORM
RUN --mount=type=bind,source=.,target=/src,rw \
--mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/go/pkg/mod \
goreleaser-xx --debug \
--name="tarrer" \
--main="." \
--dist="/out" \
--artifacts="bin" \
--artifacts="archive" \
--snapshot="no"
FROM scratch as fat
COPY --from=bin /usr/local/bin/tarrer /usr/local/bin/tarrer
ENTRYPOINT ["/usr/local/bin/tarrer"]
FROM vendored AS bin-slim
ARG TARGETPLATFORM
RUN --mount=type=bind,source=.,target=/src,rw \
--mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/go/pkg/mod \
goreleaser-xx --debug \
--name="tarrer-slim" \
--ldflags="-s -w" \
--flags="-trimpath" \
--main="." \
--dist="/out" \
--artifacts="bin" \
--artifacts="archive" \
--snapshot="no" \
--post-hooks="sh -c 'upx -v --ultra-brute --best -o /usr/local/bin/{{ .ProjectName }}{{ .Ext }} || true' "
FROM scratch as slim
COPY --from=bin-slim /usr/local/bin/tarrer-slim /usr/local/bin/tarrer
ENTRYPOINT ["/usr/local/bin/tarrer"]
## get binary out
### non slim binary
FROM scratch AS artifact
COPY --from=bin /out /
###
### slim binary
FROM scratch AS artifact-slim
COPY --from=bin-slim /out /
###
### All binaries
FROM scratch AS artifact-all
COPY --from=bin /out /
COPY --from=bin-slim /out /
###
##