Following https://github.com/shssoichiro/oxipng/pull/642 - [x] Fail to build on linting errors - [x] Switch Docker image from `alpine` to `scratch` Reduce the image size roughly from 15Mb to 2Mb.  It doesn't break the usecase mentioned in the README, as well as people copying the binary in a Docker step. I have considered making the image rootless but since it's doing file modifications it requires overwriting the user to bring back root in the README's usecase. The image would benefit of if using it only with stdin/stdout. Not sure it's worth it. I have been working on enabling cross compilation for non-Tier 1 platforms, but no ETA yet.
46 lines
1.2 KiB
Docker
46 lines
1.2 KiB
Docker
# syntax=docker/dockerfile:1
|
|
# check=error=true
|
|
FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx
|
|
|
|
FROM --platform=$BUILDPLATFORM rust:1.74-alpine AS base
|
|
|
|
RUN apk update && \
|
|
apk add \
|
|
gcc \
|
|
g++ \
|
|
clang
|
|
|
|
COPY --from=xx / /
|
|
|
|
ARG TARGETPLATFORM
|
|
RUN xx-info env
|
|
|
|
RUN xx-apk add \
|
|
gcc \
|
|
musl-dev \
|
|
libdeflate
|
|
|
|
WORKDIR /src
|
|
|
|
COPY . .
|
|
|
|
RUN --mount=type=cache,target=/root/.cargo/git/db \
|
|
--mount=type=cache,target=/root/.cargo/registry/cache \
|
|
--mount=type=cache,target=/root/.cargo/registry/index \
|
|
xx-cargo build --release && \
|
|
xx-verify /src/target/$(xx-cargo --print-target-triple)/release/oxipng && \
|
|
cp /src/target/$(xx-cargo --print-target-triple)/release/oxipng /src/target/oxipng
|
|
|
|
FROM scratch AS tool
|
|
|
|
LABEL org.opencontainers.image.title="Oxipng"
|
|
LABEL org.opencontainers.image.description="Multithreaded PNG optimizer written in Rust"
|
|
LABEL org.opencontainers.image.authors="Joshua Holmer <jholmer.in@gmail.com>"
|
|
LABEL org.opencontainers.image.licenses="MIT"
|
|
LABEL org.opencontainers.image.source="https://github.com/shssoichiro/oxipng"
|
|
|
|
COPY --from=base /src/target/oxipng /usr/local/bin/oxipng
|
|
|
|
WORKDIR /work
|
|
ENTRYPOINT [ "oxipng" ]
|
|
CMD [ "--help" ]
|