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 ``` 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: * Test arm version: Anyone working on an aarch64 linux machine? I don't see this failing or a high-priority deployment (the vast majority of linux users is on x86), but it would be nice to have it tested one. --------- Co-authored-by: Zanie Blue <contact@zanie.dev>
36 lines
1.1 KiB
Docker
36 lines
1.1 KiB
Docker
FROM --platform=$BUILDPLATFORM ubuntu as build
|
|
ENV HOME="/root"
|
|
WORKDIR $HOME
|
|
|
|
RUN apt update && apt install -y build-essential curl python3-venv
|
|
|
|
# Setup zig as cross compiling linker
|
|
RUN python3 -m venv $HOME/.venv
|
|
RUN .venv/bin/pip install cargo-zigbuild
|
|
ENV PATH="$HOME/.venv/bin:$PATH"
|
|
|
|
# Install rust
|
|
ARG TARGETPLATFORM
|
|
RUN case "$TARGETPLATFORM" in \
|
|
"linux/arm64") echo "aarch64-unknown-linux-musl" > rust_target.txt ;; \
|
|
"linux/amd64") echo "x86_64-unknown-linux-musl" > rust_target.txt ;; \
|
|
*) exit 1 ;; \
|
|
esac
|
|
# TODO: --default-toolchain none and use rust-toolchain.toml instead
|
|
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --target $(cat rust_target.txt) --profile minimal
|
|
ENV PATH="$HOME/.cargo/bin:$PATH"
|
|
|
|
# Build
|
|
COPY crates crates
|
|
COPY Cargo.toml Cargo.toml
|
|
COPY Cargo.lock Cargo.lock
|
|
RUN cargo zigbuild --bin ruff --target $(cat rust_target.txt) --release
|
|
RUN cp target/$(cat rust_target.txt)/release/ruff /ruff
|
|
# TODO: Optimize binary size, with a version that also works when cross compiling
|
|
# RUN strip --strip-all /ruff
|
|
|
|
FROM scratch
|
|
COPY --from=build /ruff /ruff
|
|
WORKDIR /io
|
|
ENTRYPOINT ["/ruff"]
|