generated from pieceowater-dev/lotof.sample.svc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
47 lines (33 loc) · 998 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
# Stage 1: Build the application and generate code
FROM golang:1.23 AS builder
WORKDIR /app
# Install dependencies
RUN apt-get update && \
apt-get install -y unzip wget curl libc6 protobuf-compiler && \
apt-get clean
# Copy go mod and sum files
COPY go.mod go.sum ./
RUN go mod download
# Copy the source code
COPY . .
# Install tools for code generation
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# Generate gRPC code
# RUN make grpc-update
RUN make grpc-gen
# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -o app ./cmd/server/main.go
# Stage 2: Create the final image
FROM alpine:latest
WORKDIR /root/
# Copy the binary from the builder stage
COPY --from=builder /app/app .
LABEL authors="pieceowater"
# Command to run the application
CMD ["./app"]
EXPOSE 50051
EXPOSE 3000
# Clean up unnecessary files to reduce image size
RUN rm -rf /app && \
rm -rf /root/.cache