bill-server-go/Dockerfile

37 lines
848 B
Docker
Raw Normal View History

2023-05-05 20:27:33 +08:00
# Get Go image from DockerHub.
2023-05-11 20:01:08 +08:00
FROM golang:1.20 AS api
2023-05-05 20:27:33 +08:00
# Set working directory.
WORKDIR /compiler
2023-05-12 21:46:48 +08:00
# Env GOPROY
ENV GOPROXY="https://proxy.golang.com.cn,direct"
2023-05-05 20:27:33 +08:00
# Copy dependency locks so we can cache.
2023-05-11 20:01:08 +08:00
COPY go.mod go.sum ./
2023-05-05 20:27:33 +08:00
# Get all of our dependencies.
RUN go mod download
# Copy all of our remaining application.
COPY . .
# Build our application.
2023-06-02 19:03:08 +08:00
RUN #CGO_ENABLED=0 GOOS=linux go build -o bill-server ./cmd/bill-server/main.go
RUN go build -a -ldflags "-linkmode external -extldflags '-static' -s -w" -o bill-server ./cmd/bill-server/main.go
2023-05-05 20:27:33 +08:00
# Use 'scratch' image for super-mini build.
FROM scratch AS prod
# Set working directory for this stage.
WORKDIR /production
# Copy our compiled executable from the last stage.
2023-06-02 19:03:08 +08:00
COPY --from=api /compiler/bill-server .
2023-05-05 20:27:33 +08:00
# Run application and expose port 8080.
EXPOSE 8080
2023-06-02 19:03:08 +08:00
CMD ["./bill-server"]