Skip to content

Commit

Permalink
ci: build arm64 docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Nov 19, 2023
1 parent f9ef0ee commit 6cd348e
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 15 deletions.
124 changes: 109 additions & 15 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,59 @@
name: "Build Docker Image"
name: "Build multi-arch images"

on:
create:
push:
tags:
- "v*.*.*"

jobs:
build:
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
crate-info:
name: "Extract crate info"
runs-on: "ubuntu-latest"
outputs:
version: ${{ steps.derive.outputs.version }}

steps:
- id: "derive"
name: "Derive crate info from Git tag"
run: |
FULL_REF="${{ github.ref }}"
REGEX="^refs\/tags\/v(.*)$"
[[ $FULL_REF =~ $REGEX ]];
echo "version=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
build-amd64:
name: "Build for linux/amd64"
runs-on: "ubuntu-latest"
needs:
- "crate-info"

env:
DOCKER_REPOSITORY: "starknet/jsonrpc-to-firestark"

steps:
- name: "Checkout"
uses: "actions/checkout@v3"

- name: "Build Docker image"
run: |
docker build -t ${DOCKER_REPOSITORY}:${{ needs.crate-info.outputs.version }}-amd64 -f ./Dockerfile .
- name: "Export Docker image"
run: |
docker save ${DOCKER_REPOSITORY}:${{ needs.crate-info.outputs.version }}-amd64 | gzip > /tmp/amd64.tar.gz
- name: "Upload Docker image artifact"
uses: "actions/upload-artifact@v3"
with:
name: "amd64.tar.gz"
path: "/tmp/amd64.tar.gz"

name: "Build"
build-arm64:
name: "Build for linux/arm64"
runs-on: "ubuntu-latest"
needs:
- "crate-info"

env:
DOCKER_REPOSITORY: "starknet/jsonrpc-to-firestark"
Expand All @@ -17,23 +62,72 @@ jobs:
- name: "Checkout"
uses: "actions/checkout@v3"

- name: "Install cross"
run: |
cargo install --locked --version 0.2.5 cross
- name: "Build release"
run: |
cross build --release --target aarch64-unknown-linux-gnu
- name: "Build Docker image"
run: |
docker build -t ${DOCKER_REPOSITORY}:${{ needs.crate-info.outputs.version }}-arm64 -f ./.github/workflows/docker/Dockerfile.arm64 .
- name: "Export Docker image"
run: |
docker save ${DOCKER_REPOSITORY}:${{ needs.crate-info.outputs.version }}-arm64 | gzip > /tmp/arm64.tar.gz
- name: "Upload Docker image artifact"
uses: "actions/upload-artifact@v3"
with:
name: "arm64.tar.gz"
path: "/tmp/arm64.tar.gz"

push:
name: "Push multi-arch manifest"
runs-on: "ubuntu-latest"
needs:
- "build-amd64"
- "build-arm64"
- "crate-info"

env:
DOCKER_REPOSITORY: "ghcr.io/zklend/zklend-v1-dev-deploy"

steps:
- name: "Login to Docker Hub"
uses: "docker/[email protected]"
with:
username: "${{ secrets.DOCKER_HUB_USERNAME }}"
password: "${{ secrets.DOCKER_HUB_PASSWORD }}"

- name: "Determine image version"
run: |
version_line="${{ github.ref }}"
regex="^refs\/tags\/v(.*)$"
[[ $version_line =~ $regex ]];
echo "VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
- name: "Download linux/amd64 image"
uses: "actions/download-artifact@v3"
with:
name: "amd64.tar.gz"
path: "/tmp/amd64.tar.gz"

- name: "Build Docker image"
- name: "Download linux/arm64/v8 image"
uses: "actions/download-artifact@v3"
with:
name: "arm64.tar.gz"
path: "/tmp/arm64.tar.gz"

- name: "Load Docker images"
run: |
docker build -t ${DOCKER_REPOSITORY}:${VERSION} -f ./Dockerfile .
docker load --input /tmp/amd64.tar.gz
docker load --input /tmp/arm64.tar.gz
- name: "Push Docker image"
- name: "Push Docker images"
run: |
docker push ${DOCKER_REPOSITORY}:${VERSION}
docker push ${DOCKER_REPOSITORY}:${{ needs.crate-info.outputs.version }}-amd64
docker push ${DOCKER_REPOSITORY}:${{ needs.crate-info.outputs.version }}-arm64
docker manifest create ${DOCKER_REPOSITORY}:${{ needs.crate-info.outputs.version }} \
${DOCKER_REPOSITORY}:${{ needs.crate-info.outputs.version }}-amd64 \
${DOCKER_REPOSITORY}:${{ needs.crate-info.outputs.version }}-arm64
docker manifest create ${DOCKER_REPOSITORY}:latest \
${DOCKER_REPOSITORY}:${{ needs.crate-info.outputs.version }}-amd64 \
${DOCKER_REPOSITORY}:${{ needs.crate-info.outputs.version }}-arm64
docker manifest push ${DOCKER_REPOSITORY}:${{ needs.crate-info.outputs.version }}
docker manifest push ${DOCKER_REPOSITORY}:latest build:
7 changes: 7 additions & 0 deletions .github/workflows/docker/Dockerfile.arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM --platform=linux/arm64/v8 debian:bullseye-slim

LABEL org.opencontainers.image.source=https://github.com/starknet-graph/jsonrpc-to-firestark

COPY ./target/aarch64-unknown-linux-gnu/release/jsonrpc-to-firestark /usr/bin/

ENTRYPOINT [ "jsonrpc-to-firestark" ]
4 changes: 4 additions & 0 deletions .github/workflows/docker/Dockerfile.arm64.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target/
/.dockerignore
/Dockerfile
!/target/aarch64-unknown-linux-gnu/release/jsonrpc-to-firestark

0 comments on commit 6cd348e

Please sign in to comment.