Skip to content

Commit

Permalink
Merge pull request #12 from shardeum/fix/ci-arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejonas authored Jan 16, 2025
2 parents 47f38ab + 50356a2 commit e12d7f3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 62 deletions.
114 changes: 56 additions & 58 deletions .github/workflows/trigger_build_push.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Build and Push Docker Image

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

on:
workflow_dispatch:
inputs:
Expand Down Expand Up @@ -27,22 +31,23 @@ on:
pull_request:
branches: [ main ]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
permissions:
contents: read
packages: write

jobs:
build-and-push:
runs-on: ubuntu-latest
timeout-minutes: 120
permissions:
contents: read
packages: write
pull-requests: write

build:
strategy:
matrix:
include:
- arch: amd64
runner: [self-hosted, Linux, X64]
- arch: arm64
runner: [self-hosted, Linux, ARM64]
runs-on: ${{ matrix.runner }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
Expand All @@ -51,19 +56,6 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Determine architecture
id: arch
run: |
ARCH=$(uname -m)
if [ "$ARCH" == "aarch64" ] || [ "$ARCH" == "arm64" ]; then
echo "ARCH_TAG=arm64" >> $GITHUB_OUTPUT
elif [ "$ARCH" == "x86_64" ]; then
echo "ARCH_TAG=amd64" >> $GITHUB_OUTPUT
else
echo "Unsupported architecture: $ARCH. Exiting."
exit 1
fi
- name: Set build args and tags
id: build_config
run: |
Expand All @@ -78,49 +70,55 @@ jobs:
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: |
TAGS="-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ steps.arch.outputs.ARCH_TAG }}:${{ steps.build_config.outputs.IMAGE_TAG }}"
if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ "${{ inputs.push_latest }}" == "true" ]; then
TAGS="$TAGS -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ steps.arch.outputs.ARCH_TAG }}:latest"
fi
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 }} \
$TAGS \
-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 }}-${{ steps.arch.outputs.ARCH_TAG }}:${{ steps.build_config.outputs.IMAGE_TAG }}
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 push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ steps.arch.outputs.ARCH_TAG }}:latest
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
- name: Comment PR with Docker instructions
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
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:
script: |
const imageTag = 'pr-preview-${{ github.event.pull_request.number }}';
const comment = `
### 🐳 Docker Image Preview Available
You can test this PR using the following Docker image:
\`\`\`bash
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ steps.arch.outputs.ARCH_TAG }}:${imageTag}
docker run -it ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ steps.arch.outputs.ARCH_TAG }}:${imageTag}
\`\`\`
> Note: This image was built for ${{ steps.arch.outputs.ARCH_TAG }} architecture
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
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
4 changes: 0 additions & 4 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ apt-get update && apt-get install -y \
python3 \
&& rm -rf /var/lib/apt/lists/*

# Install node-gyp
npm install -g [email protected]

# Install Rust 1.74.1
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.74.1
source $HOME/.cargo/env
Expand All @@ -22,4 +19,3 @@ npm --version
python3 --version
rustc --version
cargo --version
node-gyp --version

0 comments on commit e12d7f3

Please sign in to comment.