-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
54 lines (37 loc) · 1.22 KB
/
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
# build stage
FROM golang:1.17-alpine AS builder
WORKDIR /app
# copy files to download dependencies
COPY go.mod go.sum ./
# download dependencies
RUN go mod download
# explicitly download missing package
# RUN go mod download google.golang.org/grpc
# RUN go mod tidy
# RUN go get google.golang.org/grpc@v1.43.0
# RUN go get google.golang.org/protobuf/runtime/protoimpl@v1.31.0
# RUN go get google.golang.org/grpc/protobuf/reflect/protoreflect
# @v1.31.0
# RUN go mod tidy
# copy project
COPY helloworld ./helloworld
# COPY . .
WORKDIR /app/helloworld
# build greeter_server binary
RUN CGO_ENABLED=0 GOOS=linux go build -o greeter_server ./greeter_server
# build greeter_client binary
RUN CGO_ENABLED=0 GOOS=linux go build -o greeter_client ./greeter_client
# final stage
FROM alpine:latest
WORKDIR /app
# copy built server & client binaries from previous stage
COPY --from=builder /app/helloworld/greeter_server .
COPY --from=builder /app/helloworld/greeter_client .
# set executable permission for binary
RUN chmod +x greeter_server greeter_client
# install go dependencies
RUN apk update && apk add --no-cache ca-certificates
# expose desired port
EXPOSE 50051
# set entrypoint to run greeter_server
CMD ["./greeter_server"]