From c176e2a4231d0f03f32e23f88c17f062b9da2ff7 Mon Sep 17 00:00:00 2001 From: Gustavo Valverde Date: Wed, 2 Mar 2022 20:39:41 -0400 Subject: [PATCH] feat(build): add arm64 support with cross-compilation (#3678) * add(actions): lightwalletd continous integrations * refactor(actions): build lightwalletd and reuse it in zebra - Download lightwalletd source code - Create a new Dockerfile for lightwalletd - Use lightwalletd binary in Zebra's image - Create a specific step to build/update lightwalletd - Add lightwalletd integration test to the test suite - Remove lightwalletd.yml, as it was harder to control * refactor(docker): organize Dockerfiles and remove unused Fixes: #3344 * feat(build): add arrm64 support * fix(build): do not install google-compute-engine in arm64 This package is not available for this platform * fix(build): do not build arm64 for tests * fix(condition): indent for better visibility * fix(condition): wrong use of operators --- .github/workflows/cd.yml | 11 +++++++++++ .github/workflows/test.yml | 3 +-- .github/workflows/zcash-lightwalletd.yml | 11 +++++++++++ .github/workflows/zcash-params.yml | 11 +++++++++++ docker/Dockerfile | 22 +++++++++++++--------- 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 85c8f8677..aed719aca 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -42,8 +42,16 @@ jobs: with: credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }} + - name: Set up QEMU + id: qemu + uses: docker/setup-qemu-action@v1 + with: + image: tonistiigi/binfmt:latest + platforms: all + # Setup Docker Buildx to allow use of docker cache layers from GH - name: Set up Docker Buildx + id: buildx uses: docker/setup-buildx-action@v1 - name: Login to Google Artifact Registry @@ -68,6 +76,9 @@ jobs: target: runtime context: . file: ./docker/Dockerfile + platforms: | + linux/amd64 + linux/arm64 tags: | ${{ env.GAR_BASE }}/${{ env.GITHUB_HEAD_REF_SLUG_URL || env.GITHUB_REF_SLUG_URL }}:latest ${{ env.GAR_BASE }}/${{ env.GITHUB_HEAD_REF_SLUG_URL || env.GITHUB_REF_SLUG_URL }}:${{ env.GITHUB_SHA_SHORT }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 364bb98b9..df8b38f4c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -64,9 +64,8 @@ jobs: # Setup Docker Buildx to allow use of docker cache layers from GH - name: Set up Docker Buildx + id: buildx uses: docker/setup-buildx-action@v1 - with: - driver-opts: network=host - name: Login to Google Artifact Registry uses: docker/login-action@v1.12.0 diff --git a/.github/workflows/zcash-lightwalletd.yml b/.github/workflows/zcash-lightwalletd.yml index 020df6c12..b00da49bf 100644 --- a/.github/workflows/zcash-lightwalletd.yml +++ b/.github/workflows/zcash-lightwalletd.yml @@ -46,8 +46,16 @@ jobs: with: credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }} + - name: Set up QEMU + id: qemu + uses: docker/setup-qemu-action@v1 + with: + image: tonistiigi/binfmt:latest + platforms: all + # Setup Docker Buildx to allow use of docker cache layers from GH - name: Set up Docker Buildx + id: buildx uses: docker/setup-buildx-action@v1 - name: Login to Google Artifact Registry @@ -65,6 +73,9 @@ jobs: target: build context: . file: ./zebra/docker/zcash-lightwalletd/Dockerfile + platforms: | + linux/amd64 + linux/arm64 tags: | ${{ env.GAR_BASE }}/${{ env.IMAGE_NAME }}:latest ${{ env.GAR_BASE }}/${{ env.IMAGE_NAME }}:${{ env.GITHUB_SHA_SHORT }} diff --git a/.github/workflows/zcash-params.yml b/.github/workflows/zcash-params.yml index b77046294..b82e47ed2 100644 --- a/.github/workflows/zcash-params.yml +++ b/.github/workflows/zcash-params.yml @@ -42,8 +42,16 @@ jobs: with: credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }} + - name: Set up QEMU + id: qemu + uses: docker/setup-qemu-action@v1 + with: + image: tonistiigi/binfmt:latest + platforms: all + # Setup Docker Buildx to allow use of docker cache layers from GH - name: Set up Docker Buildx + id: buildx uses: docker/setup-buildx-action@v1 - name: Login to Google Artifact Registry @@ -61,6 +69,9 @@ jobs: target: builder context: . file: ./docker/zcash-params/Dockerfile + platforms: | + linux/amd64 + linux/arm64 tags: | ${{ env.GAR_BASE }}/${{ env.IMAGE_NAME }}:latest ${{ env.GAR_BASE }}/${{ env.IMAGE_NAME }}:${{ env.GITHUB_SHA_SHORT }} diff --git a/docker/Dockerfile b/docker/Dockerfile index 359a924d7..6d4cb15af 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -14,6 +14,7 @@ COPY . . RUN cargo chef prepare --recipe-path recipe.json FROM chef AS builder +SHELL ["/bin/bash", "-xo", "pipefail", "-c"] COPY --from=planner /app/recipe.json recipe.json # Install zebra build deps @@ -27,15 +28,18 @@ RUN apt-get -qq update && \ rm -rf /var/lib/apt/lists/* /tmp/* # Install google OS Config agent -RUN apt-get -qq update && \ - apt-get -qq install -y --no-install-recommends \ - curl \ - lsb-release \ - ; \ - echo "deb http://packages.cloud.google.com/apt google-compute-engine-$(lsb_release -cs)-stable main" > /etc/apt/sources.list.d/google-compute-engine.list && \ - curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \ - apt-get -qq update && \ - apt-get -qq install -y --no-install-recommends google-osconfig-agent && \ +RUN if [ "$(uname -m)" != "aarch64" ]; then \ + apt-get -qq update && \ + apt-get -qq install -y --no-install-recommends \ + curl \ + lsb-release \ + && \ + echo "deb http://packages.cloud.google.com/apt google-compute-engine-$(lsb_release -cs)-stable main" > /etc/apt/sources.list.d/google-compute-engine.list && \ + curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \ + apt-get -qq update && \ + apt-get -qq install -y --no-install-recommends google-osconfig-agent; \ + fi \ + && \ rm -rf /var/lib/apt/lists/* /tmp/* # Optimize builds. In particular, regenerate-stateful-test-disks.yml was reaching the