Skip to content

Commit

Permalink
Refactor GitHub Actions to use modular docker build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciechos committed Oct 2, 2023
1 parent ac39dd5 commit 44144d3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 34 deletions.
56 changes: 24 additions & 32 deletions .github/workflows/ci-cd-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: CI/CD

on:
push:
branches: [main]
branches: [main, wojciechos/cleanup-ci]
tags: [v*]

jobs:
docker_build_and_publish:
setup:
runs-on: ubuntu-latest
outputs:
IMAGE_TAG: ${{ steps.image_tag.outputs.IMAGE_TAG }}
Expand All @@ -19,36 +19,28 @@ jobs:
- name: Define_docker_image_tag
id: image_tag
run: |
echo "DOCKER_IMAGE_TAG=$(git describe --tags)" >> $GITHUB_ENV
echo "Debug GIT_TAG: $(git describe --tags)"
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
with:
context: .
platforms: 'linux/amd64'
push: true
tags: nethermindeth/juno:${{ env.DOCKER_IMAGE_TAG }}
docker_build_and_publish_amd:
needs: [setup]
uses: ./.github/workflows/docker-build-publish-amd.yml
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
with:
tag: ${{ needs.setup.outputs.IMAGE_TAG }}

deploy_to_dev:
needs: [docker_build_and_publish]
needs: [setup, 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.setup.outputs.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 +77,15 @@ jobs:
REPOSITORY_DISPATCH_TOKEN: ${{ secrets.REPOSITORY_DISPATCH_TOKEN }}

deploy_to_staging:
needs: [docker_build_and_publish, deploy_to_dev]
needs: [setup, 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.setup.outputs.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 +122,26 @@ jobs:
REPOSITORY_DISPATCH_TOKEN: ${{ secrets.REPOSITORY_DISPATCH_TOKEN }}

deploy_to_production:
needs: [deploy_to_staging]
needs: [setup, 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.setup.outputs.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:
secrets:
DOCKER_USERNAME:
required: false
DOCKER_PASSWORD:
required: true
inputs:
tag:
required: true
type: string

jobs:
build_and_push_amd:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- 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:${{ inputs.tag }}
4 changes: 2 additions & 2 deletions .github/workflows/docker-image-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down Expand Up @@ -96,4 +96,4 @@ jobs:
if: always()
run: |
rm -f ${HOME}/.docker/config.json

0 comments on commit 44144d3

Please sign in to comment.