-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
36 lines (25 loc) · 921 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
FROM golang:1.22.7-alpine AS builder
# install required packages in a single layer
RUN apk add --no-cache git protobuf-dev && \
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && \
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
WORKDIR /app
COPY grpc-perf-lab/go.mod grpc-perf-lab/go.sum ./
RUN go mod download
COPY grpc-perf-lab/ .
# generate gRPC code and build in a single layer
RUN protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
helloworld/helloworld.proto && \
CGO_ENABLED=0 GOOS=linux go build -o /go/bin/server greeter_server/main.go
# final stage
FROM alpine:3.19
# add non-root user
RUN adduser -D appuser
USER appuser
COPY --from=builder /go/bin/server /server
# add health check
HEALTHCHECK --interval=30s --timeout=3s \
CMD nc -z localhost 50051 || exit 1
EXPOSE 50051
CMD ["/server"]