-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
39 lines (30 loc) · 915 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
# Build stage
FROM golang AS build-env
RUN apt-get update && apt-get install -y jq curl
RUN mkdir /src
WORKDIR /src
COPY go.mod .
COPY go.sum .
# Get dependancies - will also be cached if we won't change mod/sum
RUN go mod download
COPY Makefile ./
RUN make install
# Install buf (protobuf generation tool)
RUN curl -sSL $(curl -s https://api.github.com/repos/bufbuild/buf/releases/latest | jq -r '.assets[] | select(.name | contains("buf-Linux-x86_64")) | .browser_download_url') -o /usr/local/bin/buf \
&& chmod +x /usr/local/bin/buf
# COPY the source code as the last step
COPY . .
# RUN make install
RUN make generate
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
RUN go mod tidy
RUN go build -a -ldflags="-s -w" -installsuffix cgo -o /api
# Production stage
FROM alpine:latest
RUN apk add --no-cache ca-certificates
COPY --from=build-env /api /
EXPOSE 10000
EXPOSE 11000
CMD ["/api", "serve"]