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

Refactoring multiple parts of the dockerfile #10004

Merged
merged 18 commits into from
Sep 8, 2021
Merged

Conversation

ewjoachim
Copy link
Contributor

@ewjoachim ewjoachim commented Sep 4, 2021

  • Switched to a 5-staged build:
    • Static, like before (but we now use it instead of Dockerfile.static)
    • Base which has apt deps and main env vars
    • Build with the build-time apt deps, which does the main pip install
    • Dev, which is the developper image (there's no DEVEL arg anymore)
    • App, which is to be the production image
  • Remove a lot of heavy & unused things from the docker context through .dockerignore
  • Add apt & pip cache, to speed up rebuilds and limit bandwith requirements (with no impact on layer size)
  • use set -eux; \ style instead of set -u \ && style
  • Address the todo that was in Dockerfile: add a lockfile for pip, setuptools & wheel
  • docker-compose uses python image directly for notdatadog & files, should be smaller on disk/memory

This is a good first step toward #9988

@ewdurbin I believe there might be implications on the deployment pipeline, though it might be nothing more than adding --target=app to the docker build. And even without that, I believe it would be the default.

@abitrolly
Copy link
Contributor

Should it be added into GitHub Actions pipeline? I am interested to see how the changes improve the build time.

@ewjoachim
Copy link
Contributor Author

ewjoachim commented Sep 7, 2021

I am interested to see how the changes improve the build time.

I'm not sure this would speed up CI a lot, because I doubt GitHub CI keeps --mount=type=cache between calls, this would be too dangerous because if users polluted the cache, it would be hard to recover.

For the rest, the layers here should roughly take as long as before, it's refactored for readability and ease of use.

In the end the operations we have are:

  • apt install run time deps
  • pip install run time deps
  • apt install build time deps
  • pip install dev
  • build statics
    and that's it. We had that before, we have this now, and it takes as long to run.

And even with a layer cache, it reduces bandwidth usage but from an human point of view, downloading 100ko with fiber or reading it from disk takes as long (0s).

Copy link
Member

@ewdurbin ewdurbin left a comment

Choose a reason for hiding this comment

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

This is really incredible work. Thank you @ewjoachim!

Our deployment pipeline doesn't currently have support for setting a target when building, but since the app ends up being default, that's not a problem!

# probably pin these too, and update them as we do anything else.
RUN pip --no-cache-dir --disable-pip-version-check install --upgrade pip setuptools wheel
# Pip configuration (https://github.com/pypa/warehouse/pull/4584)
ENV PIP_NO_BINARY=hiredis PIP_DISABLE_PIP_VERSION_CHECK=1
Copy link
Member

Choose a reason for hiding this comment

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

It completely escapes me why we do not use the binary releases for hiredis... but based on the date it seems to be related to redis/hiredis-py#69 (nice) which was seemingly only related to that 0.2.0 release.

Perhaps we should go back to using the wheels provided?

Copy link
Member

Choose a reason for hiding this comment

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

Will address in follow up PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@ewdurbin ewdurbin merged commit 6581b02 into pypi:main Sep 8, 2021
di added a commit to di/warehouse that referenced this pull request Sep 8, 2021
ewdurbin pushed a commit that referenced this pull request Sep 8, 2021
@ewjoachim ewjoachim deleted the dockerfile branch September 8, 2021 16:16
ewdurbin added a commit that referenced this pull request Sep 8, 2021
@ewjoachim ewjoachim mentioned this pull request Sep 13, 2021
domdfcoding pushed a commit to domdfcoding/warehouse that referenced this pull request Jun 7, 2022
* Remove the Dockerfile.static, replace with a --target

* Use APT cache

* Headers

* Switch to set -eux

* Add things to dockerignore

* Add lockfile for pip & the likes

* Add pip req alias files

* Improve APT cache

* Reorgnize apt deps

* Make dev image, use pip req aliases, and envvars

* Add base image to limit repetition

* docker-compose use dev images

* docker-compose use simple python images when possible

* Dev is not pinned, must be installed separately

* Remove unused DEVEL references

* Build static image first, though it's not used by the dev image

* Reorganize dev

Co-authored-by: Ee Durbin <[email protected]>
domdfcoding pushed a commit to domdfcoding/warehouse that referenced this pull request Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants