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