-
Notifications
You must be signed in to change notification settings - Fork 2k
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
do not patch Dockerfiles in CI #1537
Conversation
ping @ijc @vdemeester @dnephin PTAL |
Codecov Report
@@ Coverage Diff @@
## master #1537 +/- ##
==========================================
- Coverage 55.22% 55.22% -0.01%
==========================================
Files 289 289
Lines 19389 19384 -5
==========================================
- Hits 10708 10705 -3
+ Misses 7984 7983 -1
+ Partials 697 696 -1 |
866c837
to
f1a9536
Compare
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.
LGTM 🐯
This comment has been minimized.
This comment has been minimized.
When building the Dockerfiles for development, those images are mainly used to create a reproducible build-environment. The source code is bind-mounted into the image at runtime; there is no need to create an image with the actual source code, and copying the source code into the image would lead to a new image being created for each code-change (possibly leading up to many "dangling" images for previous code-changes). However, when building (and using) the development images in CI, bind-mounting is not an option, because the daemon is running remotely. To make this work, the circle-ci script patched the Dockerfiles when CI is run; adding a `COPY` to the respective Dockerfiles. Patching Dockerfiles is not really a "best practice" and, even though the source code does not and up in the image, the source would still be _sent_ to the daemon for each build (unless BuildKit is used). This patch updates the makefiles, circle-ci script, and Dockerfiles; - When building the Dockerfiles locally, pipe the Dockerfile through stdin. Doing so, prevents the build-context from being sent to the daemon. This speeds up the build, and doesn't fill up the Docker "temp" directory with content that's not used - Now that no content is sent, add the COPY instructions to the Dockerfiles, and remove the code in the circle-ci script to "live patch" the Dockerfiles. Before this patch is applied (with cache): ``` $ time make -f docker.Makefile build_shell_validate_image docker build -t docker-cli-shell-validate -f ./dockerfiles/Dockerfile.shellcheck . Sending build context to Docker daemon 41MB Step 1/2 : FROM debian:stretch-slim ... Successfully built 81e14e8ad856 Successfully tagged docker-cli-shell-validate:latest 2.75 real 0.45 user 0.56 sys ``` After this patch is applied (with cache):: ``` $ time make -f docker.Makefile build_shell_validate_image cat ./dockerfiles/Dockerfile.shellcheck | docker build -t docker-cli-shell-validate - Sending build context to Docker daemon 2.048kB Step 1/2 : FROM debian:stretch-slim ... Successfully built 81e14e8ad856 Successfully tagged docker-cli-shell-validate:latest 0.33 real 0.07 user 0.08 sys ``` Signed-off-by: Sebastiaan van Stijn <[email protected]>
f1a9536
to
166856a
Compare
ping @silvin-lubecki @dnephin PTAL 🤗 |
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.
LGTM
Interesting solution to the problem. I agree it's an improvement over appending to the Dockerfile.
What I ended up doing in one of my projects to solve this same problem is to make the main image FROM ... as dev
and then I added:
FROM dev as dev-with-source
COPY . .
Then I could use --target dev
to get a version that still had some context, but not necessarily the full context.
Yes, I considered that solution; the downside of that solution is that the context is still sent, even though it's not consumed.
In this case, no context was needed at all, so I went for this option; the "FROM dev ..." approach could be used once we need it
… On 1 Dec 2018, at 05:05, Daniel Nephin ***@***.***> wrote:
@dnephin approved this pull request.
LGTM
Interesting solution to the problem. I agree it's an improvement over appending to the Dockerfile.
What I ended up doing in one of my projects to solve this same problem is to make the main image FROM ... as dev and then I added:
FROM dev as dev-with-source
COPY . .
Then I could use --target dev to get a version that still had some context, but not necessarily the full context.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
ready for merge? 🤗 |
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.
LGTM 🐯
When building the Dockerfiles for development, those images are mainly used to create a reproducible build-environment. The source code is bind-mounted into the image at runtime; there is no need to create an image with the actual source code, and copying the source code into the image would lead to a new image being created for each code-change (possibly leading up to many "dangling" images for previous code-changes).
However, when building (and using) the development images in CI, bind-mounting is not an option, because the daemon is running remotely.
To make this work, the circle-ci script patched the Dockerfiles when CI is run; adding a
COPY
to the respective Dockerfiles.Patching Dockerfiles is not really a "best practice" and, even though the source code does not and up in the image, the source would still be sent to the daemon for each build (unless BuildKit is used).
This patch updates the makefiles, circle-ci script, and Dockerfiles;
Doing so, prevents the build-context from being sent to the daemon. This speeds
up the build, and doesn't fill up the Docker "temp" directory with content that's
not used
remove the code in the circle-ci script to "live patch" the Dockerfiles.
Before this patch is applied (with cache):
After this patch is applied (with cache)::
Signed-off-by: Sebastiaan van Stijn [email protected]
- What I did
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)