]> Untitled Git - lemmy.git/blob - docker/prod/Dockerfile
Merge pull request 'Populate `content` with HTML, and `source` with markdown (ref...
[lemmy.git] / docker / prod / Dockerfile
1 ARG RUST_BUILDER_IMAGE=ekidd/rust-musl-builder:1.47.0
2
3 # Cargo chef plan
4 FROM $RUST_BUILDER_IMAGE as planner
5 WORKDIR /app
6 RUN cargo install cargo-chef --version 0.1.6
7
8 # Copy dirs
9 COPY ./ ./
10
11 RUN sudo chown -R rust:rust .
12 RUN cargo chef prepare --recipe-path recipe.json
13
14 # Cargo chef cache dependencies
15 FROM $RUST_BUILDER_IMAGE as cacher
16 ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
17 WORKDIR /app
18 RUN cargo install cargo-chef --version 0.1.6
19 COPY --from=planner /app/recipe.json ./recipe.json
20 RUN sudo chown -R rust:rust .
21 RUN cargo chef cook --release --target ${CARGO_BUILD_TARGET} --recipe-path recipe.json
22
23 # Build the project
24 FROM $RUST_BUILDER_IMAGE as builder
25
26 ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
27 ARG RUSTRELEASEDIR="release"
28
29 WORKDIR /app
30
31 # Copy over the cached dependencies
32 COPY --from=cacher /app/target target
33 COPY --from=cacher /home/rust/.cargo /home/rust/.cargo
34
35 # Copy the rest of the dirs
36 COPY ./ ./
37
38 RUN sudo chown -R rust:rust .
39 RUN cargo build --release
40
41 # reduce binary size
42 RUN strip ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server
43
44 RUN cp ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server /app/lemmy_server
45
46 # Build the docs
47 FROM $RUST_BUILDER_IMAGE as docs
48 WORKDIR /app
49 COPY --chown=rust:rust docs ./docs
50 RUN mdbook build docs/
51
52 # The alpine runner
53 FROM alpine:3.12 as lemmy
54
55 # Install libpq for postgres
56 RUN apk add libpq
57
58 # Install Espeak for captchas
59 RUN apk add espeak
60
61 RUN addgroup -g 1000 lemmy
62 RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy
63
64 # Copy resources
65 COPY --chown=lemmy:lemmy config/defaults.hjson /config/defaults.hjson
66 COPY --chown=lemmy:lemmy --from=builder /app/lemmy_server /app/lemmy
67 COPY --chown=lemmy:lemmy --from=docs /app/docs/book/ /app/documentation/
68
69 RUN chown lemmy:lemmy /app/lemmy
70 USER lemmy
71 EXPOSE 8536
72 CMD ["/app/lemmy"]