Skip to content

Commit

Permalink
ci: fix tags and set jobs correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
VmMad committed Jan 26, 2024
1 parent d5e1812 commit bddcc38
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 36 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/build-images.reusable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Build and Push Images

on:
workflow_call:
inputs:
api_image_tags:
required: true
type: string
client_image_tags:
required: true
type: string

jobs:
build-and-push-images:
name: Build and Push Docker Images
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "16"

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

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.IOTALEDGER_DOCKER_USERNAME }}
password: ${{ secrets.IOTALEDGER_DOCKER_PASSWORD }}

- name: Build and push API Docker image
uses: docker/build-push-action@v2
with:
context: ./api
file: ./api/Dockerfile
push: true
tags: ${{ inputs.api_image_tags }}
no-cache: true

- name: Build and push Client Docker image
uses: docker/build-push-action@v2
with:
context: ./client
file: ./client/Dockerfile
push: true
tags: ${{ inputs.client_image_tags }}
no-cache: true
37 changes: 19 additions & 18 deletions .github/workflows/release-production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ name: Release Explorer to Production
on:
push:
tags:
# Only run workflow on tags that match the semantic versioning pattern 'v1.0.0'
- ^v(\d+\.\d+\.\d+)$
- 'v[0-9]+.[0-9]+.[0-9]+'
- '!v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+'

jobs:
deploy-production-images:
name: Deploy Docker Images for Production
set_tags:
name: Set Tags
runs-on: ubuntu-latest
outputs:
version_tag: ${{ steps.set_version_tag.outputs.version_tag }}
Expand All @@ -18,22 +18,23 @@ jobs:
run: |
echo "VERSION_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Build and push API Docker image
uses: ./.github/workflows/build-and-push-docker-images.yaml
with:
version_tag: ${{ steps.set_version_tag.outputs.version_tag }}
api_image_tags: |
iotaledger/explorer-api:${{ steps.set_version_tag.outputs.VERSION_TAG }}
iotaledger/explorer-api:latest
iotaledger/explorer-api:latest-stable
use-reusable-workflow:
name: Build Images
needs: set_tags
uses: ./.github/workflows/build-images.reusable.yaml
with:
api_image_tags: |
iotaledger/explorer-api:${{ needs.set_tags.outputs.version_tag }}
iotaledger/explorer-api:latest
client_image_tags: |
iotaledger/explorer-client:${{ steps.set_version_tag.outputs.VERSION_TAG }}
iotaledger/explorer-client:latest
iotaledger/explorer-client:latest-stable
client_image_tags: |
iotaledger/explorer-client:${{ needs.set_tags.outputs.version_tag }}
iotaledger/explorer-client:latest
secrets: inherit

deploy_to_server:
needs: deploy-production-images
name: Deploy Production to Server
needs: [set_tags, use-reusable-workflow]
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -46,4 +47,4 @@ jobs:

- name: Deploy to Server
run: |
ssh -o StrictHostKeyChecking=no updater@${{ secrets.EXPLORER_GATEWAY }} "${{ matrix.environment }} ${{ needs.deploy-production-images.outputs.version_tag }}"
ssh -o StrictHostKeyChecking=no updater@${{ secrets.EXPLORER_GATEWAY }} "${{ matrix.environment }} ${{ needs.set_tags.outputs.version_tag }}"
39 changes: 21 additions & 18 deletions .github/workflows/release-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Release Explorer to Staging
on:
push:
tags:
# Only run workflow on tags that match the semantic versioning pattern 'v1.0.0-rc.0'
- ^v(\d+\.\d+\.\d+)-rc\.\d+$
- 'v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+' # Versioning pattern 'v1.0.0-rc.0'
workflow_dispatch:
inputs:
tag:
Expand All @@ -13,15 +12,18 @@ on:
default: "v1.0.0-rc.0"

jobs:
deploy-staging-images:
name: Deploy Docker Images for Staging
set_tags:
name: Set Tags
runs-on: ubuntu-latest
outputs:
version_tag: ${{ steps.set_version_tag.outputs.version_tag }}
steps:
- name: Checkout
uses: actions/checkout@v2

# If the workflow was triggered by a tag, use the tag as the version.
# Otherwise, use the tag from the workflow_dispatch event.
- name: Set up the tag for docker images
- name: Set up the version tag for docker images
id: set_version_tag
run: |
if [ "${{ github.event_name }}" = "push" ]; then
Expand All @@ -30,19 +32,20 @@ jobs:
echo "VERSION_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
fi
- name: Build and push API Docker image
uses: ./.github/workflows/build-and-push-docker-images.yaml
with:
version_tag: ${{ steps.set_version_tag.outputs.version_tag }}
api_image_tags: |
iotaledger/explorer-api:${{ steps.set_version_tag.outputs.VERSION_TAG }}
iotaledger/explorer-api:latest
client_image_tags: |
iotaledger/explorer-client:${{ steps.set_version_tag.outputs.VERSION_TAG }}
iotaledger/explorer-client:latest
use-reusable-workflow:
name: Build Images
needs: set_tags
uses: ./.github/workflows/build-images.reusable.yaml
with:
api_image_tags: |
iotaledger/explorer-api:${{ needs.set_tags.outputs.version_tag }}
client_image_tags: |
iotaledger/explorer-client:${{ needs.set_tags.outputs.version_tag }}
secrets: inherit

deploy:
needs: deploy-staging-images
deploy_to_server:
name: Deploy Staging to Server
needs: [set_tags, use-reusable-workflow]
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -55,4 +58,4 @@ jobs:

- name: Deploy to Server
run: |
ssh -o StrictHostKeyChecking=no updater@${{ secrets.EXPLORER_GATEWAY }} "${{ matrix.environment }} ${{ needs.deploy-staging-images.outputs.version_tag }}"
ssh -o StrictHostKeyChecking=no updater@${{ secrets.EXPLORER_GATEWAY }} "${{ matrix.environment }} ${{ needs.set_tags.outputs.version_tag }}"

0 comments on commit bddcc38

Please sign in to comment.