Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix entrypoint in Dockerfile #4202

Merged
merged 5 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
pictrs
14 changes: 0 additions & 14 deletions .woodpecker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
41 changes: 35 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,29 +28,59 @@ 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
# 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

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
Expand Down
23 changes: 0 additions & 23 deletions docker/builders/lemmy-builder-arm64/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions docker/builders/lemmy-builder-arm64/docker-build.sh

This file was deleted.