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

docker image publishing #6

Merged
merged 3 commits into from
Sep 5, 2024
Merged

docker image publishing #6

merged 3 commits into from
Sep 5, 2024

Conversation

mjurbanski-reef
Copy link
Contributor

No description provided.

cookiecutter.json Outdated Show resolved Hide resolved
@@ -0,0 +1,34 @@
ARG PYTHON_VERSION=3.12
FROM python:${PYTHON_VERSION}-alpine AS builder

Choose a reason for hiding this comment

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

nitpick: I don't like using alpine variants of images, unless using static builds like go binaries (even then I prefer distroless images).

I had to deal with a lot of headaches due to some libraries sometimes not working under alpine. Though, I don't know the recent scene as I have not used alpine images for a long time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For actively developed project this is true, but for dockerized CLIs alpine is has additional benefits, since its twice as small, which is reflected in bootup speed. There is some argument for security as well (less security alerts due less of stuff included by default).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One thing worth noting, is project using this template can always replace this Dockerfile if for some reason alpine proves a non-starter. And then it could even be added as another option to cookiecutter if that becomes a common need.

Right now for two projects were I expect this dockerfile to be used alpine will do better.

Comment on lines 22 to 30
RUN pdm build -d /tmp/wheelhouse

RUN pip install --no-cache-dir -r /tmp/requirements.txt
RUN pip install --no-cache-dir /tmp/wheelhouse/*.whl

FROM python:${PYTHON_VERSION}-alpine

COPY --from=builder /usr/local/lib/python${PYTHON_VERSION%.*}/site-packages /usr/local/lib/python${PYTHON_VERSION%.*}/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin

Choose a reason for hiding this comment

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

Instead of copying the os level (in container) site-packages, I'd prefer to set-up a venv in the builder, install the dependencies there, copy the whole venv in the final stage. It keeps the app dependencies totally separate from container-global packages.

Copy link
Contributor Author

@mjurbanski-reef mjurbanski-reef Sep 5, 2024

Choose a reason for hiding this comment

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

there is no point of doing venv "container" inside already containerized system (there is no expectation of anything other than the installed app to be installed on it, so there are no extra "global" packages), it would also significantly increase the image size - which as mentioned in other comment - while not affecting typical apps much, for CLI is problematic

Copy link
Contributor Author

@mjurbanski-reef mjurbanski-reef Sep 5, 2024

Choose a reason for hiding this comment

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

I think right now we use venv in django cookiecutter, but AFAIK only reason for that is that we went and used pdm in different fashion than I did here, and it has no ability to work without venv other than using some rejected-PEP implementation. Also for django apps they are that heavy that we simply care much less about the extra megabytes added with venv.

Since this is targeted towards CLI, priorities are different.

with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64

Choose a reason for hiding this comment

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

question: doesn't multi-arch builds require qemu? The docs says:

If you want support for more platforms, you can use QEMU with the Docker Setup QEMU action.

But I couldn't find for which platforms you need qemu 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only thing I can say to that is that I tested this workflow and it correctly built images for these archs on default GHA runner

@mjurbanski-reef mjurbanski-reef merged commit ef29edd into master Sep 5, 2024
5 checks passed
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.

2 participants