Skip to content

Commit 992b011

Browse files
committed
revert to a single stage build
this has the disadvantage of being a large image (because it's based on golang:alpine and not alpine, plus the fact that building the project creates various cache files, though these cache files are the things we need in order to speed up compiling the project on the main go build line. most of the compilation time is spent on the dependenent libraries (i.e. discordgo, crypto, stdlib, etc). there is not a functional method of compiling dependencies from a bare go.mod and go.sum file[1], you must have a valid go project in the directory for go build all to work, at which point the docker layer cache has been invalidated by `COPY . /app`. the proposed `go list -export $(go list -m)/...` does not compile all dependencies either, showcased by checking the size of $GOCACHE before and after running `go build all` without doing funky stuff like bind-mounting a volume container into the build container[2], inflating the image size for faster compiling seems to be the best tradeoff, as the image will only stay local anyway [1] golang/go#27719 [2] https://github.com/banzaicloud/docker-golang
1 parent a83f44d commit 992b011

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

Dockerfile

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1-
FROM golang:alpine as dep_builder
2-
ARG PROJPATH=/go/src/github.com/BEANSQUAD/paul-bot
3-
RUN apk add --no-cache git gcc libc-dev
4-
WORKDIR $PROJPATH
5-
COPY go.mod go.sum ./
1+
FROM golang:alpine
2+
RUN apk add --no-cache git gcc libc-dev ca-certificates
3+
WORKDIR /app
4+
COPY go.mod go.sum /app
65
RUN go mod download
7-
RUN go build -v all
8-
9-
FROM dep_builder as proj_builder
10-
ARG PROJPATH=/go/src/github.com/BEANSQUAD/paul-bot
11-
COPY . $PROJPATH
12-
COPY --from=dep_builder /root/.cache/go-cache /root/.cache/go-cache
6+
COPY . /app
137
RUN go build -v -a -o paul-bot main.go
14-
15-
FROM alpine
16-
RUN apk add --no-cache ca-certificates
17-
COPY --from=proj_builder $PROJPATH/paul-bot /paul-bot
18-
CMD ["/paul-bot"]
8+
CMD ["/app/paul-bot"]

0 commit comments

Comments
 (0)