Skip to content
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

Reduce docker image size (and build time) #115

Merged
merged 4 commits into from
Feb 25, 2021

Conversation

lcobucci
Copy link
Member

@lcobucci lcobucci commented Feb 24, 2021

Q A
Documentation no
Bugfix no
BC Break no
New Feature no
RFC no
QA yes

Description

This improves the build process of the docker image.

When the base images are already downloaded, it takes about 15s to build the image using BuildKit - previously it was taking 1m19s.
The image size has also been drastically reduced, it's 122Mb - previously was 390Mb.

This swaps the base image so that we can have:
* faster builds
* smaller images
* more secure and up-to-date dependencies

Signed-off-by: Luís Cobucci <lcobucci@gmail.com>
It's recommended to use `COPY` instead of `ADD` because it's much
simpler and avoids unexpected behaviour - `ADD` can also do things like
uncompressing files and remote requests.

More info: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#add-or-copy

Signed-off-by: Luís Cobucci <lcobucci@gmail.com>
@lcobucci lcobucci added this to the 1.10.0 milestone Feb 24, 2021
@lcobucci
Copy link
Member Author

We can compare the speed improvements on the build too: a previous run took 1m31s while this one took 41s.

@lcobucci
Copy link
Member Author

I just noticed that we don't have the branch 1.10.x and since this isn't a bug fix it shouldn't be merged to 1.9.x. I'll convert it into a draft for now - to avoid accidental merges.

@lcobucci lcobucci marked this pull request as draft February 24, 2021 22:56
Dockerfile Outdated Show resolved Hide resolved
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I just need to do the branching ballet to get this released then :-)

Dockerfile Outdated Show resolved Hide resolved
We only need to dump the autoloader at this stage, so it's unnecessary
to do anything beyond that.

Signed-off-by: Luís Cobucci <lcobucci@gmail.com>
BuildKit is an optimised builder for docker.

Although it isn't enabled by default, it helps to speed up the process
even more and it's quite stable at this point.

More info: https://docs.docker.com/develop/develop-images/build_enhancements/

Signed-off-by: Luís Cobucci <lcobucci@gmail.com>
@Ocramius Ocramius changed the base branch from 1.9.x to 1.10.x February 25, 2021 11:48
@Ocramius Ocramius marked this pull request as ready for review February 25, 2021 11:48
@@ -18,4 +18,4 @@ jobs:
uses: "actions/checkout@v2"

- name: "Docker Build"
run: "docker build ."
run: "DOCKER_BUILDKIT=1 docker build ."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUILDKIT FTW 💪

@Ocramius Ocramius self-assigned this Feb 25, 2021
@Ocramius
Copy link
Member

Branching fixed: 🚢

@Ocramius Ocramius merged commit e1f0863 into laminas:1.10.x Feb 25, 2021
@lcobucci
Copy link
Member Author

Thanks @Ocramius

@lcobucci lcobucci deleted the reduce-image-size branch February 25, 2021 11:53
@weierophinney
Copy link
Member

I CANNOT WAIT for my next release to see the speed improvements!

@Ocramius
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants