Skip to content

Commit

Permalink
Merge branch 'dev' into bal-2513-email-plugin-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alonp99 committed Oct 12, 2024
2 parents 035fd7b + f0708e2 commit e89c31b
Show file tree
Hide file tree
Showing 23 changed files with 741 additions and 538 deletions.
240 changes: 185 additions & 55 deletions .github/workflows/test-db-ops.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
name: Under Testing - Database Operations

on:
workflow_dispatch:
inputs:
environment:
type: choice
description: 'Choose Environment'
required: true
default: 'dev'
options:
- 'dev'
- 'sb'
- 'prod'
tag:
type: string
description: 'Image Tag'
required: true
default: ''
repository_dispatch:
types: [run-test-migration]
# workflow_dispatch:
# inputs:
# environment:
# type: choice
# description: 'Choose Environment'
# required: true
# default: 'dev'
# options:
# - 'dev'
# - 'sb'
# - 'prod'
# sha:
# type: string
# description: 'Commit SHA ID'
# required: true
# default: ''

workflow_call:
inputs:
Expand All @@ -25,15 +27,144 @@ on:
description: 'Environment'
required: true
default: 'dev'
tag:
sha:
type: string
description: 'Image Tag'
description: 'Commit SHA ID'
required: true
default: ''

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/workflows-service
SHORT_HASH: ''

jobs:
check_if_data_migration_needed:
runs-on: ubuntu-latest
outputs:
should_build: ${{ steps.check-branch-existance.outputs.should_build }} # short sha of the commit
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: 'recursive'
token: ${{ secrets.SUBMODULES_TOKEN }}

- name: Check if branch exists
id: check-branch-existance
run: |
cd services/workflows-service/prisma/data-migrations
is_exists=$(git ls-remote --exit-code --heads -t --ref -q origin "${{ github.event_name == 'repository_dispatch' && github.event.client_payload.ref || inputs.environment }}" | wc -l)
# Check if the branch exists by counting the number of results
if [ $is_exists -eq 0 ]; then
echo "Branch '${{ github.event_name == 'repository_dispatch' && github.event.client_payload.ref || inputs.environment }}' does not exist."
echo "should_build=false" >> $GITHUB_OUTPUT
else
echo "should_build=true" >> $GITHUB_OUTPUT
fi
exit 0
build-and-push-ee-image:
runs-on: ubuntu-latest
needs: [check_if_data_migration_needed]
if: ${{ needs.check_if_data_migration_needed.outputs.should_build == 'true' }}
outputs:
shorthash: ${{ steps.lastcommit.outputs.shorthash }}
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Get Latest Commit ID
id: lastcommit
if: ${{ github.event_name == 'repository_dispatch' }}
uses: nmbgeek/github-action-get-latest-commit@main
with:
owner: ${{ github.repository_owner }}
repo: ballerine
branch: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.ref || inputs.environment }}

- name: Set Commit Id as Env
run: echo "SHORT_HASH=${{ steps.lastcommit.outputs.shorthash }}" >> $GITHUB_ENV

- name: Checkout wf-data-migration
uses: actions/checkout@v4
with:
repository: ballerine-io/wf-data-migration
token: ${{ secrets.SUBMODULES_TOKEN }}
ref: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.ref || inputs.environment }}
fetch-depth: 1
path: services/workflows-service/prisma/data-migrations

- name: Cache Docker layers
id: cache
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}
restore-keys: |
${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}
${{ runner.os }}-docker-
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: 'arm64,arm'

