]> Untitled Git - lemmy.git/blob - docker/prod/Dockerfile
Split code into cargo workspaces (#67)
[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 RUN mkdir -p lemmy_db/src/ lemmy_utils/src/
14 COPY --chown=rust:rust server/Cargo.toml server/Cargo.lock ./
15 COPY --chown=rust:rust server/lemmy_db/Cargo.toml ./lemmy_db/
16 COPY --chown=rust:rust server/lemmy_utils/Cargo.toml ./lemmy_utils/
17 RUN mkdir -p ./src/bin \
18    && echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs \
19    && cp ./src/bin/main.rs ./lemmy_db/src/main.rs \
20    && cp ./src/bin/main.rs ./lemmy_utils/src/main.rs
21 RUN cargo build --release
22 RUN rm -f ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/deps/lemmy_server*
23 COPY --chown=rust:rust server/src ./src/
24 COPY --chown=rust:rust server/lemmy_db ./lemmy_db/
25 COPY --chown=rust:rust server/lemmy_utils ./lemmy_utils/
26 COPY --chown=rust:rust server/migrations ./migrations/
27
28 # build for release
29 # workaround for https://github.com/rust-lang/rust/issues/62896
30 RUN cargo build --frozen --release
31
32 # reduce binary size
33 RUN strip ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server
34
35 RUN cp ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server /app/server/
36
37 FROM $RUST_BUILDER_IMAGE as docs
38 WORKDIR /app
39 COPY --chown=rust:rust docs ./docs
40 RUN mdbook build docs/
41
42 FROM node:12-buster as node
43
44 WORKDIR /app/ui
45
46 # Cache deps
47 COPY ui/package.json ui/yarn.lock ./
48 RUN yarn install --pure-lockfile --network-timeout 600000
49
50 # Build
51 COPY ui /app/ui
52 RUN yarn build
53
54 FROM alpine:3.12 as lemmy
55
56 # Install libpq for postgres
57 RUN apk add libpq
58 RUN addgroup -g 1000 lemmy
59 RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy
60
61 # Copy resources
62 COPY --chown=lemmy:lemmy server/config/defaults.hjson /config/defaults.hjson
63 COPY --chown=lemmy:lemmy --from=rust /app/server/lemmy_server /app/lemmy
64 COPY --chown=lemmy:lemmy --from=docs /app/docs/book/ /app/dist/documentation/
65 COPY --chown=lemmy:lemmy --from=node /app/ui/dist /app/dist
66
67 RUN chown lemmy:lemmy /app/lemmy
68 USER lemmy
69 EXPOSE 8536
70 CMD ["/app/lemmy"]