-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
41 lines (29 loc) · 1.09 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
ARG GO_VERSION=1.22.5
# BUILD STAGE
FROM golang:${GO_VERSION}-alpine as builder
ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
# Install the Certificate-Authority certificates for the app to be able to make calls to HTTPS endpoints.
# Install git
# Git is required for fetching the dependencies.
RUN apk update && apk add --no-cache ca-certificates git
# Set the working directory outside $GOPATH to enable the support for modules.
WORKDIR /app
COPY go.mod .
COPY go.sum .
# Fetch dependencies first; they are less susceptible to change on every build
# and will therefore be cached for speeding up the next build
RUN go mod download
COPY . .
# Build the executable to `/app`. Mark the build as statically linked.
RUN go build -o app ./cmd/api
# FINAL STAGE: the running container.
FROM alpine:3.17.3 AS final
# Import the Certificate-Authority certificates for enabling HTTPS.
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Import the compiled executable from the first stage.
COPY --chown=0:0 --from=builder /app/app /app
EXPOSE 3000
ENTRYPOINT ["/app"]