2021-11-09 22:16:59 +00:00
|
|
|
ARG RUST_BUILDER_IMAGE=clux/muslrust:1.56.0
|
2019-04-10 18:10:57 +00:00
|
|
|
|
2021-11-09 22:16:59 +00:00
|
|
|
FROM $RUST_BUILDER_IMAGE as chef
|
|
|
|
USER root
|
2021-02-24 22:10:28 +00:00
|
|
|
RUN cargo install cargo-chef
|
2021-11-09 22:16:59 +00:00
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Cargo chef plan
|
|
|
|
FROM chef as planner
|
2020-11-23 15:59:06 +00:00
|
|
|
|
|
|
|
# Copy dirs
|
2021-11-09 22:16:59 +00:00
|
|
|
COPY . .
|
2020-11-23 15:59:06 +00:00
|
|
|
|
|
|
|
RUN cargo chef prepare --recipe-path recipe.json
|
|
|
|
|
2021-11-09 22:16:59 +00:00
|
|
|
FROM chef as builder
|
2020-11-23 15:59:06 +00:00
|
|
|
ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
|
|
|
|
ARG RUSTRELEASEDIR="debug"
|
2020-09-02 15:42:48 +00:00
|
|
|
|
2021-11-09 22:16:59 +00:00
|
|
|
COPY --from=planner /app/recipe.json ./recipe.json
|
|
|
|
RUN cargo chef cook --recipe-path recipe.json --target ${CARGO_BUILD_TARGET}
|
2020-11-23 15:59:06 +00:00
|
|
|
|
|
|
|
# Copy the rest of the dirs
|
2021-11-09 22:16:59 +00:00
|
|
|
COPY . .
|
2020-11-23 15:59:06 +00:00
|
|
|
|
2021-11-09 22:16:59 +00:00
|
|
|
# Build the project
|
2021-04-12 11:47:58 +00:00
|
|
|
RUN echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs"
|
2021-11-09 22:16:59 +00:00
|
|
|
RUN cargo build --target ${CARGO_BUILD_TARGET}
|
2019-04-10 18:10:57 +00:00
|
|
|
|
2020-11-23 15:59:06 +00:00
|
|
|
# reduce binary size
|
|
|
|
RUN strip ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server
|
2020-01-01 17:01:49 +00:00
|
|
|
|
2020-11-23 15:59:06 +00:00
|
|
|
RUN cp ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server /app/lemmy_server
|
|
|
|
|
|
|
|
# The alpine runner
|
2021-09-02 11:50:20 +00:00
|
|
|
FROM alpine:3 as lemmy
|
2020-11-23 15:59:06 +00:00
|
|
|
|
|
|
|
# Install libpq for postgres
|
|
|
|
RUN apk add libpq
|
|
|
|
|
2019-05-14 00:46:29 +00:00
|
|
|
# Copy resources
|
2021-11-09 22:16:59 +00:00
|
|
|
COPY --from=builder /app/lemmy_server /app/lemmy
|
2019-12-17 21:35:48 +00:00
|
|
|
|
2019-04-06 23:48:54 +00:00
|
|
|
EXPOSE 8536
|
2019-05-14 00:46:29 +00:00
|
|
|
CMD ["/app/lemmy"]
|