-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
55 lines (38 loc) · 1.04 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
# Using multistage builds so the final image is smaller
# https://docs.docker.com/language/golang/build-images/#multi-stage-builds
###################
# 1. Building stage
###################
FROM golang:1.23.2 AS build-stage
# Update CA-Certs
RUN update-ca-certificates
# Set destination for COPY
WORKDIR /nexisAPI
# Add caching
ENV GOCACHE=$HOME/.cache/go-build
RUN --mount=type=cache,target=$GOCACHE go env -w GOCACHE=$GOCACHE
# Download Go modules
# Doing this FIRST so dependencies are cached first
COPY go.mod go.sum ./
RUN go mod download
# Copy the source code.
COPY *.go ./
COPY cmd/ ./cmd/
# Build
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -a -installsuffix cgo -o /nexis
###################
# 2. Run tests
###################
FROM build-stage AS run-test-stage
RUN go test -v ./...
###################
# 3. Deploying
###################
FROM gcr.io/distroless/static-debian11 AS deploy-stage
WORKDIR /
# Copy bin from build stage
COPY --from=build-stage /nexis /nexis
# Expose port 3000
EXPOSE 3000
# Run
ENTRYPOINT ["/nexis"]