diff --git a/.github/workflows/snapshot-build.yml b/.github/workflows/snapshot-build.yml index 7420f0fa7cc..dba04fe5b8f 100644 --- a/.github/workflows/snapshot-build.yml +++ b/.github/workflows/snapshot-build.yml @@ -33,6 +33,9 @@ jobs: - image: node base-artifact: subspace-node upload-executables: true + - image: gateway + base-artifact: subspace-gateway + upload-executables: false - image: bootstrap-node base-artifact: subspace-bootstrap-node upload-executables: false @@ -104,7 +107,6 @@ jobs: cd executables IMAGE="${{ fromJSON(steps.meta.outputs.json).tags[0] }}" ARTIFACT="${{ matrix.build.base-artifact }}" - docker run --rm --platform linux/amd64 --entrypoint /bin/cat $IMAGE /$ARTIFACT > $ARTIFACT-ubuntu-x86_64-skylake-${{ github.ref_name }} # TODO: Pull is a workaround for https://github.com/moby/moby/issues/48197#issuecomment-2472265028 docker pull --platform linux/amd64/v2 $IMAGE diff --git a/docker/gateway.Dockerfile b/docker/gateway.Dockerfile new file mode 100644 index 00000000000..85f4c62f1c1 --- /dev/null +++ b/docker/gateway.Dockerfile @@ -0,0 +1,109 @@ +# This Dockerfile supports both native building and cross-compilation to x86-64, aarch64 and riscv64 +FROM --platform=$BUILDPLATFORM ubuntu:22.04 + +ARG RUSTC_VERSION=nightly-2024-10-22 +ARG PROFILE=production +ARG RUSTFLAGS +# Incremental compilation here isn't helpful +ENV CARGO_INCREMENTAL=0 +ENV PKG_CONFIG_ALLOW_CROSS=true + +ARG BUILDARCH +ARG TARGETARCH + +WORKDIR /code + +RUN \ + apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + ca-certificates \ + protobuf-compiler \ + curl \ + git \ + llvm \ + clang \ + automake \ + libtool \ + pkg-config \ + make + +RUN \ + if [ $BUILDARCH != "arm64" ] && [ $TARGETARCH = "arm64" ]; then \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + g++-aarch64-linux-gnu \ + gcc-aarch64-linux-gnu \ + libc6-dev-arm64-cross \ + ; fi + +RUN \ + if [ $BUILDARCH != "riscv64" ] && [ $TARGETARCH = "riscv64" ]; then \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + g++-riscv64-linux-gnu \ + gcc-riscv64-linux-gnu \ + libc6-dev-riscv64-cross \ + ; fi + +RUN \ + if [ $BUILDARCH != "amd64" ] && [ $TARGETARCH = "amd64" ]; then \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + g++-x86-64-linux-gnu \ + gcc-x86-64-linux-gnu \ + libc6-dev-amd64-cross \ + ; fi + +RUN \ + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUSTC_VERSION && \ + /root/.cargo/bin/rustup target add wasm32-unknown-unknown + +COPY Cargo.lock /code/Cargo.lock +COPY Cargo.toml /code/Cargo.toml +COPY rust-toolchain.toml /code/rust-toolchain.toml + +COPY crates /code/crates +COPY domains /code/domains +COPY shared /code/shared +COPY test /code/test + +# Up until this line all Rust images in this repo should be the same to share the same layers + +ARG TARGETVARIANT + +RUN \ + if [ $BUILDARCH != "arm64" ] && [ $TARGETARCH = "arm64" ]; then \ + export RUSTFLAGS="$RUSTFLAGS -C linker=aarch64-linux-gnu-gcc" \ + ; fi && \ + if [ $BUILDARCH != "riscv64" ] && [ $TARGETARCH = "riscv64" ]; then \ + export RUSTFLAGS="$RUSTFLAGS -C linker=riscv64-linux-gnu-gcc" \ + ; fi && \ + if [ $TARGETARCH = "amd64" ] && [ "$RUSTFLAGS" = "" ]; then \ + case "$TARGETVARIANT" in \ + # x86-64-v2 with AES-NI + "v2") export RUSTFLAGS="-C target-cpu=x86-64-v2" ;; \ + # x86-64-v3 with AES-NI + "v3") export RUSTFLAGS="-C target-cpu=x86-64-v3 -C target-feature=+aes" ;; \ + # v4 is compiled for Zen 4+ + "v4") export RUSTFLAGS="-C target-cpu=znver4" ;; \ + # Default build is for Skylake + *) export RUSTFLAGS="-C target-cpu=skylake" ;; \ + esac \ + ; fi && \ + if [ $BUILDARCH != "amd64" ] && [ $TARGETARCH = "amd64" ]; then \ + export RUSTFLAGS="$RUSTFLAGS -C linker=x86_64-linux-gnu-gcc" \ + ; fi && \ + RUSTC_TARGET_ARCH=$(echo $TARGETARCH | sed "s/amd64/x86_64/g" | sed "s/arm64/aarch64/g" | sed "s/riscv64/riscv64gc/g") && \ + /root/.cargo/bin/cargo -Zgitoxide -Zgit build \ + --locked \ + -Z build-std \ + --profile $PROFILE \ + --bin subspace-gateway \ + --target $RUSTC_TARGET_ARCH-unknown-linux-gnu && \ + mv target/*/*/subspace-gateway subspace-gateway && \ + rm -rf target + +FROM ubuntu:22.04 + +COPY --from=0 /code/subspace-gateway /subspace-gateway + +USER nobody:nogroup + +ENTRYPOINT ["/subspace-gateway"] diff --git a/docker/gateway.Dockerfile.dockerignore b/docker/gateway.Dockerfile.dockerignore new file mode 100644 index 00000000000..983f1aefffc --- /dev/null +++ b/docker/gateway.Dockerfile.dockerignore @@ -0,0 +1,9 @@ +* +!/crates +!/domains +!/orml +!/shared +!/test +!/Cargo.lock +!/Cargo.toml +!/rust-toolchain.toml