-
Notifications
You must be signed in to change notification settings - Fork 145
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
[Onweek] - Replace templating with docker args in dockerfile #6177
base: main
Are you sure you want to change the base?
Conversation
Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane) |
This pull request does not have a backport label. Could you fix it @pchila? 🙏
|
|
Quality Gate passedIssues Measures |
What does this PR do?
Remove go templating from Dockerfile and substitute it with docker build arguments
This PR re-organises the docker build in 3 or more stages:
Currently tested with ubuntu and wolfi base images (ubi/rhel needs another base image, it looks feasible though)
There's a lot of build arguments defined as we need a lot of flexibility but maybe that can also be simplified.
Build args are evaluated still using templating in the docker builder but they become plain strings when invoking Docker
Why is it important?
It allows using standardized toolchains that do not necessarily play nice with golang templating.
It also allows for good IDE integration and syntax checks so editing should be easier.
Iterating over elastic agent docker images should be easier since build can be kicked off with a plain
docker
command.Checklist
./changelog/fragments
using the changelog toolDisruptive User Impact
How to test this PR locally
Implementation is not yet complete (there are a few attributes missing from the docker specs like the base image family or the build target to be used for a specific spec), however the new build can still be tested by using a new env var when packaging:
There's still potential to use docker build cache, especially if we relaunch a docker build using the command line stored in the package dir:
➜ elastic-agent git:(onweek-improve-dockerfile) ✗ cat build/package/elastic-agent/elastic-agent-linux-amd64.docker/docker_build_cmd.txt docker buildx build --build-arg BEAT_COMMIT=325e6e75dd4c5eac4e79d8bc83529ce87087215f --build-arg BEAT_DESCRIPTION=Elastic Agent - single, unified way to add monitoring for logs, metrics, and other types of data to a host. --build-arg BEAT_ROOT_IMPORT_PATH=https://www.elastic.co/beats/elastic-agent --build-arg BEAT_VCS_REF=github.com/elastic/elastic-agent --build-arg DOCKER_VARIANT=basic --build-arg ELASTIC_AGENT_USER=elastic-agent --build-arg BEAT_COMMIT_SHORT=325e6e --build-arg BEAT_LICENSE=Elastic License --build-arg BEAT_URL=https://www.elastic.co/beats/elastic-agent --build-arg BEAT_VENDOR=Elastic --build-arg BEAT_VERSION=9.0.0-SNAPSHOT --build-arg BUILD_TIMESTAMP=2024-12-02T09:09:29Z --build-context dockerbuild=/home/paolo/dev/elastic-agent/dev-tools/packaging/docker --target image_basic -f /home/paolo/dev/elastic-agent/dev-tools/packaging/docker/Dockerfile -t docker.elastic.co/beats/elastic-agent:9.0.0-SNAPSHOT build/package/elastic-agent/elastic-agent-linux-amd64.docker/docker-build % ➜ elastic-agent git:(onweek-improve-dockerfile) ✗
however, since the
mage package
process downloads components and compiles elastic-agent binary again the cache gets invalidated easily even if the exact same components/source code is used (this should be looked into as better caching would improve packaging in general, especially for development usecases)Related issues
Questions to ask yourself