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

Further reduce the size of the docker image #3972

Merged
merged 4 commits into from Oct 1, 2018

Conversation

Projects
None yet
3 participants
@richvdh
Member

richvdh commented Sep 27, 2018

  • get rid of the pip wheel cache
  • get rid of /synapse (everything we need ends up in /usr/local/lib/python2.7/site-packages

richvdh added some commits Sep 27, 2018

Further reduce the size of the docker image
* get rid of the pip wheel cache
* get rid of /synapse (everything we need ends up in
  /usr/local/lib/python2.7/site-packages
@richvdh

This comment has been minimized.

Member

richvdh commented Sep 27, 2018

This is all very well, but we end up with an image which is built on top of a layer which adds /synapse, and then we remove /synapse in the final layer. Is there a way to avoid the redundant layer?

@richvdh richvdh requested a review from michaelkaye Sep 27, 2018

@michaelkaye

This comment has been minimized.

Contributor

michaelkaye commented Sep 27, 2018

You can do it with the builder container pattern : https://docs.docker.com/develop/develop-images/multistage-build/

That way you build synapse then throw away the container(s) you built it in and just copy the required bits into a new container - it makes it a little easier than having that one multi-line RUN command to try to make a single image.

@michaelkaye

So - we can deploy this for a slight gain, if we remove the "rm -rf /synapse" as that's not doing anything useful to the size

Doing it properly will be about using the multi-stage builder to:

FROM python-alpine...
RUN apk install runtime_deps 
RUN apk install build_deps # seperate layers, because we can re-use the layer with just the runtime deps below, speeding up builds I think.

pip install to /target/ # somehow, how do you do that in python
other bits here

FROM python-alpine
RUN apk install runtime_deps # this is ok as a separate layer
COPY --from = 0 /target

Then i think we get to re-use layers where we want them - runtime dependencies, and build dependencies, without affecting the end image size.

setup.cfg \
setup.py \
synapse \
&& rm -rf /synapse \

This comment has been minimized.

@michaelkaye

michaelkaye Sep 27, 2018

Contributor

If we remove this line then this will reduce the size a little without doing deletes that aren't worthwhile.

Rewrite the dockerfile as a multistage build
This means we can get rid of a whole load of cruft which we don't need.
@richvdh

This comment has been minimized.

Member

richvdh commented Sep 27, 2018

well, in for a penny, in for a pound. A semi-interesting exercise in learning how dockerfiles work.

@richvdh richvdh requested a review from michaelkaye Sep 27, 2018

Show resolved Hide resolved docker/Dockerfile Outdated
Show resolved Hide resolved docker/Dockerfile Outdated
Show resolved Hide resolved docker/Dockerfile

@richvdh richvdh merged commit 53c5fa4 into develop Oct 1, 2018

6 checks passed

ci/circleci: sytestpy2merged Your tests passed on CircleCI!
Details
ci/circleci: sytestpy2postgresmerged Your tests passed on CircleCI!
Details
ci/circleci: sytestpy3merged Your tests passed on CircleCI!
Details
ci/circleci: sytestpy3postgresmerged Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@richvdh richvdh deleted the rav/reduce_docker_image_more branch Oct 1, 2018

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