-
Notifications
You must be signed in to change notification settings - Fork 6
Improve layer reuse of python images #39
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
Merged
hc2p
merged 6 commits into
main
from
hannes/pla-3118-improve-layer-reuse-of-python-images
Nov 18, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
259c852
Use matrix parameters to simplify job definition
hc2p dcd4861
Remove not needed Dockerfile
hc2p cf6c086
Make more layers of python image reusable
hc2p bb91be7
Ensure images are for amd64 only
hc2p 0d17795
Add missing ca-certificates
hc2p 12228e4
Centralize python-version list
hc2p File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| FROM debian:bullseye-slim | ||
| ENV DEBIAN_FRONTEND noninteractive | ||
|
|
||
| # Install OS dependencies | ||
| RUN apt-get update && apt-get -yq dist-upgrade \ | ||
| && apt-get install -yq --no-install-recommends \ | ||
| build-essential \ | ||
| bzip2 \ | ||
| cmake \ | ||
| curl \ | ||
| git \ | ||
| graphviz \ | ||
| libgtk2.0-dev \ | ||
| locales \ | ||
| sudo \ | ||
| unzip \ | ||
| vim \ | ||
| wget \ | ||
| ssh \ | ||
| gnupg2 \ | ||
| ca-certificates \ | ||
| && apt-get clean \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| ENV SHELL=/bin/bash \ | ||
| LC_ALL=en_US.UTF-8 \ | ||
| LANG=en_US.UTF-8 \ | ||
| LANGUAGE=en_US.UTF-8 \ | ||
| DEEPNOTE_PYTHON_KERNEL_ONLY=true | ||
|
|
||
| RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \ | ||
| locale-gen |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| ARG CIRCLE_PULL_REQUEST | ||
| FROM debian:bullseye-slim AS builder | ||
|
|
||
| # Install dependencies for building Python | ||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| wget \ | ||
| cmake \ | ||
| build-essential \ | ||
| libssl-dev \ | ||
| zlib1g-dev \ | ||
| libncurses5-dev \ | ||
| libncursesw5-dev \ | ||
| libreadline-dev \ | ||
| libsqlite3-dev \ | ||
| libgdbm-dev \ | ||
| libdb5.3-dev \ | ||
| libbz2-dev \ | ||
| libexpat1-dev \ | ||
| liblzma-dev \ | ||
| tk-dev \ | ||
| libffi-dev \ | ||
| uuid-dev \ | ||
| ca-certificates \ | ||
| && apt-get clean \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Download and extract the Python source code | ||
| WORKDIR /tmp | ||
| ARG PYTHON_VERSION_PATCH | ||
| RUN wget -qO- "https://www.python.org/ftp/python/${PYTHON_VERSION_PATCH}/Python-${PYTHON_VERSION_PATCH}.tgz" | tar xvz \ | ||
| && cd "/tmp/Python-${PYTHON_VERSION_PATCH}" \ | ||
| && ./configure --enable-optimizations --with-ensurepip=install \ | ||
| && make -j "$(nproc)" \ | ||
| && make altinstall | ||
|
|
||
|
|
||
| FROM deepnote/python:base${CIRCLE_PULL_REQUEST:+-ra-${CIRCLE_PULL_REQUEST##*/}} | ||
| # Copy Python from the builder stage | ||
| ARG PYTHON_VERSION | ||
| # Layers will be different between python versions from here onwards because of the build-arg | ||
|
|
||
| COPY --from=builder "/usr/local/bin/python${PYTHON_VERSION}" "/usr/local/bin/python${PYTHON_VERSION}" | ||
| COPY --from=builder "/usr/local/bin/pip${PYTHON_VERSION}" "/usr/local/bin/pip${PYTHON_VERSION}" | ||
| COPY --from=builder "/usr/local/lib/python${PYTHON_VERSION}" "/usr/local/lib/python${PYTHON_VERSION}" | ||
|
|
||
| RUN update-alternatives --install /usr/bin/python python "/usr/local/bin/python${PYTHON_VERSION}" 1 | ||
| RUN update-alternatives --install /usr/bin/pip pip "/usr/local/bin/pip${PYTHON_VERSION}" 1 | ||
|
|
||
| # We create the virtual environment in the home directory in the Dockerfile | ||
| # for performance improvement. | ||
| RUN python -m venv --system-site-packages ~/venv | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is somehow copied from official Python because I'm not sure if it is the recommended way or not.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am just afraid about some side effects that could not be transferred from the first stage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if you are sure that it is fine, I'm okay with that. It's working, so I think we are good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's basically just for symlinking python and pip binaries.
Official python is doing it differently, which we can of course adapt to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's discuss this. I think I don't understand how this can work.