Feature: parallelize dockerized builds GitHub actions#28
Open
marcellodesales wants to merge 5 commits intodevelopfrom
Open
Feature: parallelize dockerized builds GitHub actions#28marcellodesales wants to merge 5 commits intodevelopfrom
marcellodesales wants to merge 5 commits intodevelopfrom
Conversation
Hotfix: Makefile: fix publish of Github version image
According to the Buildkit library of docker, we can make parallel builds easier with multi-stage Dockerfiles. https://docs.docker.com/develop/develop-images/build_enhancements/#to-enable-buildkit-builds Here's an example: $ cat Dockerfile2 FROM alpine AS dependencies RUN echo "Downloading dependencies" RUN sleep 15 && echo "dependencies done" FROM dependencies AS windows RUN echo "Compiling windows" RUN sleep 10 && echo "windows done" FROM dependencies AS linux RUN echo "Compiling linux" RUN sleep 10 && echo "linux done" $ DOCKER_BUILDKIT=1 docker build -t build-dependencies -f ./Dockerfile2 --target dependencies . [+] Building 0.1s (7/7) FINISHED => [internal] load build definition from Dockerfile2 0.0s => => transferring dockerfile: 38B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/alpine:latest 0.0s => [dependencies 1/3] FROM docker.io/library/alpine 0.0s => CACHED [dependencies 2/3] RUN echo "Downloading dependencies" 0.0s => CACHED [dependencies 3/3] RUN sleep 15 && echo "dependencies done" 0.0s => exporting to image 0.0s => => exporting layers 0.0s => => writing image sha256:b70fc38c238cddf7d88cb495634ce79cb49b0b9416018746e8523433f91a6015 0.0s => => naming to docker.io/library/build-dependencies 0.0s * Here, another feature is to use the build cache from the previous image built for dependencies. In addition, reusing the cache is shown as CACHED for the dependencies and it avoids building the entire docker image stages (when not using BUILDKIT=1) $ DOCKER_BUILDKIT=1 docker build -t windows-binary -f ./Dockerfile2 --target windows --cache-from=build-dependencies . [+] Building 0.0s (10/10) FINISHED => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load build definition from Dockerfile2 0.0s => => transferring dockerfile: 38B 0.0s => [internal] load metadata for docker.io/library/alpine:latest 0.0s => importing cache manifest from build-dependencies 0.0s => [dependencies 1/3] FROM docker.io/library/alpine 0.0s => CACHED [dependencies 2/3] RUN echo "Downloading dependencies" 0.0s => CACHED [dependencies 3/3] RUN sleep 15 && echo "dependencies done" 0.0s => CACHED [windows 1/2] RUN echo "Compiling windows" 0.0s => CACHED [windows 2/2] RUN sleep 10 && echo "windows done" 0.0s => exporting to image 0.0s => => exporting layers 0.0s => => writing image sha256:cb2fdc9acfa878f50314d03e644f205729c8314c90d8323fb9203bbc16227275 0.0s => => naming to docker.io/library/windows-binary * Same here for the linux binaries, we can build and only the linux ones will be built with the help of the cache built previously. $ DOCKER_BUILDKIT=1 docker build -t linux-binary -f ./Dockerfile2 --target linux --cache-from=build-dependencies . [+] Building 0.1s (10/10) FINISHED => [internal] load build definition from Dockerfile2 0.0s => => transferring dockerfile: 38B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/alpine:latest 0.0s => importing cache manifest from build-dependencies 0.0s => [dependencies 1/3] FROM docker.io/library/alpine 0.0s => CACHED [dependencies 2/3] RUN echo "Downloading dependencies" 0.0s => CACHED [dependencies 3/3] RUN sleep 15 && echo "dependencies done" 0.0s => CACHED [linux 1/2] RUN echo "Compiling linux" 0.0s => CACHED [linux 2/2] RUN sleep 10 && echo "linux done" 0.0s => exporting to image 0.0s => => exporting layers 0.0s => => writing image sha256:35c85e91b47966432ae3d3c60bc455587bc46016eb528674b51b3f8c86a1e9da 0.0s => => naming to docker.io/library/linux-binary 0.0s Our builds are to run with the same level of separation. *** For our builds with BUILDKIT, we have the following => Dockerifle * dependencies: downloads all the OS and Golang specific dependencies $ DOCKER_BUILDKIT=1 BIN_VERSION=20.09.10 docker-compose build dependencies * compiler: compiles the go code with the dependencies layer $ DOCKER_BUILDKIT=1 BIN_VERSION=20.09.10 PLATFORMS=darwin docker-compose build binaries * runtime: specific for the linux runtime $ DOCKER_BUILDKIT=1 PLATFORMS=linux BIN_VERSION=20.09.10 docker-compose build runtime
* build-dependencies: build the docker image with dependencies as cache to be reused by others. * compile: for specific language * runtime: for the linux runtime
This is to speed up the compile task so that it makes images faster
4d1bd14 to
a662400
Compare
a662400 to
6c481b1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Docker Buildkit
Local use