- name: Log in to the container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for ee Docker images
id: eemeta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}-ee
tags: |
type=raw,value=${{ github.event_name == 'repository_dispatch' && github.event.client_payload.ref || inputs.environment }}
type=raw,value=${{ github.event_name == 'repository_dispatch' && steps.lastcommit.outputs.shorthash || inputs.sha }}-${{ github.event_name == 'repository_dispatch' && github.event.client_payload.ref || inputs.environment }}
type=raw,value=latest,enable=${{ github.event_name == 'repository_dispatch' && github.event.client_payload.ref == 'prod' || inputs.environment == 'prod' }}
type=sha,format=short
- name: Build and push ee Docker image
if: ${{ github.event_name != 'repository_dispatch' }}
uses: docker/build-push-action@v5
with:
context: services/workflows-service
file: services/workflows-service/Dockerfile.ee
platforms: linux/amd64
push: false
cache-from: type=local,src=/tmp/.buildx-cache
tags: ${{ steps.eemeta.outputs.tags }}
build-args: |
"BASE_IMAGE=ghcr.io/${{ github.repository_owner }}/workflows-service:${{ inputs.sha }}-${{ inputs.environment }}"
- name: Build and push ee Docker image
if: ${{ github.event_name == 'repository_dispatch' }}
uses: docker/build-push-action@v5
with:
context: services/workflows-service
file: services/workflows-service/Dockerfile.ee
platforms: linux/amd64
push: false
cache-from: type=local,src=/tmp/.buildx-cache
tags: ${{ steps.eemeta.outputs.tags }}
build-args: |
"BASE_IMAGE=ghcr.io/${{ github.repository_owner }}/workflows-service:${{ steps.lastcommit.outputs.shorthash }}-${{ github.event.client_payload.ref }}"
update-helm-chart:
runs-on: ubuntu-latest
needs: build-and-push-ee-image
permissions:
contents: read
steps:
Expand All @@ -56,30 +187,29 @@ jobs:
id: update_helm_check
shell: bash
run: |
if [ -f "kubernetes/helm/wf-service/${{ inputs.environment }}-custom-values.yaml" ]; then
echo "file_name=${{ inputs.environment }}-custom-values.yaml" >> "$GITHUB_OUTPUT"
elif [ "${{ inputs.environment }}" == "dev" ]; then
echo "file_name=dev-custom-values.yaml" >> "$GITHUB_OUTPUT"
if [ -f "kubernetes/helm/wf-service/${{ github.event_name == 'repository_dispatch' && github.event.client_payload.ref || inputs.environment }}-custom-values.yaml" ]; then
echo "file_name=${{ github.event_name == 'repository_dispatch' && github.event.client_payload.ref || inputs.environment }}-custom-values.yaml" >> "$GITHUB_OUTPUT"
echo ${{ github.event_name == 'workflow_dispatch' && needs.build-and-push-ee-image.outputs.shorthash || inputs.sha }}
else
echo "skip_helm=true" >> "$GITHUB_OUTPUT"
echo "file_name=dev-custom-values.yaml" >> "$GITHUB_OUTPUT"
echo ${{ github.event_name == 'workflow_dispatch' && needs.build-and-push-ee-image.outputs.shorthash || inputs.sha }}
fi
- name: Update workflow-service image version in the HelmChart
if: ${{ steps.update_helm_check.outputs.skip_helm != 'true' }}
uses: fjogeleit/yaml-update-action@main
with:
repository: ballerine-io/cloud-infra-config
branch: main
commitChange: true
message: 'Update wf-service image Version to ${{ inputs.tag }} - (Commit hash: ${{ github.sha }}, commit message: ${{ github.event.head_commit.message }})'
token: ${{ secrets.GIT_TOKEN }}
changes: |
{
"kubernetes/helm/wf-service/${{steps.update_helm_check.outputs.file_name}}": {
"dbMigrate.image.tag": "${{ inputs.tag }}",
"dataSync.image.tag": "${{ inputs.tag }}"
}
}
# - name: Update workflow-service image version in the HelmChart
# uses: fjogeleit/yaml-update-action@main
# with:
# repository: ballerine-io/cloud-infra-config
# branch: main
# commitChange: true
# message: "Update wf-service image Version to ${{ github.event_name == 'workflow_dispatch' && needs.build-and-push-ee-image.outputs.shorthash || inputs.sha }} - (Commit hash: ${{ github.sha }}, commit message: ${{ github.event.head_commit.message }})"
# token: ${{ secrets.GIT_TOKEN }}
# changes: |
# {
# "kubernetes/helm/wf-service/${{steps.update_helm_check.outputs.file_name}}": {
# "dbMigrate.image.tag": "${{ github.event_name == 'repository_dispatch' && needs.build-and-push-ee-image.outputs.shorthash || inputs.sha }}-${{ github.event_name == 'repository_dispatch' && github.event.client_payload.ref || inputs.environment}}",
# "dataSync.image.tag": "${{ github.event_name == 'repository_dispatch' && needs.build-and-push-ee-image.outputs.shorthash || inputs.sha }}-${{ github.event_name == 'repository_dispatch' && github.event.client_payload.ref || inputs.environment}}"
# }
# }

# sync-argo-app:
# runs-on: ubuntu-latest
Expand All @@ -100,20 +230,20 @@ jobs:
# argocd_password: ${{ secrets.ARGOCD_PASSWORD }}
# argocd_server: ${{ secrets.ARGOCD_SERVER }}

send-to-slack:
runs-on: ubuntu-latest
needs: [update-helm-chart]
if: ${{ needs.update-helm-chart.result == 'success' }}
permissions:
contents: read
packages: write
# send-to-slack:
# runs-on: ubuntu-latest
# needs: [update-helm-chart]
# if: ${{ needs.update-helm-chart.result == 'success' }}
# permissions:
# contents: read
# packages: write

steps:
- name: Send alert to Slack channel
id: slack
uses: slackapi/[email protected]
with:
channel-id: '${{ secrets.ARGO_SLACK_CHANNEL_ID }}'
slack-message: "Wf-service Migrations in ${{ github.ref_name }} build result: ${{ job.status }}. successfully updated the wf-service helm values for ${{ github.ref_name }}."
env:
SLACK_BOT_TOKEN: ${{ secrets.ARGO_SLACK_BOT_TOKEN }}
# steps:
# - name: Send alert to Slack channel
# id: slack
# uses: slackapi/[email protected]
# with:
# channel-id: '${{ secrets.ARGO_SLACK_CHANNEL_ID }}'
# slack-message: "Wf-service Migrations in ${{ inputs.environment }} build result: ${{ job.status }}. successfully updated the wf-service migration jobs helm values for ${{ inputs.environment }}."
# env:
# SLACK_BOT_TOKEN: ${{ secrets.ARGO_SLACK_BOT_TOKEN }}
Loading

0 comments on commit e89c31b

Please sign in to comment.