2023-06-22 07:46:07 -04:00
|
|
|
FROM clux/muslrust:1.70.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
|
|
|
|
2023-07-05 07:25:19 -04:00
|
|
|
# comma-seperated list of features to enable
|
|
|
|
ARG CARGO_BUILD_FEATURES=default
|
|
|
|
|
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" \
|
2023-07-05 07:25:19 -04:00
|
|
|
&& cargo build --target ${CARGO_BUILD_TARGET} --features ${CARGO_BUILD_FEATURES} \
|
2023-04-25 16:40:58 -04:00
|
|
|
&& 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 \
|
2023-06-21 15:46:32 -04:00
|
|
|
echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" \
|
2023-07-05 07:25:19 -04:00
|
|
|
&& cargo build --target ${CARGO_BUILD_TARGET} --features ${CARGO_BUILD_FEATURES} --release \
|
2023-04-25 16:40:58 -04:00
|
|
|
&& 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
|
2023-06-26 05:59:02 -04:00
|
|
|
RUN apk add --no-cache libpq
|
2023-02-17 01:29:45 -05:00
|
|
|
|
|
|
|
# Copy resources
|
|
|
|
COPY --from=builder /app/lemmy_server /app/lemmy
|
|
|
|
|
|
|
|
CMD ["/app/lemmy"]
|