]> Untitled Git - lemmy.git/blob - docker/Dockerfile
Use Dockerfile.multiarch as Dockerfile (#2818)
[lemmy.git] / docker / Dockerfile
1 # FIXME: use "--platform=$BUILDPLATFORM" and solve openssl cross-compile issue
2 FROM rust:1.67.0-alpine as builder
3
4 # Install build dependencies
5 RUN apk add --no-cache git openssl-dev libpq-dev musl-dev
6
7 # Set the working directory to /app and copy the source code
8 WORKDIR /app
9 COPY . .
10
11 # Set the target architecture (can be set using --build-arg), buildx set it automatically
12 ARG TARGETARCH
13
14 # This can be set to release using --build-arg
15 ARG RUST_RELEASE_MODE="debug"
16
17 # Prepare toolchain
18 # Docker and Rust use different architecture naming schemas, so we have to convert them
19 RUN case $TARGETARCH in \
20       arm64) RUSTARCH=aarch64 ;; \
21       amd64) RUSTARCH=x86_64 ;; \
22       *) echo "unsupported architecture: $TARGETARCH"; exit 3 ;; \
23     esac \
24  && echo "RUSTARCH=$RUSTARCH" >> .buildenv
25
26 # Debug mode build
27 RUN --mount=type=cache,target=/app/target \
28     if [ "$RUST_RELEASE_MODE" = "debug" ]; then \
29       source .buildenv \
30       && echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" \
31       && rustup target add ${RUSTARCH}-unknown-linux-musl \
32       && cargo build --target ${RUSTARCH}-unknown-linux-musl \
33       && cp ./target/${RUSTARCH}-unknown-linux-musl/${RUST_RELEASE_MODE}/lemmy_server /app/lemmy_server; \
34     fi
35
36 # Release mode build
37 RUN \
38     if [ "$RUST_RELEASE_MODE" = "release" ]; then \
39       source .buildenv \
40       && rustup target add ${RUSTARCH}-unknown-linux-musl \
41       && cargo build --target ${RUSTARCH}-unknown-linux-musl --release \
42       && cp ./target/${RUSTARCH}-unknown-linux-musl/${RUST_RELEASE_MODE}/lemmy_server /app/lemmy_server; \
43     fi
44
45 # The Alpine runner
46 FROM alpine:3 as lemmy
47
48 # Install libpq for Postgres
49 RUN apk add --no-cache ca-certificates libpq
50
51 # Copy resources
52 COPY --from=builder /app/lemmy_server /app/lemmy
53
54 EXPOSE 8536
55 CMD ["/app/lemmy"]