ci: use rustup toolchain for musl builds

This commit is contained in:
Tracewebstudio Dev 2026-04-17 03:10:14 +02:00
parent 3b27ddf356
commit b18aca10d3
2 changed files with 18 additions and 9 deletions

View file

@ -2,8 +2,11 @@ FROM registry.nxtgauge.com/rust:alpine AS builder
WORKDIR /app WORKDIR /app
RUN command -v cargo >/dev/null 2>&1 || apk add --no-cache cargo rust RUN apk add --no-cache curl ca-certificates bash build-base musl-dev pkgconfig openssl-dev openssl-libs-static
RUN apk add --no-cache musl-dev pkgconfig openssl-dev RUN update-ca-certificates
RUN curl -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable
ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup target add x86_64-unknown-linux-musl
COPY Cargo.toml Cargo.lock ./ COPY Cargo.toml Cargo.lock ./
COPY crates/db-migrate ./crates/db-migrate COPY crates/db-migrate ./crates/db-migrate
@ -12,12 +15,14 @@ COPY crates/cache ./crates/cache
COPY crates/email ./crates/email COPY crates/email ./crates/email
WORKDIR /app/crates/db-migrate WORKDIR /app/crates/db-migrate
RUN cargo build --release --bin db-migrate ENV OPENSSL_STATIC=1
ENV OPENSSL_DIR=/usr
RUN cargo build --release --bin db-migrate --target x86_64-unknown-linux-musl
FROM alpine:3.19 FROM alpine:3.19
RUN apk add --no-cache ca-certificates libpq RUN apk add --no-cache ca-certificates libpq
COPY --from=builder /app/crates/db-migrate/target/release/db-migrate /usr/local/bin/ COPY --from=builder /app/crates/db-migrate/target/x86_64-unknown-linux-musl/release/db-migrate /usr/local/bin/
COPY crates/db/migrations /migrations COPY crates/db/migrations /migrations
ENTRYPOINT ["db-migrate"] ENTRYPOINT ["db-migrate"]

View file

@ -6,9 +6,12 @@ ARG SERVICE_NAME
FROM registry.nxtgauge.com/rust:alpine AS builder FROM registry.nxtgauge.com/rust:alpine AS builder
ARG SERVICE_NAME ARG SERVICE_NAME
# Install deps # Install build deps + rust toolchain (Alpine-packaged Rust lacks proc-macro support)
RUN command -v cargo >/dev/null 2>&1 || apk add --no-cache cargo rust RUN apk add --no-cache curl ca-certificates bash build-base musl-dev pkgconfig openssl-dev openssl-libs-static
RUN apk add --no-cache musl-dev pkgconfig openssl-dev openssl-libs-static RUN update-ca-certificates
RUN curl -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable
ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup target add x86_64-unknown-linux-musl
WORKDIR /app WORKDIR /app
@ -46,8 +49,9 @@ ENV RUSTFLAGS="-C target-feature=+crt-static -C link-arg=-s"
ENV OPENSSL_STATIC=1 ENV OPENSSL_STATIC=1
ENV OPENSSL_DIR=/usr ENV OPENSSL_DIR=/usr
RUN cargo build --release \ RUN cargo build --release \
--bin $(cat /tmp/service_bin) && \ --bin $(cat /tmp/service_bin) \
cp /app/target/release/$(cat /tmp/service_bin) /app/service --target x86_64-unknown-linux-musl && \
cp /app/target/x86_64-unknown-linux-musl/release/$(cat /tmp/service_bin) /app/service
# Runtime # Runtime
FROM scratch FROM scratch