From c8cac56e417b6c890aa49f25980dc0c1717f576b Mon Sep 17 00:00:00 2001 From: ubergeek77 Date: Wed, 10 Jan 2024 16:26:23 -0600 Subject: [PATCH] Fix 0.19.2 --- Dockerfile-backend | 80 +++++++++++++++++++++++---------------------- Dockerfile-frontend | 46 +++++++------------------- README.md | 10 +++--- 3 files changed, 58 insertions(+), 78 deletions(-) diff --git a/Dockerfile-backend b/Dockerfile-backend index bb4ee61..2f7d394 100644 --- a/Dockerfile-backend +++ b/Dockerfile-backend @@ -1,55 +1,57 @@ -FROM rust:1.70-slim-buster as builder +# syntax=docker/dockerfile:1.6 +ARG RUST_VERSION=1.75 +ARG CARGO_BUILD_FEATURES=default +ARG RUST_RELEASE_MODE=release -# Install compilation dependencies -RUN apt-get update \ - && apt-get -y install --no-install-recommends libssl-dev pkg-config libpq-dev git \ - && rm -rf /var/lib/apt/lists/* +ARG BUILDER_IMAGE=rust:${RUST_VERSION} +ARG RUNNER_IMAGE=debian:bookworm-slim -WORKDIR /app +ARG UNAME=lemmy +ARG UID=1000 +ARG GID=1000 -# comma-seperated list of features to enable -ARG CARGO_BUILD_FEATURES=default +# AMD64 builder +FROM ${BUILDER_IMAGE} AS build -# This can be set to release using --build-arg -ARG RUST_RELEASE_MODE="release" +ARG CARGO_BUILD_FEATURES +ARG RUST_RELEASE_MODE -COPY . . +WORKDIR /lemmy -# Build the project +COPY . ./ -# Debug mode build -RUN --mount=type=cache,target=/app/target \ - if [ "$RUST_RELEASE_MODE" = "debug" ] ; then \ - echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" \ - && echo "Building Lemmy $(git describe --tag), Cargo Target: $(rustc -vV | sed -n 's|host: ||p'), Mode: $RUST_RELEASE_MODE" \ - && cargo build --features ${CARGO_BUILD_FEATURES} \ - && cp ./target/$RUST_RELEASE_MODE/lemmy_server /app/lemmy_server; \ +# 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 mode build -RUN \ - if [ "$RUST_RELEASE_MODE" = "release" ] ; then \ - echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" \ - && echo "Building Lemmy $(git describe --tag), Cargo Target: $(rustc -vV | sed -n 's|host: ||p'), Mode: $RUST_RELEASE_MODE" \ - && cargo build --features ${CARGO_BUILD_FEATURES} --release \ - && cp ./target/$RUST_RELEASE_MODE/lemmy_server /app/lemmy_server; \ +# 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 -# The Debian runner -FROM debian:buster-slim as lemmy +FROM ${RUNNER_IMAGE} AS runner-linux -# Install libpq for postgres -RUN apt-get update \ - && apt-get -y install --no-install-recommends postgresql-client libc6 libssl1.1 ca-certificates \ - && rm -rf /var/lib/apt/lists/* +# Federation needs CA certificates +RUN apt update && apt install -y libssl-dev libpq-dev ca-certificates -RUN addgroup --gid 1000 lemmy -RUN useradd --no-create-home --shell /bin/sh --uid 1000 --gid 1000 lemmy +COPY --from=build --chmod=0755 /lemmy/lemmy_server /usr/local/bin -# Copy resources -COPY --chown=lemmy:lemmy --from=builder /app/lemmy_server /app/lemmy +ARG UNAME +ARG GID +ARG UID -RUN chown lemmy:lemmy /app/lemmy -USER lemmy +RUN groupadd -g ${GID} -o ${UNAME} && \ + useradd -m -u ${UID} -g ${GID} -o -s /bin/bash ${UNAME} +USER $UNAME -CMD ["/app/lemmy"] +ENTRYPOINT ["lemmy_server"] +EXPOSE 8536 +STOPSIGNAL SIGTERM \ No newline at end of file diff --git a/Dockerfile-frontend b/Dockerfile-frontend index 1aef9ad..d8fad20 100644 --- a/Dockerfile-frontend +++ b/Dockerfile-frontend @@ -1,19 +1,4 @@ -# gobinaries.com is not reliable for container builds (external dependency) -# It also does not support arm/arm64 (at least not right now) -# We have to build node-prune from source -FROM golang as go-builder -WORKDIR /app -RUN cd /app && \ - git clone https://github.com/tj/node-prune && \ - cd /app/node-prune && \ - CGO_ENABLED=0 go build - -# Original Dockerfile below (mostly) -FROM node:alpine as builder - -# Upgrade to edge to fix sharp/libvips issues -RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories && \ - echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories +FROM node:20-alpine as builder # Added vips-dev and pkgconfig so that local vips is used instead of prebuilt # Done for two reasons: @@ -32,9 +17,7 @@ ENV npm_config_target_libc=musl # Cache deps COPY package.json yarn.lock ./ -RUN sed -i 's|"sharp": "^0.32.4"|"sharp": "^0.32.6"|g' package.json - -RUN yarn --production --prefer-offline --pure-lockfile +RUN yarn --production --prefer-offline --pure-lockfile --network-timeout 100000 # Build COPY generate_translations.js \ @@ -47,38 +30,31 @@ COPY lemmy-translations lemmy-translations COPY src src COPY .git .git -# Set UI version +# Set UI version RUN echo "export const VERSION = '$(git describe --tag)';" > "src/shared/version.ts" -RUN yarn --production --prefer-offline +RUN yarn --production --prefer-offline --network-timeout 100000 RUN yarn build:prod -# Prune the image -# Copy the manually built node-prune here -RUN mkdir -p /usr/local/bin/ -COPY --from=go-builder /app/node-prune/node-prune /usr/local/bin/node-prune -RUN chmod +x /usr/local/bin/node-prune -RUN node-prune /usr/src/app/node_modules - RUN rm -rf ./node_modules/import-sort-parser-typescript RUN rm -rf ./node_modules/typescript RUN rm -rf ./node_modules/npm RUN du -sh ./node_modules/* | sort -nr | grep '\dM.*' -FROM node:alpine as runner +FROM node:20-alpine as runner +ENV NODE_ENV=production -# Upgrade to edge to fix sharp/libvips issues -RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories && \ - echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories +RUN apk update && apk upgrade && apk add curl vips-cpp -RUN apk update && apk upgrade && apk add vips-cpp COPY --from=builder /usr/src/app/dist /app/dist COPY --from=builder /usr/src/app/node_modules /app/node_modules RUN chown -R node:node /app -USER node +HEALTHCHECK --interval=60s --start-period=10s --retries=2 --timeout=10s CMD curl -ILfSs http://localhost:1234/ > /dev/null || exit 1 + +USER node EXPOSE 1234 WORKDIR /app -CMD node dist/js/server.js +CMD exec node dist/js/server.js \ No newline at end of file diff --git a/README.md b/README.md index d67c21b..2ae6f98 100644 --- a/README.md +++ b/README.md @@ -10,17 +10,19 @@ Builds [`LemmyNet/lemmy`](https://github.com/LemmyNet/lemmy/) and [`LemmyNet/lem - ARM (`arm/v7`) - ARM64 (`arm64`) -I made these because the Lemmy project does not currently support ARM, [and has been deliberating how to create ARM builds since `0.17.4`](https://github.com/LemmyNet/lemmy/issues/3102). The Dockerfiles I use, and the workflow I use to compile these images, are all open source here. [You can see the logs of previous runs on the Actions tab](https://github.com/ubergeek77/lemmy-docker-multiarch/actions/workflows/build-multiarch.yml). +These images were originally created when Lemmy was at version `0.17.x`, because Lemmy only supported `amd64`. Lemmy started officially providing `arm64` images in version `0.18.0` by including some of the changes from this repository, but as of `0.19.2`, `arm/v7` images are still not officially provided by Lemmy. Since some users still want to run Lemmy on ARM32 hardware, I will continue to update these images until the Lemmy project officially builds images for `arm/v7`. + +My images are as close to upstream as possible; I only change the Dockerfiles so that they will build on virtually any host, without needing cross-compilation or platform-specific steps. The Dockerfiles I use, and the workflow I use to compile these images, are all open source here. [You can see the logs of previous runs on the Actions tab](https://github.com/ubergeek77/lemmy-docker-multiarch/actions/workflows/build-multiarch.yml). When [`LemmyNet/lemmy`](https://github.com/LemmyNet/lemmy/) or [`LemmyNet/lemmy-ui`](https://github.com/LemmyNet/lemmy-ui/) have new tags, my workflow will automatically be launched and those new tags will be built. These images are primarily here so they can be used in my [Lemmy-Easy-Deploy](https://github.com/ubergeek77/Lemmy-Easy-Deploy) project. However, you may use these images manually if you like. They are drop-in replacements for the official Lemmy images. -I don't tag `latest`, so you will need to specify a tag to pull. For example, to use `0.18.0`: +I don't tag `latest`, so you will need to specify a tag to pull. For example, to use `0.19.2`: ``` -ghcr.io/ubergeek77/lemmy:0.18.0 -ghcr.io/ubergeek77/lemmy-ui:0.18.0 +ghcr.io/ubergeek77/lemmy:0.19.2 +ghcr.io/ubergeek77/lemmy-ui:0.19.2 ``` I also build `rc` tags. In general, I will have images for any stable or `rc` tag of the official Lemmy repositories. To see the full list of tags I've built, check the Packages section on this repo, or go to the images directly: