From fc07ba2d3bfb7292e01aa887db0ec6008fb3b12d Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 26 Nov 2023 22:50:31 +0100 Subject: [PATCH] Fix entrypoint in Dockerfile (#4202) * Fix entrypoint * Delete docker/builders/lemmy-builder-arm64/docker-build.sh * Delete docker/builders directory * Remove exception for builder * Remove publish_builder_arm64 --- .dockerignore | 3 +- .woodpecker.yml | 14 ------- docker/Dockerfile | 41 ++++++++++++++++--- .../builders/lemmy-builder-arm64/Dockerfile | 23 ----------- .../lemmy-builder-arm64/docker-build.sh | 20 --------- 5 files changed, 36 insertions(+), 65 deletions(-) delete mode 100644 docker/builders/lemmy-builder-arm64/Dockerfile delete mode 100644 docker/builders/lemmy-builder-arm64/docker-build.sh diff --git a/.dockerignore b/.dockerignore index b999debba..43381f7b7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,9 +1,8 @@ # build folders and similar which are not needed for the docker build target docker -!docker/builders/lemmy-builder-arm64/docker-build.sh api_tests ansible tests *.sh -pictrs \ No newline at end of file +pictrs diff --git a/.woodpecker.yml b/.woodpecker.yml index 667e49582..910db0ce9 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -227,19 +227,6 @@ steps: - event: push branch: main - publish_builder_arm64: - image: woodpeckerci/plugin-docker-buildx - secrets: [docker_username, docker_password] - settings: - repo: dessalines/lemmy-builder-arm64 - dockerfile: docker/builders/lemmy-builder-arm64/Dockerfile - platforms: linux/amd64 - build_args: - - RUST_RELEASE_MODE=release - tag: ${CI_COMMIT_TAG} - when: - event: tag - publish_release_docker: image: woodpeckerci/plugin-docker-buildx secrets: [docker_username, docker_password] @@ -249,7 +236,6 @@ steps: platforms: linux/amd64, linux/arm64 build_args: - RUST_RELEASE_MODE=release - - LEMMY_VERSION=${CI_COMMIT_TAG} tag: ${CI_COMMIT_TAG} when: event: tag diff --git a/docker/Dockerfile b/docker/Dockerfile index 359c030ad..6ba506961 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,10 +2,9 @@ ARG RUST_VERSION=1.72.1 ARG CARGO_BUILD_FEATURES=default ARG RUST_RELEASE_MODE=debug -ARG LEMMY_VERSION="dev" ARG AMD_BUILDER_IMAGE=rust:${RUST_VERSION} -ARG ARM_BUILDER_IMAGE="dessalines/lemmy-builder-arm64:${LEMMY_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 @@ -29,15 +28,16 @@ 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/debug/lemmy_server ./lemmy; \ + mv target/"${RUST_RELEASE_MODE}"/lemmy_server ./lemmy_server; \ fi # Release build -RUN set -ex; \ +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/release/lemmy_server ./lemmy; \ + mv target/"${RUST_RELEASE_MODE}"/lemmy_server ./lemmy_server; \ fi # ARM64 builder @@ -45,13 +45,42 @@ RUN set -ex; \ # seem to be expended in --form arg of COPY :( FROM --platform=linux/amd64 ${ARM_BUILDER_IMAGE} AS build-arm64 +ARG RUST_RELEASE_MODE +ARG CARGO_BUILD_FEATURES + +WORKDIR /home/lemmy/src +USER 10001:10001 + +COPY --chown=lemmy:lemmy . ./ + +ENV PATH="/home/lemmy/.cargo/bin:${PATH}" +ENV RUST_RELEASE_MODE=${RUST_RELEASE_MODE} \ + CARGO_BUILD_FEATURES=${CARGO_BUILD_FEATURES} + +# 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 + +# 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 /usr/local/bin +COPY --from=build-amd64 --chmod=0755 /lemmy/lemmy_server /usr/local/bin # arm base runner FROM ${ARM_RUNNER_IMAGE} AS runner-linux-arm64 diff --git a/docker/builders/lemmy-builder-arm64/Dockerfile b/docker/builders/lemmy-builder-arm64/Dockerfile deleted file mode 100644 index 8863b2f99..000000000 --- a/docker/builders/lemmy-builder-arm64/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -ARG ARM_CROSS_TOOLCHAIN="ghcr.io/raskyld/aarch64-lemmy-linux-gnu:v0.1.0" - -FROM ${ARM_CROSS_TOOLCHAIN} - -# NB(raskyld): Please, do not hesitate to contact me through @raskyld@social.vivaldi.net (mastodon) -# If you have any question about the cross-toolchain -LABEL org.opencontainers.image.authors="Enzo Nocera " -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 prebuilt lemmy server using a cross toolchain from amd64 to aarch64/arm64" - -ARG CARGO_BUILD_FEATURES=default -ARG RUST_RELEASE_MODE=debug - -WORKDIR /home/lemmy/src -USER 10001:10001 - -COPY --chown=lemmy:lemmy . ./ - -ENV RUST_RELEASE_MODE=${RUST_RELEASE_MODE} \ - CARGO_BUILD_FEATURES=${CARGO_BUILD_FEATURES} - -RUN --mount=type=cache,target=./target,uid=10001,gid=10001 bash ./docker/builders/lemmy-builder-arm64/docker-build.sh diff --git a/docker/builders/lemmy-builder-arm64/docker-build.sh b/docker/builders/lemmy-builder-arm64/docker-build.sh deleted file mode 100644 index 752fda80b..000000000 --- a/docker/builders/lemmy-builder-arm64/docker-build.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -set -e; - -source "$HOME/.cargo/env" - -case "$RUST_RELEASE_MODE" in - "debug") - echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" - cargo build --features "${CARGO_BUILD_FEATURES}" - cp "./target/$CARGO_BUILD_TARGET/$RUST_RELEASE_MODE/lemmy_server" /home/lemmy/lemmy_server - ;; - "release") - # Pass a value to $USE_RELEASE_CACHE to avoid purging the cache for release builds - [[ -z "$USE_RELEASE_CACHE" ]] || cargo clean --release - echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" - cargo build --features "${CARGO_BUILD_FEATURES}" --release - cp "./target/$CARGO_BUILD_TARGET/$RUST_RELEASE_MODE/lemmy_server" /home/lemmy/lemmy_server - ;; -esac