diff --git a/Dockerfile.migrate b/Dockerfile.migrate index 77194b5..5158398 100644 --- a/Dockerfile.migrate +++ b/Dockerfile.migrate @@ -2,8 +2,11 @@ FROM registry.nxtgauge.com/rust:alpine AS builder WORKDIR /app -RUN command -v cargo >/dev/null 2>&1 || apk add --no-cache cargo rust -RUN apk add --no-cache musl-dev pkgconfig openssl-dev +RUN apk add --no-cache curl ca-certificates bash build-base 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 COPY Cargo.toml Cargo.lock ./ COPY crates/db-migrate ./crates/db-migrate @@ -12,12 +15,14 @@ COPY crates/cache ./crates/cache COPY crates/email ./crates/email 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 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 ENTRYPOINT ["db-migrate"] diff --git a/Dockerfile.simple b/Dockerfile.simple index 6ce24ae..aba206f 100644 --- a/Dockerfile.simple +++ b/Dockerfile.simple @@ -6,9 +6,12 @@ ARG SERVICE_NAME FROM registry.nxtgauge.com/rust:alpine AS builder ARG SERVICE_NAME -# Install deps -RUN command -v cargo >/dev/null 2>&1 || apk add --no-cache cargo rust -RUN apk add --no-cache musl-dev pkgconfig openssl-dev openssl-libs-static +# Install build deps + rust toolchain (Alpine-packaged Rust lacks proc-macro support) +RUN apk add --no-cache curl ca-certificates bash build-base 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 @@ -46,8 +49,9 @@ ENV RUSTFLAGS="-C target-feature=+crt-static -C link-arg=-s" ENV OPENSSL_STATIC=1 ENV OPENSSL_DIR=/usr RUN cargo build --release \ - --bin $(cat /tmp/service_bin) && \ - cp /app/target/release/$(cat /tmp/service_bin) /app/service + --bin $(cat /tmp/service_bin) \ + --target x86_64-unknown-linux-musl && \ + cp /app/target/x86_64-unknown-linux-musl/release/$(cat /tmp/service_bin) /app/service # Runtime FROM scratch