1 FROM rust:1.67.0-alpine as builder
3 # Install build dependencies
4 RUN apk add --no-cache git openssl-dev libpq-dev musl-dev
6 # Set the working directory to /app and copy the source code
10 # Set cargo build target (can be changed using --build-arg)
11 ARG CARGO_BUILD_TARGET="x86_64-unknown-linux-musl"
12 # Set the release mode (can be changed using --build-arg)
13 ARG RUST_RELEASE_MODE="debug"
16 RUN --mount=type=cache,target=/app/target \
17 if [ "$RUST_RELEASE_MODE" = "debug" ]; then \
18 echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" \
19 && rustup target add ${CARGO_BUILD_TARGET} \
20 && cargo build --target ${CARGO_BUILD_TARGET} \
21 && cp ./target/${CARGO_BUILD_TARGET}/${RUST_RELEASE_MODE}/lemmy_server /app/lemmy_server; \
26 if [ "$RUST_RELEASE_MODE" = "release" ]; then \
27 rustup target add ${CARGO_BUILD_TARGET} \
28 && cargo build --target ${CARGO_BUILD_TARGET} --release \
29 && cp ./target/${CARGO_BUILD_TARGET}/${RUST_RELEASE_MODE}/lemmy_server /app/lemmy_server; \
33 FROM alpine:3 as lemmy
35 # Install libpq for Postgres
36 RUN apk add --no-cache ca-certificates libpq
39 COPY --from=builder /app/lemmy_server /app/lemmy