Skip to content

Added Github Action to deploy Helm Chart #96

Added Github Action to deploy Helm Chart

Added Github Action to deploy Helm Chart #96

name: Deploy Helm Chart
env:
HELM_VERSION: '3.14.3'
HELM_REGISTRY: ghcr.io/${{ github.repository_owner }}/helm-charts
on:
push:
branches:
- devops/FAIRSPC-23_deployment
workflow_dispatch:
inputs:
name:
description: "Manual trigger for Helm chart deploy"
version:
description: "Version of the Helm chart to deploy (optional, defaults to latest snapshot)"
required: false
environment:
description: "Environment to deploy to"
required: true
default: "test"
options:
- "test"
- "prod"
jobs:
setup-deploy:
runs-on: ubuntu-latest
# environment: ${{ github.event.inputs.environment }} // todo: rollback to this line
environment: 'test'
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v4
with:
repository: 'thehyve/fnscloud-demonstrator'
path: './fns'
token: ${{ secrets.FNS_PAT }}
- name: Prepare model and k8s values files
run: |
ls ./fns
if [ -n "${{ github.event.inputs.environment }}" ]; then
ENVIRONMENT="${{ github.event.inputs.environment }}"
else
ENVIRONMENT="test"
fi
echo "ENVIRONMENT=$ENVIRONMENT" >> $GITHUB_ENV
echo "Starting deployment to the $ENVIRONMENT environment"
- name: Define the version
run: |
VERSION=$(cat ./VERSION)-SNAPSHOT
if [ -n "${{ github.event.inputs.version }}" ]; then
VERSION=${{ github.event.inputs.version }}
fi
echo "Helm charms version: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Auth GCP
uses: google-github-actions/auth@v2
with:
workload_identity_provider: projects/687196986816/locations/global/workloadIdentityPools/fs-fns-pool/providers/fs-fns-provider
service_account: cicd-service-account@fns-cloud-852306.iam.gserviceaccount.com
- uses: google-github-actions/get-gke-credentials@v2
with:
cluster_name: fns-cloud-f01
location: europe-west1
- name: Configure docker to authenticate
run: |
gcloud auth configure-docker
- name: Setup Helm
uses: azure/setup-helm@v4.1.0
with:
version: ${{ env.HELM_VERSION }}
- name: Login with Helm
run: |
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${{ env.HELM_REGISTRY }} --username ${{ github.repository_owner }} --password-stdin
- name: Delete StatefulSet (if exists) to force re-deploy
run: |
# Check if the StatefulSet exists
if kubectl get statefulset fairspace --namespace fairspace-${{ env.ENVIRONMENT }} &> /dev/null; then
kubectl delete statefulset fairspace --namespace fairspace-${{ env.ENVIRONMENT }} --cascade=orphan
echo "StatefulSet fairspace deleted."
else
echo "StatefulSet fairspace does not exist."
fi
- name: Deploy Helm chart
run: |
echo "--------"
pwd
echo "--------"
ls ./fns/
echo "--------"
helm upgrade --install fairspace oci://${{ env.HELM_REGISTRY }}/fairspace \
--version ${{ env.VERSION }} \
--namespace=fairspace-${{ env.ENVIRONMENT }} \
--set-file saturn.vocabulary=./fns/fairspace/model/vocabulary.ttl \
--set-file saturn.views=./fns/fairspace/model/views.yaml \
--values ./fns/fairspace/deployment/${{ env.ENVIRONMENT }}/fairspace-test-values.yaml