-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
48 lines (43 loc) · 1.14 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
# Dockerfile
# for building/running Go (Golang) services
#
# docker build -t go-ginrest:1.20 .
# docker run -rm go-ginrest:1.20
#
# https://docs.docker.com/engine/reference/run/
# https://golang.org/help/
# https://play.golang.org/
#
# Docker multi-stage build
ARG GO_VERSION=1.20
ARG ALPINE_VERSION=latest
# Golang
FROM "golang:${GO_VERSION}" AS builder
# ENV
ENV GOFLAGS=-mod=mod \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
WORKDIR /src
COPY . .
# RUN go build -ldflags "-s -w"
RUN GOFLAGS=-mod=mod go build -ldflags "-s -w" -o /src/bin .
# Alpine
FROM "alpine:${ALPINE_VERSION}"
LABEL service="go-ginrest"
LABEL github="github.com/nicholashoule"
LABEL version="1.0.0"
LABEL description="For running Go (Golang) services."
# RUN apk and add group/user
# Development container
RUN apk --no-cache add ca-certificates \
&& update-ca-certificates \
&& addgroup -g 1001 appgroup \
&& adduser -H -D -s /bin/false -G appgroup -u 1001 appuser \
&& mkdir -p tls \
&& chown appuser /tls
USER 1001:1001
COPY --from=builder /src/bin/go-ginrest /opt/go/go-ginrest
COPY --from=builder /src/favicon.ico /
#ENTRYPOINT ["/bin/sh"]
ENTRYPOINT ["/opt/go/go-ginrest"]