-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pipeline and helm release (#59)
* fix pipeline * fix pipeline * fix the needs * fix the needs * fix release * fix pipeline * fix pipeline * fix names * fix helm command
- Loading branch information
Showing
9 changed files
with
275 additions
and
52 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
name: .Deploys | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
### Required | ||
release: | ||
description: Deployment release; usually PR number, test or prod | ||
required: true | ||
type: string | ||
|
||
### Typical / recommended | ||
autoscaling: | ||
description: Autoscaling enabled or not for the deployments | ||
required: false | ||
type: string | ||
default: true | ||
environment: | ||
description: Environment name; omit for PRs | ||
required: false | ||
type: string | ||
tag: | ||
description: Container tag; usually PR number | ||
required: false | ||
type: string | ||
default: ${{ github.event.number }} | ||
triggers: | ||
description: Paths to trigger a deploy; omit=always; e.g. ('backend/' 'frontend/') | ||
required: false | ||
type: string | ||
|
||
### Usually a bad idea / not recommended | ||
directory: | ||
description: 'Chart directory' | ||
default: 'charts/${{ github.event.repository.name }}' | ||
required: false | ||
type: string | ||
timeout-minutes: | ||
description: 'Timeout minutes' | ||
default: 10 | ||
required: false | ||
type: number | ||
values: | ||
description: 'Values file' | ||
default: 'values.yaml' | ||
required: false | ||
type: string | ||
DB_HOST: | ||
description: 'Database Host' | ||
default: '' | ||
required: true | ||
type: string | ||
DB_NAME: | ||
description: 'Database Name' | ||
default: '' | ||
required: true | ||
type: string | ||
DB_PWD: | ||
description: 'Database Password' | ||
default: '' | ||
required: true | ||
type: string | ||
DB_USER: | ||
description: 'Database User' | ||
default: '' | ||
required: true | ||
type: string | ||
DB_PORT: | ||
description: 'Database Port' | ||
default: '1543' | ||
required: false | ||
type: string | ||
params: | ||
description: 'Extra parameters to pass to helm upgrade' | ||
default: '' | ||
required: false | ||
type: string | ||
|
||
env: | ||
repo_release: ${{ github.event.repository.name }}-${{ inputs.release }} | ||
package_tag: ${{ inputs.tag }} | ||
|
||
jobs: | ||
deploys: | ||
name: Helm | ||
environment: ${{ inputs.environment }} | ||
runs-on: ubuntu-22.04 | ||
timeout-minutes: ${{ inputs.timeout-minutes }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Check Deployment Triggers | ||
id: triggers | ||
run: | | ||
# Expand for trigger processing | ||
# Always deploy if no triggers are provided | ||
if [ -z "${{ inputs.triggers }}" ]; then | ||
echo "Always deploy when no triggers are provided" | ||
echo "triggered=true" >> $GITHUB_OUTPUT | ||
exit 0 | ||
fi | ||
# Deploy if changed files (git diff) match triggers | ||
TRIGGERS=${{ inputs.triggers }} | ||
git fetch origin ${{ github.event.repository.default_branch }} | ||
while read -r check; do | ||
for t in "${TRIGGERS[@]}"; do | ||
if [[ "${check}" =~ "${t}" ]]; then | ||
echo "Build triggered based on git diff" | ||
echo -e "${t}\n --> ${check}" | ||
echo "triggered=true" >> $GITHUB_OUTPUT | ||
exit 0 | ||
fi | ||
done | ||
done < <(git diff origin/${{ github.event.repository.default_branch }} --name-only) | ||
# If here skip deployment | ||
echo "No triggers have fired, deployment skipped" | ||
- name: Deploy if Triggers Fired | ||
if: ${{ steps.triggers.outputs.triggered == 'true' }} | ||
working-directory: ${{ inputs.directory }} | ||
shell: bash | ||
run: | | ||
oc login --token=${{ secrets.oc_token }} --server=${{ vars.oc_server }} | ||
oc project ${{ vars.OC_NAMESPACE }} # Safeguard! | ||
# uninstall if found | ||
helm uninstall ${{ env.repo_release }} || true | ||
# Deploy Helm Chart | ||
helm dependency update | ||
helm package --app-version="${{ env.package_tag }}" --version=${{ inputs.tag }} . | ||
helm upgrade \ | ||
--set-string app.envs.DB_HOST=${{ inputs.DB_HOST }} \ | ||
--set-string app.envs.DB_NAME=${{ inputs.DB_NAME }} \ | ||
--set-string app.envs.DB_PASSWORD=${{ inputs.DB_PWD }} \ | ||
--set-string app.envs.DB_USER=${{ inputs.DB_USER }} \ | ||
--set-string app.envs.DB_PORT="${{ inputs.DB_PORT }}" \ | ||
--set-string image.tag="${{ env.package_tag }}" \ | ||
--set-string namespace=${{ vars.oc_namespace }} \ | ||
${{ inputs.params }} \ | ||
--install --wait --atomic ${{ env.repo_release }} \ | ||
--timeout ${{ inputs.timeout-minutes }}m \ | ||
--values ${{ inputs.values }} \ | ||
./${{ github.event.repository.name }}-${{ inputs.tag }}.tgz | ||
# print history | ||
helm history ${{ env.repo_release }} | ||
# Remove old build runs, build pods and deployment pods | ||
oc delete po --field-selector=status.phase==Succeeded |
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
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
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
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
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
Oops, something went wrong.