Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 46b1224

Browse files
committed
dockerfile: use builder pattern to reduce image size
Docker image size goes from 625mb to 67mb since we exclude the build environment and source. We also include tini and bind-tools which is standard practice in our images now. There is a risk we now act slightly worse due to not including the go build toolchain. I will validate this and rollback this change if that is indeed the case.
1 parent 34ea00e commit 46b1224

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

Dockerfile

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1-
FROM golang:alpine
1+
FROM golang:alpine AS builder
22

3-
COPY . /go/src/github.com/sourcegraph/go-langserver
4-
RUN cd /go/src/github.com/sourcegraph/go-langserver && go install .
5-
RUN apk add --no-cache openssh git curl
3+
RUN apk add --no-cache ca-certificates
4+
5+
ENV CGO_ENABLED=0 GO111MODULE=on
6+
WORKDIR /go/src/github.com/google/zoekt
7+
8+
# Cache dependencies
9+
COPY go.mod go.sum ./
10+
RUN go mod download
11+
12+
COPY . ./
13+
RUN go install .
14+
15+
FROM alpine AS go-langserver
16+
17+
RUN apk add --no-cache openssh git curl ca-certificates bind-tools tini
18+
19+
COPY --from=builder /go/bin/* /usr/local/bin/
20+
21+
ENTRYPOINT ["/sbin/tini", "--"]
622
CMD ["go-langserver"]

0 commit comments

Comments
 (0)