]> Untitled Git - lemmy.git/blob - docker/dev/Dockerfile
For untagged commits, include hash in version name (fixes #1563)
[lemmy.git] / docker / dev / Dockerfile
1 ARG RUST_BUILDER_IMAGE=ekidd/rust-musl-builder:1.50.0
2
3 # Cargo chef plan
4 FROM $RUST_BUILDER_IMAGE as planner
5 WORKDIR /app
6 RUN cargo install cargo-chef
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
19 COPY --from=planner /app/recipe.json ./recipe.json
20 RUN sudo chown -R rust:rust .
21 RUN cargo chef cook --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="debug"
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 echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs"
40 RUN cargo build
41
42 # reduce binary size
43 RUN strip ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server
44
45 RUN cp ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server /app/lemmy_server
46
47 # The alpine runner
48 FROM alpine:3.12 as lemmy
49
50 # Install libpq for postgres
51 RUN apk add libpq
52
53 RUN addgroup -g 1000 lemmy
54 RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy
55
56 # Copy resources
57 COPY --chown=lemmy:lemmy --from=builder /app/lemmy_server /app/lemmy
58
59 RUN chown lemmy:lemmy /app/lemmy
60 USER lemmy
61 EXPOSE 8536
62 CMD ["/app/lemmy"]