Skip to content

Commit

Permalink
Refactor GitHub Actions to use modular AMD and ARM docker build workf…
Browse files Browse the repository at this point in the history
…lows
  • Loading branch information
wojciechos committed Oct 1, 2023
1 parent ac39dd5 commit 1207458
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 90 deletions.
58 changes: 18 additions & 40 deletions .github/workflows/ci-cd-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,27 @@ on:
tags: [v*]

jobs:
docker_build_and_publish:
docker_build_and_publish_amd:
runs-on: ubuntu-latest
outputs:
IMAGE_TAG: ${{ steps.image_tag.outputs.IMAGE_TAG }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Define_docker_image_tag
id: image_tag
run: |
echo "DOCKER_IMAGE_TAG=$(git describe --tags)" >> $GITHUB_ENV
echo "IMAGE_TAG=$(git describe --tags)" >> "$GITHUB_OUTPUT"
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and Push
uses: docker/build-push-action@v5
- name: Call AMD Build Workflow
id: amd_build
uses: ./.github/workflows/docker-build-publish-amd.yml
with:
context: .
platforms: 'linux/amd64'
push: true
tags: nethermindeth/juno:${{ env.DOCKER_IMAGE_TAG }}
tag: ${{ github.ref }}
outputs:
AMD_IMAGE_TAG: ${{ steps.amd_build.outputs.AMD_IMAGE_TAG }}

deploy_to_dev:
needs: [docker_build_and_publish]
needs: [docker_build_and_publish_amd]
runs-on: ubuntu-latest
environment:
name: Development
steps:
- name: Repository Dispatch Dev
env:
EVENT_NAME: juno-dev
IMAGE_TAG: ${{ needs.docker_build_and_publish.outputs.IMAGE_TAG }}
IMAGE_TAG: ${{ needs.docker_build_and_publish_amd.outputs.AMD_IMAGE_TAG }}
GOERLI: apps/juno-dev/overlays/dev-goerli-1/config.yaml
INTEGRATION: apps/juno-dev/overlays/dev-integration/config.yaml
MAINNET: apps/juno-dev/overlays/dev-mainnet/config.yaml
Expand Down Expand Up @@ -85,15 +63,15 @@ jobs:
REPOSITORY_DISPATCH_TOKEN: ${{ secrets.REPOSITORY_DISPATCH_TOKEN }}

deploy_to_staging:
needs: [docker_build_and_publish, deploy_to_dev]
needs: [docker_build_and_publish_amd, deploy_to_dev]
runs-on: ubuntu-latest
environment:
name: Staging
steps:
- name: Repository Dispatch Staging
env:
EVENT_NAME: juno-staging
IMAGE_TAG: ${{ needs.docker_build_and_publish.outputs.IMAGE_TAG }}
IMAGE_TAG: ${{ needs.docker_build_and_publish_amd.outputs.AMD_IMAGE_TAG }}
GOERLI: apps/juno-staging/overlays/staging-goerli-1/config.yaml
INTEGRATION: apps/juno-staging/overlays/staging-integration/config.yaml
MAINNET: apps/juno-staging/overlays/staging-mainnet/config.yaml
Expand Down Expand Up @@ -130,26 +108,26 @@ jobs:
REPOSITORY_DISPATCH_TOKEN: ${{ secrets.REPOSITORY_DISPATCH_TOKEN }}

deploy_to_production:
needs: [deploy_to_staging]
needs: [docker_build_and_publish_amd, deploy_to_staging]
runs-on: ubuntu-latest
environment:
name: Production
steps:
- name: Repository Dispatch Prod
env:
EVENT_NAME: juno-prod
IMAGE_TAG: ${{ needs.docker_build_and_publish.outputs.IMAGE_TAG }}
IMAGE_TAG: ${{ needs.docker_build_and_publish_amd.outputs.AMD_IMAGE_TAG }}
GOERLI: apps/juno-prod/overlays/prod_goerli-1/config.yaml
INTEGRATION: apps/juno-prod/overlays/prod_integration/config.yaml
MAINNET: apps/juno-prod/overlays/prod_mainnet/config.yaml
run: |
curl -L \
-X POST \
# -H "Accept: application/vnd.github+json" \
# -H "Authorization: token ${{ secrets.ACCESS_TOKEN }}" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# https://api.github.com/repos/NethermindEth/argo/dispatches \
# -d '{"event_type": "${{ env.EVENT_NAME }}", "client_payload":{"name": "${{ env.EVENT_NAME }}", "goerli_config": "${{ env.GOERLI }}", "integration_config": "${{ env.INTEGRATION }}", "mainnet_config": "${{ env.MAINNET }}", "tag": "${{ env.IMAGE_TAG }}"}}'
-H "Accept: application/vnd.github+json" \
-H "Authorization: token ${{ secrets.ACCESS_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/NethermindEth/argo/dispatches \
-d '{"event_type": "${{ env.EVENT_NAME }}", "client_payload":{"name": "${{ env.EVENT_NAME }}", "goerli_config": "${{ env.GOERLI }}", "integration_config": "${{ env.INTEGRATION }}", "mainnet_config": "${{ env.MAINNET }}", "tag": "${{ env.IMAGE_TAG }}"}}'
prod-starknet-rs-tests:
needs: [deploy_to_production]
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/docker-build-publish-amd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Docker Build and Publish AMD

on:
workflow_call:

jobs:
build_and_push_amd:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

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

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push AMD image
uses: docker/build-push-action@v4
with:
context: .
platforms: 'linux/amd64'
push: true
tags: nethermindeth/juno:${{ github.ref }}

- name: Set Output
id: set_output
run: echo "AMD_IMAGE_TAG=${{ github.ref }}" >> $GITHUB_ENV

outputs:
AMD_IMAGE_TAG: ${{ steps.set_output.outputs.AMD_IMAGE_TAG }}
42 changes: 42 additions & 0 deletions .github/workflows/docker-build-publish-arm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Docker Build and Publish ARM

on:
workflow_call:

jobs:
build_and_push_arm:
if: github.repository_owner == 'NethermindEth'
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

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

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push ARM image
uses: docker/build-push-action@v4
with:
context: .
platforms: 'linux/arm64'
push: true
tags: nethermindeth/juno:${{ github.event.inputs.tag }}-arm64

- name: Cleanup self-hosted
run: |
docker system prune -af
- name: Set Output
id: set_output
run: echo "ARM_IMAGE_TAG=${{ github.event.inputs.tag }}-arm64" >> $GITHUB_ENV

outputs:
ARM_IMAGE_TAG: ${{ steps.set_output.outputs.ARM_IMAGE_TAG }}
55 changes: 5 additions & 50 deletions .github/workflows/docker-image-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,16 @@ on:

jobs:
build_and_push_docker_image_amd:
if: github.repository_owner == 'NethermindEth'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

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

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
platforms: 'linux/amd64'
push: true
tags: nethermindeth/juno:${{ github.event.inputs.tag }}
- name: Call AMD Build Workflow
uses: ./.github/workflows/docker-build-publish-amd.yml

build_and_push_docker_image_arm:
if: github.repository_owner == 'NethermindEth'
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

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

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push ARM
uses: docker/build-push-action@v4
with:
context: .
platforms: 'linux/arm64'
push: true
tags: nethermindeth/juno:${{ github.event.inputs.tag }}-arm64

- name: Cleanup self-hosted
run: |
docker system prune -af
- name: Call ARM Build Workflow
uses: ./.github/workflows/docker-build-publish-arm.yml

create_and_push_official_image:
if: github.repository_owner == 'NethermindEth' && github.event.inputs.repo_type == 'official'
Expand All @@ -95,5 +51,4 @@ jobs:
- name: Clean up environment
if: always()
run: |
rm -f ${HOME}/.docker/config.json
rm -f ${HOME}/.docker/config.json

0 comments on commit 1207458

Please sign in to comment.