From 112cce746a22a5e60aa0f99061c9dd2b4f68d426 Mon Sep 17 00:00:00 2001 From: Tarrence van As Date: Fri, 1 Dec 2023 23:16:52 +0200 Subject: [PATCH] Update release ci approach to use a single docker build step --- .github/workflows/release.yml | 75 ++++++++++------------------------- Dockerfile | 20 +++------- 2 files changed, 27 insertions(+), 68 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4a14f85788..ef0597e95e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -81,6 +81,10 @@ jobs: name: ${{ matrix.job.target }} (${{ matrix.job.os }}) needs: prepare runs-on: ${{ matrix.job.os }} + env: + PLATFORM_NAME: ${{ matrix.job.platform }} + TARGET: ${{ matrix.job.target }} + ARCH: ${{ matrix.job.arch }} strategy: matrix: job: @@ -148,9 +152,6 @@ jobs: - name: Archive binaries id: artifacts env: - PLATFORM_NAME: ${{ matrix.job.platform }} - TARGET: ${{ matrix.job.target }} - ARCH: ${{ matrix.job.arch }} VERSION_NAME: ${{ (env.IS_NIGHTLY == 'true' && 'nightly') || needs.prepare.outputs.tag_name }} run: | if [ "$PLATFORM_NAME" == "linux" ]; then @@ -193,18 +194,22 @@ jobs: files: | ${{ steps.artifacts.outputs.file_name }} + # We move binaries so they match $TARGETPLATFORM in the Docker build + - name: Move Binaries + if: ${{ env.PLATFORM_NAME == 'linux' }} + run: | + mkdir -p $PLATFORM_NAME/$ARCH + mv target/$TARGET/release/katana $PLATFORM_NAME/$ARCH + mv target/$TARGET/release/sozo $PLATFORM_NAME/$ARCH + mv target/$TARGET/release/torii $PLATFORM_NAME/$ARCH + shell: bash + # Upload these for use with the Docker build later - name: Upload binaries uses: actions/upload-artifact@v3 with: name: binaries - path: | - target/x86_64-unknown-linux-gnu/release/katana - target/x86_64-unknown-linux-gnu/release/sozo - target/x86_64-unknown-linux-gnu/release/torii - target/aarch64-unknown-linux-gnu/release/katana - target/aarch64-unknown-linux-gnu/release/sozo - target/aarch64-unknown-linux-gnu/release/torii + path: ${{ env.PLATFORM_NAME }} retention-days: 1 cleanup: @@ -232,8 +237,8 @@ jobs: const prunePrereleases = require('./.github/scripts/prune-prereleases.js') await prunePrereleases({github, context}) - docker-build-and-push-linux-amd64: - name: Build and push linux-amd64 docker image + docker-build-and-push: + name: Build and push docker image runs-on: ubuntu-latest-4-cores needs: [prepare, release] @@ -245,43 +250,10 @@ jobs: uses: actions/download-artifact@v3 with: name: binaries - path: artifacts - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push docker image - uses: docker/build-push-action@v4 - with: - build-contexts: | - artifacts=artifacts - push: true - provenance: false - tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:${{ needs.prepare.outputs.tag_name }} - platforms: linux/amd64 - target: amd64 - - docker-build-and-push-linux-arm64: - name: Build and push linux-arm64 docker image - runs-on: ubuntu-latest-4-cores - needs: [prepare, release] - - steps: - - name: Checkout repository - uses: actions/checkout@v2 + path: artifacts/linux - - name: Download binaries - uses: actions/download-artifact@v3 - with: - name: binaries - path: artifacts + - name: Display structure of downloaded files + run: ls -R - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 @@ -294,13 +266,10 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push docker image - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v3 with: push: true - provenance: false tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:${{ needs.prepare.outputs.tag_name }} - platforms: linux/arm64 - target: arm64 + platforms: linux/amd64,linux/arm64 build-contexts: | artifacts=artifacts - diff --git a/Dockerfile b/Dockerfile index 5d959e7fa8..18c996cead 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,15 @@ FROM debian:bookworm-slim as base +ARG TARGETPLATFORM + LABEL description="Dojo is a provable game engine and toolchain for building onchain games and autonomous worlds with Cairo" \ authors="tarrence " \ source="https://github.com/dojoengine/dojo" \ documentation="https://book.dojoengine.org/" -FROM base as amd64 - -COPY --from=artifacts x86_64-unknown-linux-gnu/release/katana /usr/local/bin/katana -COPY --from=artifacts x86_64-unknown-linux-gnu/release/sozo /usr/local/bin/sozo -COPY --from=artifacts x86_64-unknown-linux-gnu/release/torii /usr/local/bin/torii - -RUN chmod +x /usr/local/bin/katana \ - && chmod +x /usr/local/bin/sozo \ - && chmod +x /usr/local/bin/torii - -FROM base as arm64 - -COPY --from=artifacts aarch64-unknown-linux-gnu/release/katana /usr/local/bin/katana -COPY --from=artifacts aarch64-unknown-linux-gnu/release/sozo /usr/local/bin/sozo -COPY --from=artifacts aarch64-unknown-linux-gnu/release/torii /usr/local/bin/torii +COPY --from=artifacts $TARGETPLATFORM/katana /usr/local/bin/katana +COPY --from=artifacts $TARGETPLATFORM/sozo /usr/local/bin/sozo +COPY --from=artifacts $TARGETPLATFORM/torii /usr/local/bin/torii RUN chmod +x /usr/local/bin/katana \ && chmod +x /usr/local/bin/sozo \