-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
47 lines (34 loc) · 1.11 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
############################
# STEP 1 build executable binary
############################
FROM --platform=$BUILDPLATFORM golang:alpine AS builder
# Install git.
RUN apk update && apk add --no-cache git=~2
# Set up working directory
WORKDIR /app
# Copy go.mod and go.sum separately so we only invalidate the downloading layers if we need to
COPY go.mod go.sum ./
# Fetch dependencies and build the binary
ENV GO111MODULE=on
RUN go mod download
# Copy the rest of the project to ensure code changes doesnt trigger re-download of all deps
COPY . .
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$GOARCH go build -a -installsuffix cgo -o main .
############################
# STEP 2 build a small image
############################
FROM alpine:3
# Set up the working directory
WORKDIR /go
# Copy the binary from the builder stage
COPY --from=builder /app/main .
# Copy the "index" folder
COPY --from=builder /app/index index
# Copy the "docs" folder
COPY --from=builder /app/docs docs
# Set environment variables and expose necessary port
ENV PORT=8080
ENV GIN_MODE=release
EXPOSE 8080
# Run the Go Gin binary
ENTRYPOINT ["./main"]