diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 046bbe42216a0444f34a6ea5e2a94eb421e984e2..f17c841487c9a836754aec99fee52e60c8fed70b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -70,7 +70,7 @@ fmt_and_clippy: - echo podman build --layers --tag "$IMAGE_NAME:$IMAGE_TAG" -f docker/Dockerfile $PODMAN_BUILD_OPTIONS . - podman build --layers --tag "$IMAGE_NAME:$IMAGE_TAG" -f docker/Dockerfile $PODMAN_BUILD_OPTIONS . tags: - - kepler + - podman .docker_deploy: stage: deploy diff --git a/docker/Dockerfile b/docker/Dockerfile index 51d1779c1b9481d64dfd294a1e42d75ad484913b..7b3e0dd7c8196ffe11311176956bddc61b04d186 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,20 +1,15 @@ # Workaround for https://github.com/containers/buildah/issues/4742 FROM debian:bullseye-slim as target -#ARG TARGETPLATFORM - -#RUN apt-get update -#RUN apt-get install ca-certificates curl gnupg -#RUN install -m 0755 -d /etc/apt/keyrings -#RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg -#RUN chmod a+r /etc/apt/keyrings/docker.gpg -#RUN echo \ -# "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ -# "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ -# tee /etc/apt/sources.list.d/docker.list > /dev/null -# -#RUN apt-get update -#RUN apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -RUN docker run --entrypoint /bin/sh hello-world echo FromDocker + +# ------------------------------------------------------------------------------ +# Build Stage +# ------------------------------------------------------------------------------ + +# When building for a foreign arch, use cross-compilation +# https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/ +FROM --platform=$BUILDPLATFORM rust:1-bullseye as build +ARG BUILDPLATFORM +ARG TARGETPLATFORM # We need the target arch triplet in both Debian and rust flavor RUN echo "DEBIAN_ARCH_TRIPLET='$(dpkg-architecture -A${TARGETPLATFORM#linux/} -qDEB_TARGET_MULTIARCH)'" >>/root/dynenv @@ -38,34 +33,38 @@ RUN if [ "$debug" = 0 ]; then \ echo "TARGET_FOLDER=debug" >>/root/dynenv; \ fi -## Configure cross-build environment if need be -#RUN set -x && \ -# if [ "$TARGETPLATFORM" != "$BUILDPLATFORM" ]; then \ -# . /root/dynenv && \ -# apt install -y gcc-$DEBIAN_ARCH_TRIPLET binutils-$DEBIAN_ARCH_TRIPLET && \ -# rustup target add "$RUST_ARCH_TRIPLET" && \ -# : https://github.com/rust-lang/cargo/issues/4133 && \ -# echo "RUSTFLAGS='-C linker=$DEBIAN_ARCH_TRIPLET-gcc'; export RUSTFLAGS" >>/root/dynenv; \ -# fi +# Configure cross-build environment if need be +RUN set -x && \ + if [ "$TARGETPLATFORM" != "$BUILDPLATFORM" ]; then \ + . /root/dynenv && \ + apt install -y gcc-$DEBIAN_ARCH_TRIPLET binutils-$DEBIAN_ARCH_TRIPLET && \ + rustup target add "$RUST_ARCH_TRIPLET" && \ + : https://github.com/rust-lang/cargo/issues/4133 && \ + echo "RUSTFLAGS='-C linker=$DEBIAN_ARCH_TRIPLET-gcc'; export RUSTFLAGS" >>/root/dynenv; \ + fi # Build RUN set -x && \ - cargo xtask release-runtime 600 - -## Run tests if requested, expted when cross-building -#ARG cucumber=0 -#RUN if [ "$cucumber" != 0 ] && [ "$TARGETPLATFORM" = "$BUILDPLATFORM" ]; then \ -# cargo test --workspace --exclude duniter-end2end-tests --exclude duniter-live-tests && \ -# cargo cucumber -i account_creation* && \ -# cargo cucumber -i certification* && \ -# cargo cucumber -i identity_creation* && \ -# cargo cucumber -i monetary_mass* && \ -# cargo cucumber -i oneshot_account* && \ -# cargo cucumber -i transfer_all* && \ -# cd target/debug/deps/ && \ -# rm cucumber_tests-*.d && \ -# mv cucumber_tests* ../../../build/duniter-cucumber; \ -# fi + cat /root/dynenv && \ + . /root/dynenv && \ + cargo build --locked $CARGO_OPTIONS --target "$RUST_ARCH_TRIPLET" && \ + mkdir -p build && \ + mv target/$RUST_ARCH_TRIPLET/$TARGET_FOLDER/duniter build/ + +# Run tests if requested, expted when cross-building +ARG cucumber=0 +RUN if [ "$cucumber" != 0 ] && [ "$TARGETPLATFORM" = "$BUILDPLATFORM" ]; then \ + cargo test --workspace --exclude duniter-end2end-tests --exclude duniter-live-tests && \ + cargo cucumber -i account_creation* && \ + cargo cucumber -i certification* && \ + cargo cucumber -i identity_creation* && \ + cargo cucumber -i monetary_mass* && \ + cargo cucumber -i oneshot_account* && \ + cargo cucumber -i transfer_all* && \ + cd target/debug/deps/ && \ + rm cucumber_tests-*.d && \ + mv cucumber_tests* ../../../build/duniter-cucumber; \ + fi # ------------------------------------------------------------------------------ # Final Stage