diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d5b909fde..82aedf260 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -27,6 +27,9 @@ jobs: - name: Checkout sources uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -57,6 +60,7 @@ jobs: - name: Build and push pgo worker uses: docker/build-push-action@v5 with: + platforms: linux/amd64,linux/arm64 context: . file: pgo-worker.Dockerfile push: true @@ -174,6 +178,9 @@ jobs: - name: Checkout sources uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -220,6 +227,7 @@ jobs: - name: Build and push worker uses: docker/build-push-action@v5 with: + platforms: linux/amd64,linux/arm64 context: . # file: optimized-worker.Dockerfile file: Dockerfile @@ -232,6 +240,7 @@ jobs: - name: Build and push leader uses: docker/build-push-action@v5 with: + platforms: linux/amd64,linux/arm64 context: . file: Dockerfile push: true diff --git a/Dockerfile b/Dockerfile index 6dadd1d24..7dc84f221 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,10 +13,14 @@ # - `/output` is where the binaries go. ARG BUILD_BASE=rustlang/rust:nightly-bullseye-slim -FROM ${BUILD_BASE} AS build +FROM --platform=$BUILDPLATFORM ${BUILD_BASE} AS build +ARG TARGETPLATFORM +ARG TARGETARCH +ARG BUILDPLATFORM # Install build dependencies. -RUN apt-get update && apt-get install -y \ +RUN dpkg add --add-architecture arm64 && \ + apt-get update && apt-get install -y \ # for jemalloc libjemalloc-dev \ libjemalloc2 \ @@ -24,6 +28,10 @@ RUN apt-get update && apt-get install -y \ # for openssl libssl-dev \ pkg-config \ + # for cross compilation + libssl-dev:arm64 \ + gcc-aarch64-linux-gnu \ + && rustup target add aarch64-unknown-linux-gnu \ # clean the image && rm -rf /var/lib/apt/lists/* @@ -48,9 +56,17 @@ set -eux # .cargo/config.toml cd /src +TARGET="" +case ${TARGETARCH} in \ + arm64) TARGET="aarch64-unknown-linux-gnu" ;; \ + amd64) TARGET="x86_64-unknown-linux-gnu" ;; \ + *) exit 1 ;; \ +esac + # use the cache mount # (we will not be able to to write to e.g `/src/target` because it is bind-mounted) -CARGO_TARGET_DIR=/artifacts cargo build --locked "--profile=${PROFILE}" --all +CARGO_TARGET_DIR=/artifacts cargo build --locked "--profile=${PROFILE}" "--target=${TARGET}" --all + # narrow the find call to SUBDIR because if we just copy out all executables # we will break the cache invariant if [ "$PROFILE" = "dev" ]; then diff --git a/optimized-worker.Dockerfile b/optimized-worker.Dockerfile index 33144a42d..4a0a79780 100644 --- a/optimized-worker.Dockerfile +++ b/optimized-worker.Dockerfile @@ -14,10 +14,14 @@ # - `/output` is where the binaries go. ARG BUILD_BASE=rustlang/rust:nightly-bullseye-slim -FROM ${BUILD_BASE} AS build +FROM --platform=$BUILDPLATFORM ${BUILD_BASE} AS build +ARG TARGETPLATFORM +ARG TARGETARCH +ARG BUILDPLATFORM # Install build dependencies. -RUN apt-get update && apt-get install -y \ +RUN dpkg add --add-architecture arm64 && \ + apt-get update && apt-get install -y \ # for jemalloc libjemalloc-dev \ libjemalloc2 \ @@ -25,6 +29,10 @@ RUN apt-get update && apt-get install -y \ # for openssl libssl-dev \ pkg-config \ + # for cross compilation + libssl-dev:arm64 \ + gcc-aarch64-linux-gnu \ + && rustup target add aarch64-unknown-linux-gnu \ # clean the image && rm -rf /var/lib/apt/lists/* @@ -51,12 +59,19 @@ set -eux # .cargo/config.toml cd /src +TARGET="" +case ${TARGETARCH} in \ + arm64) TARGET="aarch64-unknown-linux-gnu" ;; \ + amd64) TARGET="x86_64-unknown-linux-gnu" ;; \ + *) exit 1 ;; \ +esac + mkdir -p /artifacts/pgo-profiles cp -r pgo-profiles/* /artifacts/pgo-profiles # use the cache mount # (we will not be able to to write to e.g `/src/target` because it is bind-mounted) -CARGO_TARGET_DIR=/artifacts cargo pgo optimize build -- --bin worker --locked "--profile=${PROFILE}" --target=x86_64-unknown-linux-gnu +CARGO_TARGET_DIR=/artifacts cargo pgo optimize build -- --bin worker --locked "--profile=${PROFILE}" "--target=${TARGET}" # narrow the find call to SUBDIR because if we just copy out all executables # we will break the cache invariant @@ -72,7 +87,7 @@ find /artifacts/ -print -ls mkdir /output -cp /artifacts/x86_64-unknown-linux-gnu/release/worker /output/worker +cp /artifacts/$TARGET/release/worker /output/worker ls -lha /output EOF diff --git a/pgo-worker.Dockerfile b/pgo-worker.Dockerfile index cbc34ebf0..85bfe3194 100644 --- a/pgo-worker.Dockerfile +++ b/pgo-worker.Dockerfile @@ -7,9 +7,13 @@ ARG BUILD_BASE=rustlang/rust:nightly-bullseye-slim FROM ${BUILD_BASE} AS build +ARG TARGETPLATFORM +ARG TARGETARCH +ARG BUILDPLATFORM # Install build dependencies. -RUN apt-get update && apt-get install -y \ +RUN dpkg add --add-architecture arm64 && \ + apt-get update && apt-get install -y \ # for jemalloc libjemalloc-dev \ libjemalloc2 \ @@ -17,8 +21,13 @@ RUN apt-get update && apt-get install -y \ # for openssl libssl-dev \ pkg-config \ + # for cross compilation + libssl-dev:arm64 \ + gcc-aarch64-linux-gnu \ + && rustup target add aarch64-unknown-linux-gnu \ # clean the image python3 python3-pip \ + python3:arm64 python3-pip:arm64 \ && rm -rf /var/lib/apt/lists/* @@ -42,14 +51,21 @@ RUN \ <