lemmy/docker/Dockerfile

111 lines
3.7 KiB
Docker
Raw Normal View History

# syntax=docker/dockerfile:1.6
ARG RUST_VERSION=1.75
ARG CARGO_BUILD_FEATURES=default
ARG RUST_RELEASE_MODE=debug
ARG AMD_BUILDER_IMAGE=rust:${RUST_VERSION}
ARG ARM_BUILDER_IMAGE="ghcr.io/raskyld/aarch64-lemmy-linux-gnu:v0.1.0"
ARG AMD_RUNNER_IMAGE=debian:bookworm-slim
ARG ARM_RUNNER_IMAGE=debian:bookworm-slim
ARG UNAME=lemmy
ARG UID=1000
ARG GID=1000
# AMD64 builder
FROM --platform=${BUILDPLATFORM} ${AMD_BUILDER_IMAGE} AS build-amd64
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; \
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; \
if [ "${RUST_RELEASE_MODE}" = "release" ]; then \
echo "pub const VERSION: &str = \"$(git describe --tag)\";" > crates/utils/src/version.rs; \
[ -z "$USE_RELEASE_CACHE" ] && cargo clean --release; \
cargo build --features "${CARGO_BUILD_FEATURES}" --release; \
mv target/"${RUST_RELEASE_MODE}"/lemmy_server ./lemmy_server; \
fi
# ARM64 builder
2024-01-05 19:35:31 +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 :(
2024-01-05 19:35:31 +00:00
# FROM --platform=linux/amd64 ${ARM_BUILDER_IMAGE} AS build-arm64
2024-01-05 19:35:31 +00:00
# ARG RUST_RELEASE_MODE
# ARG CARGO_BUILD_FEATURES
2024-01-05 19:35:31 +00:00
# WORKDIR /home/lemmy/src
# USER 10001:10001
2024-01-05 19:35:31 +00:00
# COPY --chown=lemmy:lemmy . ./
2024-01-05 19:35:31 +00:00
# ENV PATH="/home/lemmy/.cargo/bin:${PATH}"
# ENV RUST_RELEASE_MODE=${RUST_RELEASE_MODE} \
# CARGO_BUILD_FEATURES=${CARGO_BUILD_FEATURES}
2024-01-05 19:35:31 +00:00
# # Debug build
# RUN --mount=type=cache,target=./target,uid=10001,gid=10001 set -ex; \
# if [ "${RUST_RELEASE_MODE}" = "debug" ]; then \
# echo "pub const VERSION: &str = \"$(git describe --tag)\";" > crates/utils/src/version.rs; \
# cargo build --features "${CARGO_BUILD_FEATURES}"; \
# mv "./target/$CARGO_BUILD_TARGET/$RUST_RELEASE_MODE/lemmy_server" /home/lemmy/lemmy_server; \
# fi
2024-01-05 19:35:31 +00:00
# # Release build
# RUN --mount=type=cache,target=./target,uid=10001,gid=10001 set -ex; \
# if [ "${RUST_RELEASE_MODE}" = "release" ]; then \
# echo "pub const VERSION: &str = \"$(git describe --tag)\";" > crates/utils/src/version.rs; \
# [ -z "$USE_RELEASE_CACHE" ] && cargo clean --release; \
# cargo build --features "${CARGO_BUILD_FEATURES}" --release; \
# mv "./target/$CARGO_BUILD_TARGET/$RUST_RELEASE_MODE/lemmy_server" /home/lemmy/lemmy_server; \
# fi
# amd64 base runner
FROM ${AMD_RUNNER_IMAGE} AS runner-linux-amd64
# Federation needs CA certificates
RUN apt update && apt install -y libssl-dev libpq-dev ca-certificates
COPY --from=build-amd64 --chmod=0755 /lemmy/lemmy_server /usr/local/bin
# arm base runner
2024-01-05 19:35:31 +00:00
# FROM ${ARM_RUNNER_IMAGE} AS runner-linux-arm64
2024-01-05 19:35:31 +00:00
# RUN apt update && apt install -y ca-certificates libssl-dev libpq-dev
2024-01-05 19:35:31 +00:00
# COPY --from=build-arm64 --chmod=0755 /home/lemmy/lemmy_server /usr/local/bin
2024-01-05 19:35:31 +00:00
# # Final image that use a base runner based on the target OS and ARCH
# FROM runner-${TARGETOS}-${TARGETARCH}
2024-01-05 19:35:31 +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"
2024-01-05 19:35:31 +00:00
# ARG UNAME
# ARG GID
# ARG UID
2024-01-05 19:35:31 +00:00
# RUN groupadd -g ${GID} -o ${UNAME} && \
# useradd -m -u ${UID} -g ${GID} -o -s /bin/bash ${UNAME}
# USER $UNAME
2024-01-05 19:35:31 +00:00
# ENTRYPOINT ["lemmy_server"]
# EXPOSE 8536
# STOPSIGNAL SIGTERM