2021-03-01 12:46:56 -05:00
|
|
|
ARG RUST_BUILDER_IMAGE=ekidd/rust-musl-builder:1.50.0
|
2019-04-10 14:10:57 -04:00
|
|
|
|
2020-11-23 10:59:06 -05:00
|
|
|
# Cargo chef plan
|
|
|
|
FROM $RUST_BUILDER_IMAGE as planner
|
|
|
|
WORKDIR /app
|
2021-02-24 17:10:28 -05:00
|
|
|
RUN cargo install cargo-chef
|
2020-11-23 10:59:06 -05:00
|
|
|
|
|
|
|
# Copy dirs
|
|
|
|
COPY ./ ./
|
|
|
|
|
|
|
|
RUN sudo chown -R rust:rust .
|
|
|
|
RUN cargo chef prepare --recipe-path recipe.json
|
|
|
|
|
|
|
|
# Cargo chef cache dependencies
|
|
|
|
FROM $RUST_BUILDER_IMAGE as cacher
|
|
|
|
ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
|
|
|
|
WORKDIR /app
|
2021-02-24 17:10:28 -05:00
|
|
|
RUN cargo install cargo-chef
|
2020-11-23 10:59:06 -05:00
|
|
|
COPY --from=planner /app/recipe.json ./recipe.json
|
|
|
|
RUN sudo chown -R rust:rust .
|
|
|
|
RUN cargo chef cook --target ${CARGO_BUILD_TARGET} --recipe-path recipe.json
|
|
|
|
|
|
|
|
# Build the project
|
|
|
|
FROM $RUST_BUILDER_IMAGE as builder
|
|
|
|
|
|
|
|
ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
|
|
|
|
ARG RUSTRELEASEDIR="debug"
|
2020-09-02 11:42:48 -04:00
|
|
|
|
2020-10-24 11:23:45 -04:00
|
|
|
WORKDIR /app
|
2020-09-02 11:42:48 -04:00
|
|
|
|
2020-11-23 10:59:06 -05:00
|
|
|
# Copy over the cached dependencies
|
|
|
|
COPY --from=cacher /app/target target
|
|
|
|
COPY --from=cacher /home/rust/.cargo /home/rust/.cargo
|
|
|
|
|
|
|
|
# Copy the rest of the dirs
|
|
|
|
COPY ./ ./
|
|
|
|
|
|
|
|
RUN sudo chown -R rust:rust .
|
|
|
|
RUN cargo build
|
2019-04-10 14:10:57 -04:00
|
|
|
|
2020-11-23 10:59:06 -05:00
|
|
|
# reduce binary size
|
|
|
|
RUN strip ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server
|
2020-01-01 12:01:49 -05:00
|
|
|
|
2020-11-23 10:59:06 -05:00
|
|
|
RUN cp ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server /app/lemmy_server
|
|
|
|
|
|
|
|
# The alpine runner
|
|
|
|
FROM alpine:3.12 as lemmy
|
|
|
|
|
|
|
|
# Install libpq for postgres
|
|
|
|
RUN apk add libpq
|
|
|
|
|
|
|
|
RUN addgroup -g 1000 lemmy
|
|
|
|
RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy
|
2020-07-29 09:02:46 -04:00
|
|
|
|
2019-05-13 20:46:29 -04:00
|
|
|
# Copy resources
|
2020-11-23 10:59:06 -05:00
|
|
|
COPY --chown=lemmy:lemmy --from=builder /app/lemmy_server /app/lemmy
|
2019-12-17 16:35:48 -05:00
|
|
|
|
2020-11-23 10:59:06 -05:00
|
|
|
RUN chown lemmy:lemmy /app/lemmy
|
|
|
|
USER lemmy
|
2019-04-06 19:48:54 -04:00
|
|
|
EXPOSE 8536
|
2019-05-13 20:46:29 -04:00
|
|
|
CMD ["/app/lemmy"]
|