Stop building arm 32bit images & better cache in docker image
This commit is contained in:
57
Dockerfile
57
Dockerfile
@@ -1,3 +1,5 @@
|
|||||||
|
# syntax = docker/dockerfile:1.3
|
||||||
|
|
||||||
# Builds a minimal image with the binary only. It is multi-arch capable,
|
# Builds a minimal image with the binary only. It is multi-arch capable,
|
||||||
# cross-building to aarch64 and x86_64. When cross-compiling, Docker sets two
|
# cross-building to aarch64 and x86_64. When cross-compiling, Docker sets two
|
||||||
# implicit BUILDARG: BUILDPLATFORM being the host platform and TARGETPLATFORM
|
# implicit BUILDARG: BUILDPLATFORM being the host platform and TARGETPLATFORM
|
||||||
@@ -29,55 +31,47 @@ RUN find public -type f -exec touch -t 197001010000.00 {} +
|
|||||||
# The image Debian base name (bullseye) must be in sync with the runtime variant (debian11)
|
# The image Debian base name (bullseye) must be in sync with the runtime variant (debian11)
|
||||||
FROM --platform=${BUILDPLATFORM} docker.io/library/rust:${RUSTC_VERSION}-slim-${DEBIAN_VERSION_NAME} AS chef
|
FROM --platform=${BUILDPLATFORM} docker.io/library/rust:${RUSTC_VERSION}-slim-${DEBIAN_VERSION_NAME} AS chef
|
||||||
|
|
||||||
# Install x86_64, aarch64 and arm (v6 and v7) cross-compiling stack
|
# Install x86_64 and aarch64 cross-compiling stack
|
||||||
RUN apt update && apt install -y --no-install-recommends \
|
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
|
||||||
g++-x86-64-linux-gnu \
|
RUN \
|
||||||
|
--mount=type=cache,target=/var/cache/apt \
|
||||||
|
--mount=type=cache,target=/var/lib/apt \
|
||||||
|
apt update && apt install -y --no-install-recommends \
|
||||||
g++-aarch64-linux-gnu \
|
g++-aarch64-linux-gnu \
|
||||||
g++-arm-linux-gnueabihf \
|
g++-x86-64-linux-gnu \
|
||||||
libc6-dev-arm64-cross \
|
libc6-dev-arm64-cross \
|
||||||
libc6-dev-amd64-cross \
|
libc6-dev-amd64-cross
|
||||||
libc6-dev-armhf-cross \
|
|
||||||
qemu-user \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN cargo install --locked cargo-chef
|
RUN \
|
||||||
|
--mount=type=cache,target=/usr/local/cargo/registry \
|
||||||
|
cargo install --locked cargo-chef
|
||||||
|
|
||||||
ENV \
|
ENV \
|
||||||
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc \
|
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc \
|
||||||
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="qemu-x86_64 -L /usr/x86_64-linux-gnu" \
|
|
||||||
CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc \
|
CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc \
|
||||||
CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++ \
|
CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++ \
|
||||||
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
|
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
|
||||||
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="qemu-aarch64 -L /usr/aarch64-linux-gnu" \
|
|
||||||
CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \
|
CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \
|
||||||
CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ \
|
CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++
|
||||||
CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \
|
|
||||||
CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_RUNNER="qemu-arm -L /usr/arm-linux-gnueabihf" \
|
|
||||||
CC_arm_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \
|
|
||||||
CXX_arm_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ \
|
|
||||||
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \
|
|
||||||
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER="qemu-arm -L /usr/arm-linux-gnueabihf" \
|
|
||||||
CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \
|
|
||||||
CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++
|
|
||||||
|
|
||||||
ARG RUSTC_VERSION
|
ARG RUSTC_VERSION
|
||||||
ARG TARGETPLATFORM
|
|
||||||
|
|
||||||
# Install all cross-compilation targets
|
# Install all cross-compilation targets
|
||||||
RUN rustup target add --toolchain "${RUSTC_VERSION}" \
|
RUN rustup target add --toolchain "${RUSTC_VERSION}" \
|
||||||
x86_64-unknown-linux-gnu \
|
x86_64-unknown-linux-gnu \
|
||||||
aarch64-unknown-linux-gnu \
|
aarch64-unknown-linux-gnu
|
||||||
arm-unknown-linux-gnueabihf \
|
|
||||||
armv7-unknown-linux-gnueabihf
|
|
||||||
|
|
||||||
# Helper script that transforms docker platforms to LLVM triples
|
# Helper script that transforms docker platforms to LLVM triples
|
||||||
COPY ./misc/docker-arch-to-rust-target.sh /
|
COPY ./misc/docker-arch-to-rust-target.sh /
|
||||||
|
|
||||||
## Run the planner from cargo-chef ##
|
## Run the planner from cargo-chef ##
|
||||||
FROM --platform=${BUILDPLATFORM} chef AS planner
|
FROM --platform=${BUILDPLATFORM} chef AS planner
|
||||||
COPY . .
|
COPY ./Cargo.toml ./Cargo.lock /app/
|
||||||
RUN cargo chef prepare --recipe-path recipe.json
|
COPY ./crates /app/crates
|
||||||
|
RUN \
|
||||||
|
--mount=type=cache,target=/usr/local/cargo/registry \
|
||||||
|
cargo chef prepare --recipe-path recipe.json
|
||||||
|
|
||||||
## Actual build stage ##
|
## Actual build stage ##
|
||||||
FROM --platform=${BUILDPLATFORM} chef AS builder
|
FROM --platform=${BUILDPLATFORM} chef AS builder
|
||||||
@@ -86,17 +80,22 @@ ARG TARGETPLATFORM
|
|||||||
|
|
||||||
# Build dependencies
|
# Build dependencies
|
||||||
COPY --from=planner /app/recipe.json recipe.json
|
COPY --from=planner /app/recipe.json recipe.json
|
||||||
RUN cargo chef cook \
|
RUN \
|
||||||
|
--mount=type=cache,target=/usr/local/cargo/registry \
|
||||||
|
cargo chef cook \
|
||||||
--release \
|
--release \
|
||||||
--recipe-path recipe.json \
|
--recipe-path recipe.json \
|
||||||
--target $(/docker-arch-to-rust-target.sh "${TARGETPLATFORM}") \
|
--target $(/docker-arch-to-rust-target.sh "${TARGETPLATFORM}") \
|
||||||
--package mas-cli
|
--package mas-cli
|
||||||
|
|
||||||
# Build the rest
|
# Build the rest
|
||||||
COPY . .
|
COPY ./Cargo.toml ./Cargo.lock /app/
|
||||||
|
COPY ./crates /app/crates
|
||||||
COPY --from=static-files /app/crates/static-files/public /app/crates/static-files/public
|
COPY --from=static-files /app/crates/static-files/public /app/crates/static-files/public
|
||||||
ENV SQLX_OFFLINE=true
|
ENV SQLX_OFFLINE=true
|
||||||
RUN cargo build \
|
RUN \
|
||||||
|
--mount=type=cache,target=/usr/local/cargo/registry \
|
||||||
|
cargo build \
|
||||||
--release \
|
--release \
|
||||||
--bin mas-cli \
|
--bin mas-cli \
|
||||||
--target $(/docker-arch-to-rust-target.sh "${TARGETPLATFORM}")
|
--target $(/docker-arch-to-rust-target.sh "${TARGETPLATFORM}")
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ target "base" {
|
|||||||
platforms = [
|
platforms = [
|
||||||
"linux/amd64",
|
"linux/amd64",
|
||||||
"linux/arm64",
|
"linux/arm64",
|
||||||
"linux/arm",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user