-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
39 lines (27 loc) · 861 Bytes
/
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
# Start from golang base image
FROM golang:1.21-alpine as builder
# Install git dependencies
RUN apk update && apk add --no-cache git alpine-sdk
# Working directory
WORKDIR /app
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download all dependencies
RUN go mod download
# Copy everything
COPY . .
# Build the Go app
ENV GOCACHE=/root/.cache/go-build
RUN --mount=type=cache,target="/root/.cache/go-build" CGO_ENABLED=1 GOOS=linux go build -mod=readonly -v -o main .
# Start a new stage from scratch
FROM alpine:latest
# Install ca-certificates runtime libraries
RUN apk --no-cache add ca-certificates
WORKDIR /root/
# Copy the pre-built binary file from the previous stage. Also copy config yml file
COPY --from=builder /app/main .
# Expose port 8080 to the outside world
EXPOSE 8000
EXPOSE 50051
# Command to run the executable
CMD ["./main"]