2023-04-25 16:40:58 -04:00
|
|
|
FROM clux/muslrust:1.67.0 as builder
|
2023-04-16 12:56:12 -04:00
|
|
|
WORKDIR /app
|
2023-04-25 16:40:58 -04:00
|
|
|
ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
|
2023-04-18 16:21:31 -04:00
|
|
|
|
|
|
|
# This can be set to release using --build-arg
|
2023-04-16 12:56:12 -04:00
|
|
|
ARG RUST_RELEASE_MODE="debug"
|
|
|
|
|
2023-04-25 16:40:58 -04:00
|
|
|
COPY . .
|
2023-04-18 16:21:31 -04:00
|
|
|
|
2023-04-25 16:40:58 -04:00
|
|
|
# Build the project
|
|
|
|
|
2023-02-17 01:29:45 -05:00
|
|
|
# Debug mode build
|
|
|
|
RUN --mount=type=cache,target=/app/target \
|
2023-04-25 16:40:58 -04:00
|
|
|
if [ "$RUST_RELEASE_MODE" = "debug" ] ; then \
|
|
|
|
echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" \
|
|
|
|
&& cargo build --target ${CARGO_BUILD_TARGET} \
|
|
|
|
&& cp ./target/$CARGO_BUILD_TARGET/$RUST_RELEASE_MODE/lemmy_server /app/lemmy_server; \
|
2023-02-17 01:29:45 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Release mode build
|
|
|
|
RUN \
|
2023-04-25 16:40:58 -04:00
|
|
|
if [ "$RUST_RELEASE_MODE" = "release" ] ; then \
|
|
|
|
cargo build --target ${CARGO_BUILD_TARGET} --release \
|
|
|
|
&& cp ./target/$CARGO_BUILD_TARGET/$RUST_RELEASE_MODE/lemmy_server /app/lemmy_server; \
|
2023-02-17 01:29:45 -05:00
|
|
|
fi
|
|
|
|
|
2023-04-25 16:40:58 -04:00
|
|
|
# The alpine runner
|
2023-02-17 01:29:45 -05:00
|
|
|
FROM alpine:3 as lemmy
|
|
|
|
|
2023-04-25 16:40:58 -04:00
|
|
|
# Install libpq for postgres
|
|
|
|
RUN apk add libpq
|
2023-02-17 01:29:45 -05:00
|
|
|
|
|
|
|
# Copy resources
|
|
|
|
COPY --from=builder /app/lemmy_server /app/lemmy
|
|
|
|
|
|
|
|
CMD ["/app/lemmy"]
|