-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
54 lines (38 loc) · 1014 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
FROM golang:1.18.2-alpine3.15 AS build
# Install Alpine Dependencies
RUN apk update && apk upgrade && \
apk add --no-cache make protoc gcc musl-dev
# Set working directory
WORKDIR /app
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download
# Copy the project files
COPY cmd cmd
COPY internal internal
COPY Makefile ./
COPY LICENSE ./
COPY README.md ./
# Generate code
RUN make generate-code
# Generate docs
RUN make generate-docs
# Define development target
FROM build AS development
# Build with -race option
RUN make build-for-development
# Start development
CMD ["./main"]
# Define production target
FROM build AS production_build
# Build project
RUN make build-for-production
# Start from fresh image
FROM alpine:3.15 AS production
# Set working directory
WORKDIR /app
# Copy binary from build stage
COPY --from=production_build /app/main /app/main
# Start
CMD ["./main"]