2023-04-16 16:56:12 +00:00
|
|
|
FROM rust:1.67.0-alpine as builder
|
2023-02-17 06:29:45 +00:00
|
|
|
|
2023-04-16 16:56:12 +00:00
|
|
|
# Install build dependencies
|
|
|
|
RUN apk add --no-cache git openssl-dev libpq-dev musl-dev
|
2023-02-17 06:29:45 +00:00
|
|
|
|
2023-04-16 16:56:12 +00:00
|
|
|
# Set the working directory to /app and copy the source code
|
|
|
|
WORKDIR /app
|
2023-02-17 06:29:45 +00:00
|
|
|
COPY . .
|
|
|
|
|
2023-04-16 16:56:12 +00:00
|
|
|
# Set cargo build target (can be changed using --build-arg)
|
|
|
|
ARG CARGO_BUILD_TARGET="x86_64-unknown-linux-musl"
|
|
|
|
# Set the release mode (can be changed using --build-arg)
|
|
|
|
ARG RUST_RELEASE_MODE="debug"
|
|
|
|
|
2023-02-17 06:29:45 +00:00
|
|
|
# Debug mode build
|
|
|
|
RUN --mount=type=cache,target=/app/target \
|
2023-04-16 16:56:12 +00:00
|
|
|
if [ "$RUST_RELEASE_MODE" = "debug" ]; then \
|
2023-03-21 15:03:05 +00:00
|
|
|
echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" \
|
2023-04-16 16:56:12 +00:00
|
|
|
&& rustup target add ${CARGO_BUILD_TARGET} \
|
2023-03-21 15:03:05 +00:00
|
|
|
&& cargo build --target ${CARGO_BUILD_TARGET} \
|
2023-04-16 16:56:12 +00:00
|
|
|
&& 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-16 16:56:12 +00:00
|
|
|
if [ "$RUST_RELEASE_MODE" = "release" ]; then \
|
|
|
|
rustup target add ${CARGO_BUILD_TARGET} \
|
|
|
|
&& cargo build --target ${CARGO_BUILD_TARGET} --release \
|
|
|
|
&& cp ./target/${CARGO_BUILD_TARGET}/${RUST_RELEASE_MODE}/lemmy_server /app/lemmy_server; \
|
2023-02-17 06:29:45 +00:00
|
|
|
fi
|
|
|
|
|
2023-04-16 16:56:12 +00:00
|
|
|
# The Alpine runner
|
2023-02-17 06:29:45 +00:00
|
|
|
FROM alpine:3 as lemmy
|
|
|
|
|
2023-04-16 16:56:12 +00:00
|
|
|
# Install libpq for Postgres
|
|
|
|
RUN apk add --no-cache ca-certificates libpq
|
2023-02-17 06:29:45 +00:00
|
|
|
|
|
|
|
# Copy resources
|
|
|
|
COPY --from=builder /app/lemmy_server /app/lemmy
|
|
|
|
|
|
|
|
EXPOSE 8536
|
|
|
|
CMD ["/app/lemmy"]
|