Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change Dockerfile to be a multistage build
The existing Dockerfile produced a broken binary (static compile caused the binary to segfault). This patch changes the Dockerfile to - Build a non-static binary - Use a multi-stage build: separate stages are used for build and deploy; the build stage contains the tools needed for building the binary, after which the build artefacts are copied to the final stage. which produces the actual image. Using this approach, the build-tools can be kept in the Docker build-cache, which improves performance of repeated builds and does not require cleanup steps in the Dockerfile itself, which can simplify the steps. - The official Python image is used for the build stage, so that there is no need to install python manually. The version of python is set to the same version as the version used in CI, but can be overridden using at build-time using a build-arg: docker build --build-arg PYTHON_VERSION=x .. - Both build- and deploy stages use the debian "stretch" variants, which matches what's used in the current version of the Dockerfile, but could be updated to the current stable ("buster") variant if there is a need. - The final stage uses the "slim" variant to reduce the size. For comparison, below are sizes of the final image when using the regular, or "slim" version of the image: REPOSITORY TAG IMAGE ID CREATED SIZE jq stretch-slim 4b7f380970f0 About a minute ago 70.3MB jq stretch c5fa8b766cd4 7 minutes ago 119MB A .dockerignore file is also added to prevent "busting" the Docker build-cache if not needed, and steps in the Dockerfile are optimized for BuildKit, but remain compatible with the legacy builder. To build, and verify the image: DOCKER_BUILDKIT=1 docker build -t jq . And, test the image, us it (for example) to pretty-print its own "docker image inspect" output: docker image inspect jq | docker run -i --rm jq . [ { "Id": "sha256:4b7f380970f0d06d4ca9137fbbb3fa3f6554da996147d1d956cda6f44be25650", "RepoTags": [ "jq:latest", "jq:stretch-slim" ], Signed-off-by: Sebastiaan van Stijn <[email protected]>
- Loading branch information