lemmy/docker/Dockerfile
Dessalines 993489a80f
Combine prod and dev docker setups using build-arg (#2739)
* Combine prod and dev docker setups using build-arg

- Fixes #2603

* Dont use cache for release build.
2023-02-17 15:29:45 +09:00

38 lines
1,009 B
Docker

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