-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add a ruff docker image at ghcr.io/astral-sh/ruff #8554
Conversation
Here's an example of a CI workflow https://github.com/PrefectHQ/prefect/blob/main/.github/workflows/docker-images.yaml — the matrix is of course not necessary for us. It'd be nice to submit an addition to the DockerHub official image collection, but to start I don't have a strong preference on DockerHub vs ghcr.io. |
This is great! I was able to build it for |
Actually, the arm64 build failed with this error:
|
Made the multiarch build work for x86_64 and aarch64, do we need other architectures too? The build works by cross compiling, so we avoid QEMU. |
CodSpeed Performance ReportMerging #8554 will not alter performanceComparing Summary
|
This dockerfile creates a minimal docker container that runs ruff ```console $ docker run -v .:/io --rm ruff check --select G004 . scripts/check_ecosystem.py:51:26: G004 Logging statement uses f-string scripts/check_ecosystem.py:55:22: G004 Logging statement uses f-string scripts/check_ecosystem.py:84:13: G004 Logging statement uses f-string scripts/check_ecosystem.py:177:18: G004 Logging statement uses f-string scripts/check_ecosystem.py:200:18: G004 Logging statement uses f-string scripts/check_ecosystem.py:354:18: G004 Logging statement uses f-string scripts/check_ecosystem.py:477:18: G004 Logging statement uses f-string Found 7 errors. ``` ```console $ docker image ls ruff REPOSITORY TAG IMAGE ID CREATED SIZE ruff latest 505876b0f817 2 minutes ago 16.2MB ``` TODO: * Multi arch (never done this before) * CI integration * Where do we want to host this, ghcr.io?
Co-authored-by: Zanie Blue <contact@zanie.dev>
01e3056
to
caa1585
Compare
Added a github actions integration, this is ready |
ENV HOME="/root" | ||
WORKDIR $HOME | ||
|
||
RUN apt update && apt install -y build-essential curl python3-venv |
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.
Probably still good to follow best practice to use apt-get
, clean the cache, not install recommends.
Even if it's not in the production images, reducing the size of the cached layers is important.
RUN python3 -m venv $HOME/.venv | ||
RUN .venv/bin/pip install cargo-zigbuild |
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.
Hello @konstin , I was just looking through ruff
commit history and saw this PR.
One comment here is usually one just uses system Python in a Docker container, mainly cuz Docker containers are short-lived objects already.
I wanted to suggest a nice Dockerfile
linter hadolint that has a lot of good suggestions:
- Using
pip install --no-cache-dir
to minimize image size - Using
apt-get
overapt
and removing the apt cache when done
Here is a sample pre-commit
integration:
- repo: https://github.com/hadolint/hadolint
rev: v2.12.1-beta
hooks:
- id: hadolint-docker
Feel free to disregard this as well, just sharing for reference. Cheers!
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.
One comment here is usually one just uses system Python in a Docker container, mainly cuz Docker containers are short-lived objects already.
I have bad experiences with user packages colliding with system packages, so i won't support that. As pip install cargo-zigbuild
in the system environment will tell you: "Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv"
Using pip install --no-cache-dir to minimize image size
This is a multi-stage docker build, the builder does not affect the final image size. As shown in the PR description, the total is 16.2MB, which is the size of the x86_64-unknown-linux-musl release binary.
Using apt-get over apt and removing the apt cache when done
The apt
interface is stable nowadays and the same as for the pip cache applies here.
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.
Alright sounds good! The multi-stage build you set up here is pretty clever, nice work there
I don't think this image is public accessible, because I can't find the image on the registry of this repo and |
Sorry, it's public now: https://github.com/astral-sh/ruff/pkgs/container/ruff |
This dockerfile creates a minimal docker container that runs ruff
Test repo: https://github.com/konstin/release-testing2
Successful build: https://github.com/konstin/release-testing2/actions/runs/6862107104/job/18659155108
The package: https://github.com/konstin/release-testing2/pkgs/container/release-testing2
After merging this, i have to manually push the first image and connect it the repo in the github UI or the action will fail due to lack of permissions
Open questions: