save the planet 2/2: multi-stages prod build: lighter and faster #92
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.
This PR makes prod builds an order of magnitude faster and lighter
Currently, in the prod mode, every time the Acsone Odoo bedrock base image gets a security update (once a week), all the Docker lines caches are swept and we rebuild the world, downloading 15 years of Odoo git history that weights 5.7 Gb. It can easily take 20 min in the cloud to 1h30 with a bad onsite connection...
With this change, we pack the bare git-autoshare object references minimum to make the build always fast and light: git history objects are never copied in the production image, only the <250 Mb worktree is. The auxiliary base image weights also no more than 280 Mb because we use fetch --shallow-since the release date: so we can get the Odoo PR merges without carrying the whole "fatty odoo" git repo.
Cached builds still take less than 3 seconds while builds after an Acsone Odoo bedrock update will not download anything from odoo/odoo, only copy the 250 Mb local worktree. And odoo-spec,yaml updates will not trigger large downloads either, only the git delta will be fetched. Most of these builds don't exceed 2 minutes.
Only a standard Dockerfile, no host hack.
The auxiliary images are built here https://github.com/akretion/odoo-docker-builder
see https://docs.docker.com/build/building/multi-stage/
full explanation and real life example https://gitlab.akretion.com/akretion/dualsun/-/merge_requests/179
cc @hparfr @PierrickBrun @sebastienbeau @bealdav @renatonlima @mbcosta