CD Pipeline #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CD Pipeline | |
on: | |
workflow_run: | |
workflows: ['CI pipeline'] | |
types: [completed] | |
branches: | |
- dev | |
jobs: | |
deploy-locally: | |
runs-on: self-hosted | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Check if repository is checked out | |
id: check-repo | |
run: | | |
$repoPath = "${{ secrets.REPO_PATH }}" | |
if (Test-Path $repoPath) { | |
$repoContents = Get-ChildItem -Path $repoPath | |
if ($repoContents.Count -gt 0) { | |
echo "repo-exists=true" >> $env:GITHUB_ENV | |
} else { | |
echo "repo-exists=false" >> $env:GITHUB_ENV | |
} | |
} else { | |
echo "repo-exists=false" >> $env:GITHUB_ENV | |
} | |
- name: Checkout repository if not present | |
if: env.repo-exists == 'false' | |
run: | | |
git clone https://github.com/AleksandraKrasteva/skipass.git ${{ secrets.REPO_PATH }} | |
- name: Switch to dev branch and pull latest change | |
run: | | |
cd ${{ secrets.REPO_PATH }} | |
git checkout dev | |
git pull origin dev | |
- name: Check if deployment is running | |
id: check-deployment | |
run: | | |
kubectl get deployment post-service-deployment -o jsonpath='{.status.readyReplicas}'; echo "0" | |
continue-on-error: true | |
- name: Create temporary grafana values file if deployment is not running | |
if: steps.check-deployment.outputs.status == '0' | |
run: | | |
$grafanaFilePath = "${{secrets.REPO_PATH}}\docker_kubernetes\values.yaml"; | |
$grafanaConfig = @" | |
${{ secrets.GRAFANA_CONFIG }} | |
"@; | |
$grafanaConfig | Out-File -FilePath $grafanaFilePath -Encoding utf8 | |
- name: Deploy application if not running | |
if: steps.check-deployment.outputs.status == '0' | |
run: | | |
cd ${{ secrets.REPO_PATH }}/docker_kubernetes | |
kubectl create secret generic global-secret --from-literal=post-db-user=${{ secrets.USER_DB_SECRET }} --from-literal=post-db-pass=${{ secrets.PASS_DB_SECRET }} --from-literal=rabbitmq-user=${{ secrets.RABBITMQ_USER }} --from-literal=rabbitmq-pass=${{ secrets.RABBITMQ_PASS }} --from-literal=journey-db-pass=${{ secrets.JOURNEY_DB_PASS }} --from-literal=journey-db-user=${{ secrets.JOURNEY_DB_USER }} | |
powershell.exe -File ./initialize.ps1 | |
- name: Update deployment | |
if: steps.check-deployment.outputs.status != '0' | |
run: | | |
kubectl rollout restart statefulset -n default; | |
kubectl rollout restart deployments -n default; | |
powershell.exe -File ${{ secrets.REPO_PATH }}/docker_kubernetes/initialize_redeploy.ps1 | |