2020-11-23 15:59:06 +00:00
|
|
|
ARG RUST_BUILDER_IMAGE=ekidd/rust-musl-builder:1.47.0
|
2020-06-12 13:29:50 +00:00
|
|
|
|
2020-11-23 15:59:06 +00:00
|
|
|
# Cargo chef plan
|
|
|
|
FROM $RUST_BUILDER_IMAGE as planner
|
|
|
|
WORKDIR /app
|
2021-02-24 22:10:28 +00:00
|
|
|
RUN cargo install cargo-chef
|
2020-11-23 15:59:06 +00: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 22:10:28 +00:00
|
|
|
RUN cargo install cargo-chef
|
2020-11-23 15:59:06 +00:00
|
|
|
COPY --from=planner /app/recipe.json ./recipe.json
|
|
|
|
RUN sudo chown -R rust:rust .
|
|
|
|
RUN cargo chef cook --release --target ${CARGO_BUILD_TARGET} --recipe-path recipe.json
|
|
|
|
|
|
|
|
# Build the project
|
|
|
|
FROM $RUST_BUILDER_IMAGE as builder
|
2020-06-12 13:29:50 +00:00
|
|
|
|
2020-10-26 22:32:50 +00:00
|
|
|
ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
|
|
|
|
ARG RUSTRELEASEDIR="release"
|
|
|
|
|
2020-11-23 15:59:06 +00:00
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# 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 ./ ./
|
|
|
|
|
2020-10-26 18:35:19 +00:00
|
|
|
RUN sudo chown -R rust:rust .
|
2020-06-14 20:36:18 +00:00
|
|
|
RUN cargo build --release
|
2020-06-12 13:29:50 +00:00
|
|
|
|
|
|
|
# reduce binary size
|
2020-06-14 20:36:18 +00:00
|
|
|
RUN strip ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server
|
2020-06-12 13:29:50 +00:00
|
|
|
|
2020-11-23 15:59:06 +00:00
|
|
|
RUN cp ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server /app/lemmy_server
|
2020-06-14 20:36:18 +00:00
|
|
|
|
2020-11-23 15:59:06 +00:00
|
|
|
# The alpine runner
|
2020-06-14 20:36:18 +00:00
|
|
|
FROM alpine:3.12 as lemmy
|
2020-06-12 13:29:50 +00:00
|
|
|
|
|
|
|
# Install libpq for postgres
|
|
|
|
RUN apk add libpq
|
2020-07-29 13:02:46 +00:00
|
|
|
|
|
|
|
# Install Espeak for captchas
|
|
|
|
RUN apk add espeak
|
|
|
|
|
2020-06-14 20:36:18 +00:00
|
|
|
RUN addgroup -g 1000 lemmy
|
|
|
|
RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy
|
2020-06-12 13:29:50 +00:00
|
|
|
|
|
|
|
# Copy resources
|
2020-09-15 19:26:47 +00:00
|
|
|
COPY --chown=lemmy:lemmy config/defaults.hjson /config/defaults.hjson
|
2020-11-23 15:59:06 +00:00
|
|
|
COPY --chown=lemmy:lemmy --from=builder /app/lemmy_server /app/lemmy
|
2020-06-12 13:29:50 +00:00
|
|
|
|
|
|
|
RUN chown lemmy:lemmy /app/lemmy
|
|
|
|
USER lemmy
|
|
|
|
EXPOSE 8536
|
|
|
|
CMD ["/app/lemmy"]
|