-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
40 lines (28 loc) · 996 Bytes
/
Dockerfile
File metadata and controls
40 lines (28 loc) · 996 Bytes
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
# Stage 1: Build
FROM golang:1.23 AS builder
# Disable CGO to produce a fully static binary
ENV CGO_ENABLED=0
# Set the Go proxy to help with module resolution
ENV GOPROXY=https://proxy.golang.org,direct
# Set the working directory
WORKDIR /app
# Copy dependency files and download dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the source code
COPY . .
# Build the binary and place it in the /app/bin directory
RUN go build -o ./bin/go-modules-api main.go
# Stage 2: Final image for execution
FROM alpine:3.17
# Install necessary certificates
RUN apk add --no-cache ca-certificates
# Set the working directory
WORKDIR /root/
# Copy the compiled binary and the .env file into the final image
COPY --from=builder /app/bin/go-modules-api /bin/go-modules-api
COPY --from=builder /app/.env .env
# Copy the docs folder so the binary finds ./docs/redoc.html
COPY --from=builder /app/docs /root/docs
# Default command to run the binary
CMD ["/bin/go-modules-api"]