2023-10-11 15:57:05 +00:00
|
|
|
ARG RUST_VERSION=1.72.1
|
2023-07-05 11:25:19 +00:00
|
|
|
ARG CARGO_BUILD_FEATURES=default
|
2023-08-31 13:02:59 +00:00
|
|
|
ARG RUST_RELEASE_MODE=debug
|
2023-10-11 15:57:05 +00:00
|
|
|
ARG AMD_BUILDER_IMAGE=rust:${RUST_VERSION}
|
|
|
|
ARG ARM_BUILDER_IMAGE=blackdex/rust-musl:aarch64-musl-stable-${RUST_VERSION}-openssl3
|
|
|
|
ARG AMD_RUNNER_IMAGE=debian:bookworm-slim
|
|
|
|
ARG ARM_RUNNER_IMAGE=alpine:3.18
|
2023-08-31 13:02:59 +00:00
|
|
|
|
|
|
|
# AMD64 builder
|
2023-10-11 15:57:05 +00:00
|
|
|
FROM --platform=${BUILDPLATFORM} ${AMD_BUILDER_IMAGE} AS build-amd64
|
2023-08-31 13:02:59 +00:00
|
|
|
|
|
|
|
ARG CARGO_BUILD_FEATURES
|
|
|
|
ARG RUST_RELEASE_MODE
|
|
|
|
|
|
|
|
WORKDIR /lemmy
|
|
|
|
|
|
|
|
COPY . ./
|
|
|
|
|
|
|
|
# Debug build
|
|
|
|
RUN --mount=type=cache,target=/lemmy/target set -ex; \
|
|
|
|
if [ "${RUST_RELEASE_MODE}" = "debug" ]; then \
|
|
|
|
echo "pub const VERSION: &str = \"$(git describe --tag)\";" > crates/utils/src/version.rs; \
|
2023-10-11 15:57:05 +00:00
|
|
|
cargo build --features "${CARGO_BUILD_FEATURES}"; \
|
|
|
|
mv target/debug/lemmy_server ./lemmy; \
|
2023-02-17 06:29:45 +00:00
|
|
|
fi
|
|
|
|
|
2023-08-31 13:02:59 +00:00
|
|
|
# Release build
|
|
|
|
RUN set -ex; \
|
|
|
|
if [ "${RUST_RELEASE_MODE}" = "release" ]; then \
|
|
|
|
echo "pub const VERSION: &str = \"$(git describe --tag)\";" > crates/utils/src/version.rs; \
|
2023-10-11 15:57:05 +00:00
|
|
|
cargo build --features "${CARGO_BUILD_FEATURES}" --release; \
|
|
|
|
mv target/release/lemmy_server ./lemmy; \
|
2023-02-17 06:29:45 +00:00
|
|
|
fi
|
|
|
|
|
2023-08-31 13:02:59 +00:00
|
|
|
# ARM64 builder
|
2023-10-11 15:57:05 +00:00
|
|
|
# TODO currently broken
|
|
|
|
# FROM --platform=${BUILDPLATFORM} ${ARM_BUILDER_IMAGE} as build-arm64
|
2023-08-31 13:02:59 +00:00
|
|
|
|
2023-10-11 15:57:05 +00:00
|
|
|
# ENV DEBIAN_FRONTEND=noninteractive
|
|
|
|
# ENV CARGO_HOME=/root/.cargo
|
|
|
|
# ENV PQ_LIB_DIR=/usr/local/musl/pq15/lib
|
2023-02-17 06:29:45 +00:00
|
|
|
|
2023-10-11 15:57:05 +00:00
|
|
|
# RUN apt update && apt install -y \
|
|
|
|
# --no-install-recommends \
|
|
|
|
# git
|
2023-02-17 06:29:45 +00:00
|
|
|
|
2023-10-11 15:57:05 +00:00
|
|
|
# RUN mkdir -pv "${CARGO_HOME}" && \
|
|
|
|
# rustup set profile minimal && \
|
|
|
|
# rustup target add aarch64-unknown-linux-musl
|
2023-08-31 13:02:59 +00:00
|
|
|
|
2023-10-11 15:57:05 +00:00
|
|
|
# ARG CARGO_BUILD_FEATURES
|
|
|
|
# ARG RUST_RELEASE_MODE
|
2023-08-31 13:02:59 +00:00
|
|
|
|
2023-10-11 15:57:05 +00:00
|
|
|
# WORKDIR /lemmy
|
|
|
|
|
|
|
|
# COPY . ./
|
2023-08-31 13:02:59 +00:00
|
|
|
|
2023-10-11 15:57:05 +00:00
|
|
|
# # Debug build
|
|
|
|
# RUN --mount=type=cache,target=/lemmy/target set -ex; \
|
|
|
|
# if [ "${RUST_RELEASE_MODE}" = "debug" ]; then \
|
|
|
|
# echo "pub const VERSION: &str = \"$(git describe --tag)\";" > crates/utils/src/version.rs; \
|
|
|
|
# cargo build --target=aarch64-unknown-linux-musl --features "${CARGO_BUILD_FEATURES}"; \
|
|
|
|
# mv target/aarch64-unknown-linux-musl/debug/lemmy_server ./lemmy; \
|
|
|
|
# fi
|
|
|
|
|
|
|
|
# # Release build
|
|
|
|
# RUN set -ex; \
|
|
|
|
# if [ "${RUST_RELEASE_MODE}" = "release" ]; then \
|
|
|
|
# echo "pub const VERSION: &str = \"$(git describe --tag)\";" > crates/utils/src/version.rs; \
|
|
|
|
# cargo build --target=aarch64-unknown-linux-musl --features "${CARGO_BUILD_FEATURES}" --release; \
|
|
|
|
# mv target/aarch64-unknown-linux-musl/release/lemmy_server ./lemmy; \
|
|
|
|
# fi
|
2023-08-31 13:02:59 +00:00
|
|
|
|
|
|
|
## Final image
|
2023-10-11 15:57:05 +00:00
|
|
|
FROM ${AMD_RUNNER_IMAGE}
|
2023-08-31 13:02:59 +00:00
|
|
|
|
2023-10-11 15:57:05 +00:00
|
|
|
# Federation needs CA certificates
|
|
|
|
RUN apt update && apt install -y libssl-dev libpq-dev ca-certificates
|
2023-08-31 13:02:59 +00:00
|
|
|
|
2023-10-11 15:57:05 +00:00
|
|
|
# Debian / Ubuntu non-root user creds
|
|
|
|
ARG UNAME=lemmy
|
|
|
|
ARG UID=1000
|
|
|
|
ARG GID=1000
|
|
|
|
RUN groupadd -g $GID -o $UNAME
|
|
|
|
RUN useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME
|
|
|
|
USER $UNAME
|
2023-08-31 13:02:59 +00:00
|
|
|
|
2023-10-11 15:57:05 +00:00
|
|
|
COPY --from=build-amd64 /lemmy/lemmy ./
|
|
|
|
CMD ["./lemmy"]
|
|
|
|
EXPOSE 8536
|
|
|
|
STOPSIGNAL SIGTERM
|
2023-08-31 13:02:59 +00:00
|
|
|
|
2023-10-11 15:57:05 +00:00
|
|
|
## Arm Runner
|
|
|
|
# FROM --platform=${BUILDPLATFORM} ${ARM_RUNNER_IMAGE}
|
2023-02-17 06:29:45 +00:00
|
|
|
|
2023-10-11 15:57:05 +00:00
|
|
|
# ARG UNAME=lemmy
|
|
|
|
# ARG UID=1000
|
|
|
|
# ARG GID=1000
|
2023-07-24 13:51:51 +00:00
|
|
|
|
2023-10-11 15:57:05 +00:00
|
|
|
# RUN apk add --no-cache ca-certificates
|
2023-08-31 13:02:59 +00:00
|
|
|
|
2023-10-11 15:57:05 +00:00
|
|
|
# COPY --from=build-arm64 --chmod=0755 /lemmy/lemmy /usr/local/bin
|
|
|
|
|
|
|
|
# RUN addgroup -S -g ${GID} ${UNAME} && \
|
|
|
|
# adduser -S -H -D -G ${UNAME} -u ${UID} -g "" -s /sbin/nologin ${UNAME}
|
|
|
|
# USER $UNAME
|
|
|
|
|
|
|
|
# CMD ["lemmy"]
|
|
|
|
# EXPOSE 8536
|
|
|
|
# STOPSIGNAL SIGTERM
|
2023-08-31 13:02:59 +00:00
|
|
|
|