-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
executable file
·76 lines (67 loc) · 1.91 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
# syntax=docker/dockerfile:1.3
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 / /
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
## bin
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="zipper" \
--main="./cmd/zipper" \
--dist="/out" \
--artifacts="bin" \
--artifacts="archive" \
--snapshot="no"
## Slim bin
FROM vendored AS bin-slim
COPY --from=upx / /
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="zipper-slim" \
--flags="-trimpath" \
--ldflags="-s -w" \
--main="./cmd/zipper" \
--dist="/out" \
--artifacts="bin" \
--artifacts="archive" \
--snapshot="no" \
--post-hooks="sh -c 'upx -v --ultra-brute --best -o /usr/local/bin/{{ .ProjectName }}{{ .Ext }} || true'"
## standard
FROM scratch AS standard
COPY --from=bin /usr/local/bin/zipper /usr/local/bin/zipper
ENTRYPOINT [ "/usr/local/bin/zipper" ]
## Slim
FROM scratch AS slim
COPY --from=bin-slim /usr/local/bin/zipper-slim /usr/local/bin/zipper
ENTRYPOINT [ "/usr/local/bin/zipper" ]
## 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 /
###
##