From 303f9cb411827e94767f9a07ffd4194c7b3e0551 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 10 May 2024 21:20:51 +0100 Subject: [PATCH] Use docker command only around native build Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .github/workflows/build_and_test.yaml | 10 +++++++ .github/workflows/build_linux.yaml | 41 +++++++++++---------------- .github/workflows/dockerbuild.yaml | 9 ++++++ dockerbuild/Dockerfile | 9 ++++-- dockerbuild/aarch64.sh | 9 ++++++ 5 files changed, 52 insertions(+), 26 deletions(-) create mode 100755 dockerbuild/aarch64.sh diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index 1a364673..9a409bfc 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -45,6 +45,15 @@ jobs: with: files: | dockerbuild/** + + - name: Set up QEMU + uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3 + with: + install: true + - name: Log in to the Container registry if: steps.changed_files.outputs.any_modified == 'true' uses: docker/login-action@5f4866a30a54f16a52d2ecb4a3898e9e424939cf @@ -68,6 +77,7 @@ jobs: context: dockerbuild push: true tags: ${{ steps.docker.outputs.image }} + platforms: linux/amd64,linux/arm64 linux: needs: diff --git a/.github/workflows/build_linux.yaml b/.github/workflows/build_linux.yaml index a5383b60..29307ce8 100644 --- a/.github/workflows/build_linux.yaml +++ b/.github/workflows/build_linux.yaml @@ -27,8 +27,6 @@ on: jobs: build: runs-on: ubuntu-latest - container: - image: ${{ inputs.docker-image || format('ghcr.io/element-hq/element-desktop-dockerbuild:{0}', github.ref_name == 'master' && 'master' || 'develop') }} defaults: run: shell: bash @@ -47,7 +45,8 @@ jobs: "arm64": { "target": "aarch64-unknown-linux-gnu", "arch": "aarch64", - "build-args": "--arm64" + "build-args": "--arm64", + "docker-args": "--env-file ./dockerbuild/aarch64/.env" } } @@ -77,30 +76,24 @@ jobs: - name: Install Deps run: "yarn install --frozen-lockfile" - - name: Prepare for static sqlcipher build - if: inputs.sqlcipher == 'static' - run: | - echo "SQLCIPHER_BUNDLED=1" >> $GITHUB_ENV - - - name: Prepare for cross compilation - if: steps.cache.outputs.cache-hit != 'true' && inputs.arch == 'arm64' - run: | - rustup target add aarch64-unknown-linux-gnu - mv dockerbuild/aarch64/.cargo . - cat dockerbuild/aarch64/.env >> $GITHUB_ENV - - # Ideally the docker image would be ready for cross-compilation but libsqlcipher-dev is not Multi-Arch compatible - # https://unix.stackexchange.com/a/349359 - - name: Prepare for cross compilation (dynamic) - if: steps.cache.outputs.cache-hit != 'true' && inputs.arch == 'arm64' && inputs.sqlcipher == 'system' - run: | - dpkg --add-architecture arm64 - apt-get -qq update - apt-get -qq install --no-install-recommends libsqlcipher-dev:arm64 libssl-dev:arm64 libsecret-1-dev:arm64 + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + if: steps.cache.outputs.cache-hit != 'true' && inputs.arch != 'amd64' + with: + platforms: ${{ matrix.arch }} - name: Build Natives if: steps.cache.outputs.cache-hit != 'true' - run: "yarn build:native --target ${{ steps.config.outputs.target }}" + run: | + docker run \ + --rm \ + -v $(pwd):/${{ github.workspace }} \ + -w ${{ github.workspace }} \ + --platform linux/${{ matrix.arch }} \ + ${{ inputs.docker-image || format('ghcr.io/element-hq/element-desktop-dockerbuild:{0}', github.ref_name == 'master' && 'master' || 'develop') }} \ + ${{ steps.config.outputs.docker-args }} \ + -e SQLCIPHER_BUNDLED=${{ inputs.sqlcipher == 'static' && '1' || '0' }} \ + yarn build:native --target ${{ steps.config.outputs.target }} - name: "[Nightly] Resolve version" if: inputs.version != '' diff --git a/.github/workflows/dockerbuild.yaml b/.github/workflows/dockerbuild.yaml index 7a70c7cf..42d9f827 100644 --- a/.github/workflows/dockerbuild.yaml +++ b/.github/workflows/dockerbuild.yaml @@ -19,6 +19,14 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3 + with: + install: true + - name: Log in to the Container registry uses: docker/login-action@5f4866a30a54f16a52d2ecb4a3898e9e424939cf with: @@ -41,3 +49,4 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 diff --git a/dockerbuild/Dockerfile b/dockerbuild/Dockerfile index ddb0adea..b6cb66de 100644 --- a/dockerbuild/Dockerfile +++ b/dockerbuild/Dockerfile @@ -3,6 +3,9 @@ FROM buildpack-deps:buster-curl ENV DEBIAN_FRONTEND noninteractive +# For DinD to work +COPY --from=docker:dind /usr/local/bin/docker /usr/local/bin/ + RUN curl --proto "=https" -L https://yarnpkg.com/latest.tar.gz | tar xvz && mv yarn-* /yarn && ln -s /yarn/bin/yarn /usr/bin/yarn RUN apt-get -qq update && apt-get -qq dist-upgrade && \ # add repo for git-lfs @@ -19,8 +22,6 @@ RUN apt-get -qq update && apt-get -qq dist-upgrade && \ jq grep file \ # Used by seshat (when not SQLCIPHER_STATIC) \ libsqlcipher-dev && \ - # Used for cross-compilation - crossbuild-essential-arm64 \ # git-lfs git lfs install && \ apt-get purge -y --auto-remove && rm -rf /var/lib/apt/lists/* @@ -47,3 +48,7 @@ ENV RUSTUP_HOME=/usr/local/rustup \ PATH=/usr/local/cargo/bin:$PATH RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal + +# Run platform-specific tasks +ADD COPY ./dockerbuild/ /dockerbuild/ +RUN /dockerbuild/aarch64.sh diff --git a/dockerbuild/aarch64.sh b/dockerbuild/aarch64.sh new file mode 100755 index 00000000..6173532c --- /dev/null +++ b/dockerbuild/aarch64.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +if [ "$TARGETPLATFORM" = "linux/arm64" ]; then + echo "Building for aarch64" + apt-get -qq update + apt-get -y install crossbuild-essential-arm64 libsqlcipher-dev:arm64 libssl-dev:arm64 libsecret-1-dev:arm64 + rustup target add aarch64-unknown-linux-gnu + mv /dockerbuild/aarch64/.cargo . +fi