mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-23 19:31:33 +00:00
d26a7ad337
* Trying out cargo chef and a travis docker image cache. * trying to change internal target. * Use latest cargo-chef with --target * Remove caching for now. * Adding back in chowns * Adding back in cache. * Remove travis caching. * Switching dev dockerfile to match prod, using cargo-chef and alpine. * Make travis happy * Trying a chown rust. * Caching cargo-chef first. * Moving the chowns * Removing many copy commands. * Go back to rust 1.47.0 due to config-rs breaking. * Adding the old volume mount version. * Adding some script comments. Co-authored-by: Luca Palmieri <lpalmieri@truelayer.com>
72 lines
1.8 KiB
Docker
72 lines
1.8 KiB
Docker
ARG RUST_BUILDER_IMAGE=ekidd/rust-musl-builder:1.47.0
|
|
|
|
# Cargo chef plan
|
|
FROM $RUST_BUILDER_IMAGE as planner
|
|
WORKDIR /app
|
|
RUN cargo install cargo-chef --version 0.1.6
|
|
|
|
# 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
|
|
RUN cargo install cargo-chef --version 0.1.6
|
|
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
|
|
|
|
ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
|
|
ARG RUSTRELEASEDIR="release"
|
|
|
|
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 ./ ./
|
|
|
|
RUN sudo chown -R rust:rust .
|
|
RUN cargo build --release
|
|
|
|
# reduce binary size
|
|
RUN strip ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server
|
|
|
|
RUN cp ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server /app/lemmy_server
|
|
|
|
# Build the docs
|
|
FROM $RUST_BUILDER_IMAGE as docs
|
|
WORKDIR /app
|
|
COPY --chown=rust:rust docs ./docs
|
|
RUN mdbook build docs/
|
|
|
|
# The alpine runner
|
|
FROM alpine:3.12 as lemmy
|
|
|
|
# Install libpq for postgres
|
|
RUN apk add libpq
|
|
|
|
# Install Espeak for captchas
|
|
RUN apk add espeak
|
|
|
|
RUN addgroup -g 1000 lemmy
|
|
RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy
|
|
|
|
# Copy resources
|
|
COPY --chown=lemmy:lemmy config/defaults.hjson /config/defaults.hjson
|
|
COPY --chown=lemmy:lemmy --from=builder /app/lemmy_server /app/lemmy
|
|
COPY --chown=lemmy:lemmy --from=docs /app/docs/book/ /app/documentation/
|
|
|
|
RUN chown lemmy:lemmy /app/lemmy
|
|
USER lemmy
|
|
EXPOSE 8536
|
|
CMD ["/app/lemmy"]
|