-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
67 lines (52 loc) · 1.38 KB
/
Dockerfile
File metadata and controls
67 lines (52 loc) · 1.38 KB
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
# See https://medium.com/@chemidy/create-the-smallest-and-secured-golang-docker-image-based-on-scratch-4752223b7324
FROM golang:1.20-alpine AS builder
# Git is used for dependencies
RUN apk update \
&& apk add \
--no-cache \
git \
ca-certificates
ENV USER=hackathon
ENV UID=1000
# See https://stackoverflow.com/a/55757473/12429735RUN
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
-u "${UID}" \
"${USER}"
ARG PROJECT
ARG RELEASE
ARG COMMIT
WORKDIR $GOPATH/src/${PROJECT}/
COPY ${PROJECT}/go.mod ${PROJECT}/go.sum ./
RUN go mod download \
&& go mod verify
COPY ${PROJECT}/ .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-o /go/bin/hackathon \
-ldflags="\
-w -s \
-X ${PROJECT}/version.Name=${PROJECT} \
-X ${PROJECT}/version.Release=${RELEASE} \
-X ${PROJECT}/version.Commit=${COMMIT} \
-X ${PROJECT}/version.BuildTime=$(date -u -Iseconds)" \
${PROJECT}.go
FROM scratch
ARG PROJECT
ENV RABBITMQ "amqp://guest:guest@rabbitmq:5672/"
WORKDIR /go
COPY --from=builder \
/etc/passwd \
/etc/group \
/etc/
COPY --from=builder \
/etc/ssl/certs/ca-certificates.crt \
/etc/ssl/certs/
COPY --from=builder \
/go/bin/hackathon \
/go/bin/hackathon
USER 1000
ENTRYPOINT [ "/go/bin/hackathon" ]