diff --git a/.github/actions/build-docker/action.yml b/.github/actions/build-docker/action.yml index 7fd53835a6e..d0071a4809b 100644 --- a/.github/actions/build-docker/action.yml +++ b/.github/actions/build-docker/action.yml @@ -27,6 +27,10 @@ inputs: description: "The arguments that are sent to the dockerfile to built. Format ARG=value" required: false default: "" + platforms: + description: "Comma-separated list of platforms to build for" + required: false + default: "linux/amd64" outputs: artifact_path: @@ -52,7 +56,8 @@ runs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build Docker image + - id: build-image + name: Build Docker image uses: docker/build-push-action@v6 with: context: . @@ -63,6 +68,7 @@ runs: cache-from: type=gha cache-to: type=gha,mode=max build-args: ${{ inputs.build_args }} + platforms: ${{ inputs.platforms }} # Since we're exporting the image as a tar, we need to load it manually as well - name: Load image locally diff --git a/.github/workflows/tag_latest.yaml b/.github/workflows/tag_latest.yaml index b7ec1da1b6d..72b611728b4 100644 --- a/.github/workflows/tag_latest.yaml +++ b/.github/workflows/tag_latest.yaml @@ -53,25 +53,17 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Download Docker images - run: | - docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PREV_TAG }} - docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PREV_TAG }}-l2 - - name: Retag Docker images run: | - docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PREV_TAG }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.NEW_TAG }} - docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PREV_TAG }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest - docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PREV_TAG }}-l2 ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:l2 - docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PREV_TAG }}-l2 ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.NEW_TAG }}-l2 + docker buildx imagetools create \ + -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.NEW_TAG }} \ + -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PREV_TAG }} + docker buildx imagetools create \ + -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.NEW_TAG }}-l2 \ + -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:l2 \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PREV_TAG }}-l2 - - name: Push retagged Docker images - run: | - docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.NEW_TAG }} - docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest - docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.NEW_TAG }}-l2 - docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:l2 - publish-apt: needs: [retag_docker_images] uses: lambdaclass/ethrex-apt/.github/workflows/publish-apt.yml@main diff --git a/.github/workflows/tag_release.yaml b/.github/workflows/tag_release.yaml index 2c1aa1559dc..a1058e75036 100644 --- a/.github/workflows/tag_release.yaml +++ b/.github/workflows/tag_release.yaml @@ -320,16 +320,25 @@ jobs: path: ethrex-contracts.tar.gz build-docker: - name: "Build and publish ethrex docker image" - runs-on: ubuntu-latest + name: "Build ethrex docker images" + strategy: + matrix: + platform: + - ubuntu-latest + - ubuntu-22.04-arm + include: + - platform: ubuntu-latest + arch: amd64 + - platform: ubuntu-22.04-arm + arch: arm64 + runs-on: ${{ matrix.platform }} + outputs: + tag: ${{ steps.tag_version.outputs.tag }} # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. permissions: contents: read packages: write - attestations: write - id-token: write - actions: write steps: - name: Checkout code @@ -338,38 +347,71 @@ jobs: - name: Free Disk Space uses: ./.github/actions/free-disk - - name: Format name + - name: Determine tag version + id: tag_version run: | # For branch builds (main) we want docker images tagged as 'main'. For tag pushes # use the tag name (stripped of a leading 'v'). if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then echo "TAG_VERSION=main" >> $GITHUB_ENV + echo "tag=main" >> $GITHUB_OUTPUT else echo "TAG_VERSION=$(echo ${{ github.ref_name }} | tr -d v)" >> $GITHUB_ENV + echo "tag=$(echo ${{ github.ref_name }} | tr -d v)" >> $GITHUB_OUTPUT fi - # Pushes to ghcr.io/lambdaclass/ethrex - - name: Build and push L1 Docker image - id: push_l1 + - name: Build L1 Docker image + id: build_l1 uses: ./.github/actions/build-docker with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} push: ${{ github.event_name != 'workflow_dispatch'}} - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG_VERSION }} + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG_VERSION }}-${{ matrix.arch }} + platforms: linux/${{ matrix.arch }} - # Pushes to ghcr.io/lambdaclass/ethrex - - name: Build and push L2 Docker image - id: push_l2 + - name: Build L2 Docker image + id: build_l2 uses: ./.github/actions/build-docker with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} push: ${{ github.event_name != 'workflow_dispatch'}} - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG_VERSION }}-l2 + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG_VERSION }}-l2-${{ matrix.arch }} build_args: BUILD_FLAGS=--features l2,l2-sql + platforms: linux/${{ matrix.arch }} + + publish-docker: + name: "Create and push multi-arch Docker manifests" + runs-on: ubuntu-latest + if: ${{ github.event_name != 'workflow_dispatch'}} + needs: build-docker + + permissions: + packages: write + contents: read + + steps: + - name: Login to Docker registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create multi-arch image + run: | + docker buildx imagetools create \ + -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build-docker.outputs.tag }} \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build-docker.outputs.tag }}-amd64 \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build-docker.outputs.tag }}-arm64 + + docker buildx imagetools create \ + -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build-docker.outputs.tag }}-l2 \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build-docker.outputs.tag }}-l2-amd64 \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build-docker.outputs.tag }}-l2-arm64 # Creates a release on GitHub with the binaries finalize-release: @@ -378,6 +420,7 @@ jobs: - build-ethrex - build-ethrex-guest - build-docker + - publish-docker - package-contracts - package-ethrex-guest runs-on: ubuntu-latest diff --git a/Dockerfile b/Dockerfile index 4ae6ee881fd..0c0c400e63a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,7 +36,13 @@ FROM chef AS builder COPY --from=planner /ethrex/recipe.json recipe.json RUN cargo chef cook --release --recipe-path recipe.json -RUN curl -L -o /usr/bin/solc https://github.com/ethereum/solidity/releases/download/v0.8.29/solc-static-linux \ +RUN if [ "$(uname -m)" = aarch64 ]; \ + then \ + SOLC_URL=https://github.com/nikitastupin/solc/raw/refs/heads/main/linux/aarch64/solc-v0.8.29;\ + else \ + SOLC_URL=https://github.com/ethereum/solidity/releases/download/v0.8.29/solc-static-linux; \ + fi \ + && curl -L -o /usr/bin/solc $SOLC_URL \ && chmod +x /usr/bin/solc COPY benches ./benches