Skip to content

fix: added arm64 build to ci and manifest creation #29

fix: added arm64 build to ci and manifest creation

fix: added arm64 build to ci and manifest creation #29

name: Build and Push Docker Image
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
on:
workflow_dispatch:
inputs:
shardeum_branch:
description: 'Shardeum repository branch'
required: true
default: 'dev'
relayer_collector_branch:
description: 'Relayer collector repository branch'
required: true
default: 'dev'
json_rpc_server_branch:
description: 'JSON RPC server repository branch'
required: true
default: 'dev'
image_tag:
description: 'Docker image tag'
required: true
default: 'dev'
push_latest:
description: 'Push latest tag'
type: boolean
required: true
default: false
pull_request:
branches: [ main ]
permissions:
contents: read
packages: write
jobs:
build:
strategy:
matrix:
include:
- arch: amd64
runner: ubuntu-latest
- arch: arm64
runner: macos-13
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- if: matrix.runner == 'macos-13'
uses: douglascamata/[email protected]
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set build args and tags
id: build_config
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "SHARDEUM_BRANCH=dev" >> $GITHUB_OUTPUT
echo "RELAYER_COLLECTOR_BRANCH=dev" >> $GITHUB_OUTPUT
echo "JSON_RPC_SERVER_BRANCH=dev" >> $GITHUB_OUTPUT
echo "IMAGE_TAG=pr-preview-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
else
echo "SHARDEUM_BRANCH=${{ inputs.shardeum_branch }}" >> $GITHUB_OUTPUT
echo "RELAYER_COLLECTOR_BRANCH=${{ inputs.relayer_collector_branch }}" >> $GITHUB_OUTPUT
echo "JSON_RPC_SERVER_BRANCH=${{ inputs.json_rpc_server_branch }}" >> $GITHUB_OUTPUT
echo "IMAGE_TAG=${{ inputs.image_tag }}" >> $GITHUB_OUTPUT
fi
- name: Build Docker image
run: |
docker build \
--platform linux/${{ matrix.arch }} \
--build-arg SHARDEUM_BRANCH=${{ steps.build_config.outputs.SHARDEUM_BRANCH }} \
--build-arg RELAYER_COLLECTOR_BRANCH=${{ steps.build_config.outputs.RELAYER_COLLECTOR_BRANCH }} \
--build-arg JSON_RPC_SERVER_BRANCH=${{ steps.build_config.outputs.JSON_RPC_SERVER_BRANCH }} \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.arch }}:${{ steps.build_config.outputs.IMAGE_TAG }} \
.
- name: Push Docker image
run: |
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.arch }}:${{ steps.build_config.outputs.IMAGE_TAG }}
if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ "${{ inputs.push_latest }}" == "true" ]; then
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.arch }}:${{ steps.build_config.outputs.IMAGE_TAG }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.arch }}:latest
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.arch }}:latest
fi
create-manifest:
needs: build
runs-on: ubuntu-latest
steps:
- name: Set image tag
id: build_config
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "IMAGE_TAG=pr-preview-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
else
echo "IMAGE_TAG=${{ inputs.image_tag }}" >> $GITHUB_OUTPUT
fi
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push manifest
run: |
docker manifest create ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.build_config.outputs.IMAGE_TAG }} \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-amd64:${{ steps.build_config.outputs.IMAGE_TAG }} \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-arm64:${{ steps.build_config.outputs.IMAGE_TAG }}
docker manifest push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.build_config.outputs.IMAGE_TAG }}
if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ "${{ inputs.push_latest }}" == "true" ]; then
docker manifest create ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-amd64:latest \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-arm64:latest
docker manifest push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
fi