1 ARG RUST_BUILDER_IMAGE=ekidd/rust-musl-builder:1.51.0
4 FROM $RUST_BUILDER_IMAGE as planner
6 RUN cargo install cargo-chef
11 RUN sudo chown -R rust:rust .
12 RUN cargo chef prepare --recipe-path recipe.json
14 # Cargo chef cache dependencies
15 FROM $RUST_BUILDER_IMAGE as cacher
16 ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
18 RUN cargo install cargo-chef
19 COPY --from=planner /app/recipe.json ./recipe.json
20 RUN sudo chown -R rust:rust .
21 RUN cargo chef cook --target ${CARGO_BUILD_TARGET} --recipe-path recipe.json
24 FROM $RUST_BUILDER_IMAGE as builder
26 ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
27 ARG RUSTRELEASEDIR="debug"
31 # Copy over the cached dependencies
32 COPY --from=cacher /app/target target
33 COPY --from=cacher /home/rust/.cargo /home/rust/.cargo
35 # Copy the rest of the dirs
38 RUN sudo chown -R rust:rust .
39 RUN echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs"
43 RUN strip ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server
45 RUN cp ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server /app/lemmy_server
48 FROM alpine:3 as lemmy
50 # Install libpq for postgres
53 RUN addgroup -g 1000 lemmy
54 RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy
57 COPY --chown=lemmy:lemmy --from=builder /app/lemmy_server /app/lemmy
59 RUN chown lemmy:lemmy /app/lemmy