mirror of https://github.com/LemmyNet/lemmy
fix: Cross-compilation to ARM64 (#4142)
* feat(docker/docs): explain how building lemmy works Signed-off-by: Enzo NOCERA <enzo@nocera.eu> * feat: add arm build * review: rename script & fix typo * feat(ci): allow cross platform compilation * feat(ci): prettier * fix(docker): fix base image name * fix: add dockerfile in CI path Signed-off-by: Enzo Nocera <enzo@nocera.eu> * fix(docker): fix runner name * fix(docker): fix builder base image * fix(docker): fix builder base image platform * fix(docker): avoid using the wrapper adduser/addgroup * feat: avoid adding the whole docker directory in the build context --------- Signed-off-by: Enzo NOCERA <enzo@nocera.eu> Signed-off-by: Enzo Nocera <enzo@nocera.eu> Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Nutomic <me@nutomic.com>pull/4198/head^2
parent
934fe7d1cb
commit
8a05c8f8be
@ -0,0 +1,21 @@
|
||||
# Building Lemmy Images
|
||||
|
||||
Lemmy's images are meant to be **built** on `linux/amd64`,
|
||||
but they can be **executed** on both `linux/amd64` and `linux/arm64`.
|
||||
|
||||
To do so we need to use a _cross toolchain_ whose goal is to build
|
||||
**from** amd64 **to** arm64.
|
||||
|
||||
Namely, we need to link the _lemmy_server_ with `pq` and `openssl`
|
||||
shared libraries and a few others, and they need to be in `arm64`,
|
||||
indeed.
|
||||
|
||||
The toolchain we use to cross-compile is specifically tailored for
|
||||
Lemmy's needs, see [the image repository][image-repo].
|
||||
|
||||
#### References
|
||||
|
||||
- [The Linux Documentation Project on Shared Libraries][tldp-lib]
|
||||
|
||||
[tldp-lib]: https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
|
||||
[image-repo]: https://github.com/raskyld/lemmy-cross-toolchains
|
@ -0,0 +1,23 @@
|
||||
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 <enzo@nocera.eu>"
|
||||
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
|
@ -0,0 +1,20 @@
|
||||
#!/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
|
Loading…
Reference in New Issue