Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(CI): Unified mulitplatform namespace && dev container support #64

Merged
merged 10 commits into from
Feb 18, 2025
72 changes: 72 additions & 0 deletions .github/actions/docker-image/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: EigenDA Docker Image

inputs:
context:
required: true
type: string
images:
required: true
type: string
target:
required: true
type: string
platforms:
required: true
type: string
file:
required: true
type: string
push:
required: true
type: boolean

outputs:
digest:
value: "${{ steps.build.outputs.digest }}"

runs:
using: composite
steps:
- name: Generate docker metadata
uses: docker/metadata-action@v5
id: metadata
with:
images: ${{ inputs.images }}
- name: Build and push docker
uses: docker/build-push-action@v5
id: build
with:
context: ${{ inputs.context }}
file: ${{ inputs.file }}
target: ${{ inputs.target }}
labels: ${{ steps.metadata.outputs.labels }}
platforms: ${{ inputs.platforms }}
cache-from: type=registry,ref=${{ steps.metadata.outputs.tags }}
cache-to: type=inline
outputs: type=image,name=${{ inputs.images }},push-by-digest=true,name-canonical=true,push=${{ inputs.push }}

- name: Export digest
shell: bash
run: |
digest_dir="${{ runner.temp }}/${{ inputs.target }}-${{ github.run_number }}-digests"
mkdir -p "${digest_dir}"
digest="${{ steps.build.outputs.digest }}"
touch "${digest_dir}/${digest#sha256:}"

- name: Upload digest to arm64
if: ${{ matrix.platform == 'linux/arm64' }}
uses: actions/upload-artifact@v4
with:
name: "${{ inputs.target }}-digests-${{ github.run_number }}-arm64"
path: "${{ runner.temp }}/${{ inputs.target }}-${{ github.run_number }}-digests/*"
if-no-files-found: error
retention-days: 1

- name: Upload digest to amd64
if: ${{ matrix.platform == 'linux/amd64' }}
uses: actions/upload-artifact@v4
with:
name: "${{ inputs.target }}-digests-${{ github.run_number }}-amd64"
path: "${{ runner.temp }}/${{ inputs.target }}-${{ github.run_number }}-digests/*"
if-no-files-found: error
retention-days: 1
166 changes: 80 additions & 86 deletions .github/workflows/docker-upload.yml
Original file line number Diff line number Diff line change
@@ -1,120 +1,114 @@
name: Build and Publish Docker Image

on:
workflow_dispatch:
push:
branches:
- eigenda
tags:
- "v[0-9]+.[0-9]+.[0-9]+-*"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build-linux-amd64:
runs-on: linux-2xl
build:
strategy:
matrix:
platform: [linux/amd64, linux/arm64]
runs-on: ${{ matrix.platform == 'linux/amd64' && 'linux-2xl' || 'linux-xl-arm' }}

steps:
- name: Checkout
- name: Checkout Repository
uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

submodules: recursive
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache-amd64
key: linux-amd64-buildx-${{ hashFiles('Dockerfile') }}
restore-keys: linux-amd64-buildx-

- name: Login to GitHub Container Registry
uses: docker/login-action@v2

- name: Login to Github Container Repo
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
- name: Build nitro-node image
uses: ./.github/actions/docker-image
with:
images: |
ghcr.io/${{ github.repository_owner }}/nitro-eigenda
tags: |
${{ github.ref_name }}-linux-amd64
latest-linux-amd64
context: .
file: Dockerfile
images: ghcr.io/layr-labs/nitro/nitro-node
target: nitro-node
platforms: ${{ matrix.platform }}

- name: Build and push for linux/amd64
uses: docker/build-push-action@v5
- name: Build nitro-node-dev image
uses: ./.github/actions/docker-image
id: nitro-node-dev
with:
platform: linux/amd64
target: nitro-node
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache-amd64
cache-to: type=local,dest=/tmp/.buildx-cache-amd64-new,mode=max

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache-amd64
mv /tmp/.buildx-cache-amd64-new /tmp/.buildx-cache-amd64

build-linux-arm64:
runs-on: linux-xl-arm
file: Dockerfile
images: ghcr.io/layr-labs/nitro/nitro-node-dev
target: nitro-node-dev
platforms: ${{ matrix.platform }}

merge_into_multiplatform_images:
needs:
- build
strategy:
matrix:
target: [nitro-node, nitro-node-dev]
include:
- target: nitro-node
image: ghcr.io/layr-labs/nitro/nitro-node
- target: nitro-node-dev
image: ghcr.io/layr-labs/nitro/nitro-node-dev

runs-on: linux-2xl
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Github Container Repo
uses: docker/login-action@v2
with:
install: true
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Cache Docker layers
uses: actions/cache@v3
- name: Download digest amd64
uses: actions/download-artifact@v4
with:
path: /tmp/.buildx-cache-arm64
key: linux-arm64-buildx-${{ hashFiles('Dockerfile') }}
restore-keys: linux-arm64-buildx-
name: "${{ matrix.target }}-digests-${{ github.run_number }}-amd64"
path: "${{ runner.temp }}/${{ matrix.target }}-${{ github.run_number }}-digests"

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
- name: Download digest arm64
uses: actions/download-artifact@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
name: "${{ matrix.target }}-digests-${{ github.run_number }}-arm64"
path: "${{ runner.temp }}/${{ matrix.target }}-${{ github.run_number }}-digests"

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/nitro-eigenda
tags: |
${{ github.ref_name }}-linux-arm64
latest-linux-arm64

- name: Build and push for linux/arm64
uses: docker/build-push-action@v5
with:
platform: linux/arm64/v8
target: nitro-node
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache-arm64
cache-to: type=local,dest=/tmp/.buildx-cache-arm64-new,mode=max
images: ${{ matrix.image }}

- name: Move cache
- name: Create manifest list and push
working-directory: "${{ runner.temp }}/${{ matrix.target }}-${{ github.run_number }}-digests"
run: |
# Count the number of files in the directory
file_count=$(find . -type f | wc -l)

if [ "$file_count" -ne 2 ]; then
echo "Should have exactly 2 digests to combine, something went wrong"
ls -lah
exit 1
fi

docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ matrix.image }}@sha256:%s ' *)
- name: Inspect image
run: |
rm -rf /tmp/.buildx-cache-arm64
mv /tmp/.buildx-cache-arm64-new /tmp/.buildx-cache-arm64
docker buildx imagetools inspect ${{ matrix.image }}:${{ steps.meta.outputs.version }}
Loading