]> Untitled Git - lemmy.git/blob - docker/prod/Dockerfile
Isomorphic docker (#1124)
[lemmy.git] / docker / prod / Dockerfile
1 ARG RUST_BUILDER_IMAGE=shtripok/rust-musl-builder:arm
2
3 FROM $RUST_BUILDER_IMAGE as rust
4
5 #ARG RUSTRELEASEDIR="debug"
6 ARG RUSTRELEASEDIR="release"
7
8 # Cache deps
9 WORKDIR /app
10 RUN sudo chown -R rust:rust .
11 RUN USER=root cargo new server
12 WORKDIR /app/server
13 COPY Cargo.toml Cargo.lock ./
14 COPY lemmy_db ./lemmy_db
15 COPY lemmy_utils ./lemmy_utils
16 COPY lemmy_api_structs ./lemmy_api_structs
17 COPY lemmy_rate_limit ./lemmy_rate_limit
18 RUN mkdir -p ./src/bin \
19    && echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs
20 RUN cargo build --release
21 RUN find target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR -type f -name "$(echo "lemmy_server" | tr '-' '_')*" -exec touch -t 200001010000 {} +
22 COPY src ./src/
23 COPY migrations ./migrations/
24
25 # build for release
26 # workaround for https://github.com/rust-lang/rust/issues/62896
27 RUN cargo build --frozen --release
28
29 # reduce binary size
30 RUN strip ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server
31
32 RUN cp ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server /app/server/
33
34 FROM $RUST_BUILDER_IMAGE as docs
35 WORKDIR /app
36 COPY --chown=rust:rust docs ./docs
37 RUN mdbook build docs/
38
39 FROM alpine:3.12 as lemmy
40
41 # Install libpq for postgres
42 RUN apk add libpq
43
44 # Install Espeak for captchas
45 RUN apk add espeak
46
47 RUN addgroup -g 1000 lemmy
48 RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy
49
50 # Copy resources
51 COPY --chown=lemmy:lemmy config/defaults.hjson /config/defaults.hjson
52 COPY --chown=lemmy:lemmy --from=rust /app/server/lemmy_server /app/lemmy
53 COPY --chown=lemmy:lemmy --from=docs /app/docs/book/ /app/documentation/
54
55 RUN chown lemmy:lemmy /app/lemmy
56 USER lemmy
57 EXPOSE 8536
58 CMD ["/app/lemmy"]