Skip to content
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

Remove cross compilation from Dockerfile #3

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 7 additions & 58 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,78 +1,27 @@
# syntax=docker/dockerfile:1.4
FROM alpine:3.19 AS alpine
ARG TARGETPLATFORM

RUN \
--mount=type=cache,id=$TARGETPLATFORM-alpine,target=/var/cache/apk,sharing=locked \
set -eux; \
apk add -U libgcc;
ARG ALPINE_VERSION=3.19
ARG RUST_VERSION=1.75

################################################################################

FROM alpine AS alpine-dev
FROM rust:$RUST_VERSION-alpine$ALPINE_VERSION AS builder
ARG TARGETPLATFORM

RUN \
--mount=type=cache,id=$TARGETPLATFORM-alpine,target=/var/cache/apk,sharing=locked \
set -eux; \
apk add -U musl-dev;

################################################################################

FROM --platform=$BUILDPLATFORM rust:1 AS builder
ARG BUILDPLATFORM
ARG TARGETPLATFORM

RUN \
--mount=type=cache,id=$BUILDPLATFORM-debian,target=/var/cache,sharing=locked \
--mount=type=cache,id=$BUILDPLATFORM-debian,target=/var/lib/apt,sharing=locked \
set -eux; \
case "${TARGETPLATFORM}" in \
linux/i386) \
dpkgArch='i386'; \
;; \
linux/amd64) \
dpkgArch='amd64'; \
;; \
linux/arm64) \
dpkgArch='arm64'; \
;; \
*) echo "unsupported architecture"; exit 1 ;; \
esac; \
dpkg --add-architecture $dpkgArch; \
apt-get update; \
apt-get install -y --no-install-recommends \
musl-dev:$dpkgArch \
musl-tools:$dpkgArch \
;
apk add -U build-base;

WORKDIR /opt/aode-relay

RUN set -eux; \
case "${TARGETPLATFORM}" in \
linux/i386) arch='i686';; \
linux/amd64) arch='x86_64';; \
linux/arm64) arch='aarch64';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac; \
rustup target add "${arch}-unknown-linux-musl";

ADD Cargo.lock Cargo.toml /opt/aode-relay/
RUN cargo fetch;

ADD . /opt/aode-relay
COPY --link --from=alpine-dev / /opt/alpine/

RUN set -eux; \
case "${TARGETPLATFORM}" in \
linux/i386) arch='i686';; \
linux/amd64) arch='x86_64';; \
linux/arm64) arch='aarch64';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac; \
ln -s "target/${arch}-unknown-linux-musl/release/relay" "aode-relay"; \
export RUSTFLAGS="-C target-cpu=generic -C linker=${arch}-linux-musl-gcc -C target-feature=-crt-static -C link-self-contained=no -L /opt/alpine/lib -L /opt/alpine/usr/lib"; \
cargo build --frozen --release --target="${arch}-unknown-linux-musl";
export RUSTFLAGS="-C target-cpu=generic"; \
cargo build --frozen --release;

################################################################################

Expand All @@ -84,7 +33,7 @@ RUN \
set -eux; \
apk add -U ca-certificates curl tini;

COPY --link --from=builder /opt/aode-relay/aode-relay /usr/local/bin/aode-relay
COPY --link --from=builder /opt/aode-relay/target/release/relay /usr/local/bin/aode-relay

# Smoke test
RUN /usr/local/bin/aode-relay --help
Expand Down
Loading