2023-11-24 17:52:19 +00:00
|
|
|
# syntax=docker/dockerfile:1.6
|
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-11-24 17:52:19 +00:00
|
|
|
ARG LEMMY_VERSION="dev"
|
|
|
|
|
2023-10-11 15:57:05 +00:00
|
|
|
ARG AMD_BUILDER_IMAGE=rust:${RUST_VERSION}
|
2023-11-24 17:52:19 +00:00
|
|
|
ARG ARM_BUILDER_IMAGE="dessalines/lemmy-builder-arm64:${LEMMY_VERSION}"
|
|
|
|
|
2023-10-11 15:57:05 +00:00
|
|
|
ARG AMD_RUNNER_IMAGE=debian:bookworm-slim
|
2023-11-24 17:52:19 +00:00
|
|
|
ARG ARM_RUNNER_IMAGE=debian:bookworm-slim
|
|
|
|
|
|
|
|
ARG UNAME=lemmy
|
|
|
|
ARG UID=1000
|
|
|
|
ARG GID=1000
|
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-11-24 17:52:19 +00:00
|
|
|
# NB(raskyld): this is a hack to be able to COPY --from= this image, because the variable doesn't
|
|
|
|
# seem to be expended in --form arg of COPY :(
|
|
|
|
FROM --platform=linux/amd64 ${ARM_BUILDER_IMAGE} AS build-arm64
|
2023-08-31 13:02:59 +00:00
|
|
|
|
2023-11-24 17:52:19 +00:00
|
|
|
# amd64 base runner
|
|
|
|
FROM ${AMD_RUNNER_IMAGE} AS runner-linux-amd64
|
2023-02-17 06:29:45 +00:00
|
|
|
|
2023-11-24 17:52:19 +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-11-24 17:52:19 +00:00
|
|
|
COPY --from=build-amd64 --chmod=0755 /lemmy/lemmy /usr/local/bin
|
2023-08-31 13:02:59 +00:00
|
|
|
|
2023-11-24 17:52:19 +00:00
|
|
|
# arm base runner
|
|
|
|
FROM ${ARM_RUNNER_IMAGE} AS runner-linux-arm64
|
2023-10-11 15:57:05 +00:00
|
|
|
|
2023-11-24 17:52:19 +00:00
|
|
|
RUN apt update && apt install -y ca-certificates libssl-dev libpq-dev
|
2023-08-31 13:02:59 +00:00
|
|
|
|
2023-11-24 17:52:19 +00:00
|
|
|
COPY --from=build-arm64 --chmod=0755 /home/lemmy/lemmy_server /usr/local/bin
|
2023-10-11 15:57:05 +00:00
|
|
|
|
2023-11-24 17:52:19 +00:00
|
|
|
# Final image that use a base runner based on the target OS and ARCH
|
|
|
|
FROM runner-${TARGETOS}-${TARGETARCH}
|
2023-08-31 13:02:59 +00:00
|
|
|
|
2023-11-24 17:52:19 +00:00
|
|
|
LABEL org.opencontainers.image.authors="The Lemmy Authors"
|
|
|
|
LABEL org.opencontainers.image.source="https://github.com/LemmyNet/lemmy"
|
|
|
|
LABEL org.opencontainers.image.licenses="AGPL-3.0-or-later"
|
|
|
|
LABEL org.opencontainers.image.description="A link aggregator and forum for the fediverse"
|
2023-08-31 13:02:59 +00:00
|
|
|
|
2023-11-24 17:52:19 +00:00
|
|
|
ARG UNAME
|
|
|
|
ARG GID
|
|
|
|
ARG UID
|
2023-08-31 13:02:59 +00:00
|
|
|
|
2023-11-24 17:52:19 +00:00
|
|
|
RUN groupadd -g ${GID} -o ${UNAME} && \
|
|
|
|
useradd -m -u ${UID} -g ${GID} -o -s /bin/bash ${UNAME}
|
2023-10-11 15:57:05 +00:00
|
|
|
USER $UNAME
|
2023-08-31 13:02:59 +00:00
|
|
|
|
2023-11-24 17:52:19 +00:00
|
|
|
ENTRYPOINT ["lemmy_server"]
|
2023-10-11 15:57:05 +00:00
|
|
|
EXPOSE 8536
|
|
|
|
STOPSIGNAL SIGTERM
|