Skip to content

Commit

Permalink
feat: helm package before deploy to add proper versioning for the app (
Browse files Browse the repository at this point in the history
…#1660)

Co-authored-by: Derek Roberts <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 30, 2023
1 parent 39db943 commit b40c456
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 8 deletions.
21 changes: 19 additions & 2 deletions .github/workflows/.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ on:
default: 'values.yaml'
required: false
type: string
semver:
description: 'The Semantic version that is being released. Mainly used for TEST and PROD'
default: ''
required: false
type: string

env:
repo_release: ${{ github.event.repository.name }}-${{ inputs.release }}
Expand Down Expand Up @@ -92,6 +97,13 @@ jobs:
working-directory: ${{ inputs.directory }}
shell: bash
run: |
# Check Semver or default to 0.0.1
if [ -z "${{ inputs.semver }}" ]; then
VERSION=0.0.1
else
VERSION=${{ inputs.semver }}
fi
oc login --token=${{ secrets.oc_token }} --server=${{ vars.oc_server }}
oc project ${{ vars.OC_NAMESPACE }} # Safeguard!
Expand All @@ -105,16 +117,21 @@ jobs:
# Deploy Helm Chart
helm dependency update
helm package --app-version="${{ env.package_tag }}" --version=$VERSION .
helm upgrade \
--set global.autoscaling=${{ inputs.autoscaling }} \
--set-string global.repository=${{ github.repository }} \
--set-string global.secrets.databasePassword=${{ secrets.DB_PASSWORD }} \
--set-string backend.containers[0].tag="${{ env.package_tag }}" \
--set-string backend.initContainers[0].tag="${{ env.package_tag }}" \
--set-string frontend.containers[0].tag="${{ env.package_tag }}" \
--install --wait --atomic ${{ env.repo_release }} \
--install --wait --atomic ${{ env.repo_release }} ./${{ github.event.repository.name }}-$VERSION.tgz \
--timeout ${{ inputs.timeout-minutes }}m \
--values ${{ inputs.values }} .
--values ${{ inputs.values }}
# print history
helm history ${{ env.repo_release }}
# Remove old build runs, build pods and deployment pods
oc delete po --field-selector=status.phase==Succeeded
61 changes: 56 additions & 5 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
name: Merge

on:
workflow_run:
workflows: [PR Closed]
types: [completed]
push:
branches: [main]
paths-ignore:
- '*.md'
- '.graphics/**'
- '.github/**'
- '!.github/workflows/merge.yml'
workflow_dispatch:
inputs:
pr_no:
Expand Down Expand Up @@ -35,8 +39,54 @@ jobs:
# Create and push semver tag
- name: Create Tags
run: |
git tag ${{ steps.changelog.outputs.tag }}
git push origin --tag
echo git tag ${{ steps.changelog.outputs.tag }}
echo git push origin --tag
# Get last merged (or current) PR number
- name: Get PR Number
id: pr-number
run: |
# Accept a provided PR number or use the API
if [ ! -z "${{ inputs.pr_no }}" ]; then
PR_NO="${{ inputs.pr_no }}"
else
HEAD=$(git log main --oneline | head -n1 | awk '{print $1}')
PR_NO=$(\
curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/bcgov/quickstart-openshift/commits/${HEAD}/pulls \
| jq .[0].number
)
fi
echo -e "Last merged PR: ${PR_NO}"
# Validate PR number and send to GitHub Output
if [ "${PR_NO}" =~ ^[0-9]+$ ]; then
echo "No PR number not found"
exit 1
fi
echo "pr=${PR_NO}" >> $GITHUB_OUTPUT
# Add tag number and latest tags to PR image
retags:
name: Retag Images
needs: [vars]
runs-on: ubuntu-22.04
permissions:
packages: write
strategy:
matrix:
package: [migrations, backend, frontend]
timeout-minutes: 1
steps:
- uses: shrink/actions-docker-registry-tag@v3
with:
registry: ghcr.io
repository: ${{ github.repository }}/${{ matrix.package }}
target: ${{ needs.vars.outputs.pr }}
tags: |
latest
${{ needs.vars.outputs.tag }}
# Get last merged (or current) PR number
- name: Get PR Number
Expand Down Expand Up @@ -73,6 +123,7 @@ jobs:
environment: prod
tag: ${{ needs.vars.outputs.tag }}
release: prod
semver: ${{ needs.vars.outputs.semver }}

promote:
name: Promote Images
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export default function Dashboard() {
})
}, [])

return <MUIDataTable title={'User List'} data={data} columns={columns} />
return <MUIDataTable title={'Users List'} data={data} columns={columns} />
}

0 comments on commit b40c456

Please sign in to comment.