-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile-backend
72 lines (56 loc) · 2.24 KB
/
Dockerfile-backend
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# syntax=docker/dockerfile:1.10
ARG RUST_VERSION=1.81
ARG CARGO_BUILD_FEATURES=default
ARG RUST_RELEASE_MODE=release
ARG BUILDER_IMAGE=rust:${RUST_VERSION}
ARG RUNNER_IMAGE=debian:bookworm-slim
ARG UNAME=lemmy
ARG UID=1000
ARG GID=1000
FROM ${BUILDER_IMAGE} AS build
# These packages are needed when building on ARM/ARM64, but not on x86 for some reason?
RUN apt update && apt install -y clang cmake git golang libclang-dev libssl-dev ninja-build perl
ARG CARGO_BUILD_FEATURES
ARG RUST_RELEASE_MODE
ARG RUSTFLAGS
ARG TARGETARCH
WORKDIR /lemmy
COPY . ./
# Debug build
RUN --mount=type=cache,target=/lemmy/target set -ex; \
if [ "${RUST_RELEASE_MODE}" = "debug" ]; then \
RUST_BACKTRACE=full cargo build --features "${CARGO_BUILD_FEATURES}"; \
mv target/"${RUST_RELEASE_MODE}"/lemmy_server ./lemmy_server; \
fi
# Release build
RUN --mount=type=cache,target=/lemmy/target set -ex; \
# Build with 16 codegen units 32-bit architectures due to build issues
if [ "$(getconf LONG_BIT)" = "32" ]; then \
export RUSTFLAGS="-Ccodegen-units=16 ${RUSTFLAGS}"; \
fi; \
if [ "${RUST_RELEASE_MODE}" = "release" ]; then \
cargo clean --release; \
RUST_BACKTRACE=full cargo build --features "${CARGO_BUILD_FEATURES}" --release; \
mv target/"${RUST_RELEASE_MODE}"/lemmy_server ./lemmy_server; \
# Compress the binary with upx
# Skip this step on 32-but architectures
if [ "$(getconf LONG_BIT)" = "64" ]; then \
wget https://github.com/upx/upx/releases/download/v4.2.4/upx-4.2.4-${TARGETARCH}_linux.tar.xz; \
tar -xvf upx-4.2.4-${TARGETARCH}_linux.tar.xz; \
cp upx-4.2.4-${TARGETARCH}_linux/upx /usr/bin; \
upx --best --lzma /lemmy/lemmy_server; \
fi; \
fi
FROM ${RUNNER_IMAGE} AS runner-linux
# Add system packages that are needed: federation needs CA certificates, curl can be used for healthchecks
RUN apt update && apt install -y libssl-dev libpq-dev ca-certificates curl
COPY --from=build --chmod=0755 /lemmy/lemmy_server /usr/local/bin
ARG UNAME
ARG GID
ARG UID
RUN groupadd -g ${GID} -o ${UNAME} && \
useradd -m -u ${UID} -g ${GID} -o -s /bin/bash ${UNAME}
USER $UNAME
ENTRYPOINT ["lemmy_server"]
EXPOSE 8536
STOPSIGNAL SIGTERM