-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make docker build faster #1074
Make docker build faster #1074
Changes from 4 commits
f7a18b8
fe21590
6a6f0af
fdbe5e1
36f8a67
5b22c73
9c287c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# syntax = docker/dockerfile:1.2 | ||
############################ | ||
# Build | ||
############################ | ||
|
@@ -19,13 +20,16 @@ ENV GO111MODULE=on | |
RUN go mod download | ||
RUN go mod verify | ||
|
||
# Copy everything from the current directory to the PWD(Present Working Directory) inside the container | ||
COPY . . | ||
|
||
# Build the binary | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ | ||
-ldflags='-w -s -extldflags "-static"' -a \ | ||
-o /go/bin/goshimmer | ||
# 1. Mount everything from the current directory to the PWD(Present Working Directory) inside the container | ||
# 2. Mount the build cache volume | ||
# 3. Build the binary | ||
# 4. Verify that goshimmer binary is statically linked | ||
RUN --mount=target=. \ | ||
--mount=type=cache,target=/root/.cache/go-build \ | ||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ | ||
-ldflags='-w -s -extldflags "-static"' \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see you removed the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only reason that I see is to always rebuild everything including the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I usually add the |
||
-o /go/bin/goshimmer; \ | ||
./check_static.sh | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the static check really needed? Shouldn't otherwise the build with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need it with 99.99% probability. The only case we would need it that I see is: if there is a flow in the Go build cache mechanism and it re-used some dynamically linked parts. Since we don't rebuild everything from scratch as with |
||
|
||
############################ | ||
# Image | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
# This script uses ldd utility to verify that result goshimmer binary is statically linked | ||
|
||
ldd /go/bin/goshimmer &> /dev/null | ||
if [ $? -ne 0 ]; then | ||
exit 0 | ||
else | ||
echo "/go/bin/goshimmer must be a statically linked binary" | ||
exit 1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should significantly speed up local builds and thus make development for integration tests much less painful. But we won't be able to leverage the cache on GH Actions since this is not persisted anywhere and we'd need to share it across builds as suggested as a "hack" here See this issue moby/buildkit#1512.
Another option would be using one of the techniques described in #890.
But in general I think this is already great and we should maybe first implement static peering to speed up overall execution of the integration tests before investing too much time into CI optimizations/caching
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree with you. Reusing
RUN --mount=type=cache
in GH actions seems to be hard right now. let's postpone it.The docker layer caching is pretty doable: here are the official docker GH actions for that: https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md
and a third-party article https://evilmartians.com/chronicles/build-images-on-github-actions-with-docker-layer-caching
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is the mounting interacting with the docker build cache?
Before with a
COPY . .
it was assured that if none of the files (outside of .dockerignore) changed, all the successive build steps were skipped.Is the
mount .
doing the same and is it also skipping files dockerignore? I think it could make sense to still keep theCOPY
for the sources.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It provides the same features as
COPY . .
: if none of the files changed: everything is cached in dockerYes, it also respects the .dockerignore file.
This tips if from the official Docker article for Go applications https://www.docker.com/blog/containerize-your-go-developer-environment-part-3/: