Improve Dockerfile
- Cross-compilation support (amd64 + arm64) - Use cargo build cache - Add opencontainers labels
This commit is contained in:
parent
c81a863e69
commit
c743af20a8
2 changed files with 39 additions and 10 deletions
4
.dockerignore
Normal file
4
.dockerignore
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
scripts
|
||||||
|
.github
|
||||||
|
.editorconfig
|
||||||
|
.pre-commit-hooks.yaml
|
||||||
45
Dockerfile
45
Dockerfile
|
|
@ -1,20 +1,45 @@
|
||||||
FROM rust:alpine as base
|
# syntax=docker/dockerfile:1
|
||||||
|
FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx
|
||||||
|
|
||||||
COPY . /src
|
FROM --platform=$BUILDPLATFORM rust:1.74-alpine AS base
|
||||||
|
|
||||||
RUN rustup update 1.74 && rustup default 1.74
|
RUN apk update && \
|
||||||
|
apk add \
|
||||||
RUN apk update \
|
|
||||||
&& apk add \
|
|
||||||
gcc \
|
gcc \
|
||||||
g++
|
g++ \
|
||||||
|
clang
|
||||||
|
|
||||||
RUN cd /src && cargo build --release
|
COPY --from=xx / /
|
||||||
|
|
||||||
FROM alpine as tool
|
ARG TARGETPLATFORM
|
||||||
|
RUN xx-info env
|
||||||
|
|
||||||
COPY --from=base /src/target/release/oxipng /usr/local/bin
|
RUN xx-apk add \
|
||||||
|
gcc \
|
||||||
|
musl-dev \
|
||||||
|
libdeflate
|
||||||
|
|
||||||
WORKDIR /src
|
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 alpine 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
|
||||||
|
|
||||||
|
WORKDIR /work
|
||||||
ENTRYPOINT [ "oxipng" ]
|
ENTRYPOINT [ "oxipng" ]
|
||||||
CMD [ "--help" ]
|
CMD [ "--help" ]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue