Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add artifactory and argo #13

Closed
wants to merge 69 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
38b3e55
Use updated quickstart template
barrfalk Dec 8, 2023
3ec9267
Exclude deploy action since we'll be using Argo to pull the images
barrfalk Dec 12, 2023
6229857
Update pr-open.yml
barrfalk Dec 13, 2023
1bb7ba3
Update pr-open.yml
barrfalk Dec 13, 2023
2030355
Added push to artifactory
barrfalk Dec 14, 2023
926bd24
Update pr-open.yml
barrfalk Dec 14, 2023
058070e
Update .push-to-artifactory.yml
barrfalk Dec 14, 2023
44aa43b
Update .push-to-artifactory.yml
barrfalk Dec 14, 2023
2684f1e
Update .push-to-artifactory.yml
barrfalk Dec 14, 2023
482b486
Update .push-to-artifactory.yml
barrfalk Dec 14, 2023
5d15660
Update .push-to-artifactory.yml
barrfalk Dec 14, 2023
7e56938
Update .push-to-artifactory.yml
barrfalk Dec 14, 2023
81ebfe8
Update .push-to-artifactory.yml
barrfalk Dec 18, 2023
e9ededb
Update .push-to-artifactory.yml
barrfalk Dec 18, 2023
433ea51
Update .push-to-artifactory.yml
barrfalk Dec 18, 2023
a874c5a
Update .push-to-artifactory.yml
barrfalk Dec 18, 2023
8b07f60
Pushes helm chart to ghcr
barrfalk Dec 19, 2023
4b7e3ee
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
74dec55
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
660660d
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
fb770a3
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
80d13a1
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
3f44399
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
70e48da
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
dbe165b
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
7ea275e
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
5d60c35
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
de0a39b
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
fe95066
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
d622a9e
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
481a705
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
67b5c7a
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
548e1f3
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
4761527
Cleanup
barrfalk Dec 19, 2023
edc8132
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
6d86d1a
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
e2ec872
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
8dca20c
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
393f573
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
84a00cb
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
c58e395
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
bbfe263
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
2bbe93e
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
b40e5a8
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
b752e96
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
5c4e41d
Github action to push helm to gitops repo
barrfalk Dec 19, 2023
e6e47cf
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
2a904f6
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
1332eaa
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
e0bed63
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
480b158
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
68767c7
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
7059f72
Update .push-helm-chart.yml
barrfalk Dec 19, 2023
7fba0bd
Update .push-helm-chart.yml
barrfalk Dec 20, 2023
7a930c1
Update .push-helm-chart.yml
barrfalk Dec 20, 2023
9ea4f05
Update .push-helm-chart.yml
barrfalk Dec 20, 2023
9db7540
Update .push-helm-chart.yml
barrfalk Dec 20, 2023
8f8d368
Update .push-helm-chart.yml
barrfalk Dec 20, 2023
251a60d
Update .push-helm-chart.yml
barrfalk Dec 20, 2023
06c05db
Update .push-helm-chart.yml
barrfalk Dec 20, 2023
7d370f1
Update .push-helm-chart.yml
barrfalk Dec 20, 2023
44afe14
Update .push-helm-chart.yml
barrfalk Dec 20, 2023
59be8d7
Update .push-helm-chart.yml
barrfalk Dec 20, 2023
1c1e93d
Update values.yaml
barrfalk Dec 20, 2023
b073327
Update values.yaml
barrfalk Dec 20, 2023
34baf4c
Update values.yaml
barrfalk Dec 20, 2023
64a88ef
Update Chart.yaml
barrfalk Jan 4, 2024
4c57527
Update Chart.yaml
barrfalk Jan 4, 2024
5674875
Update Chart.yaml
barrfalk Jan 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .github/dependabot.yml

This file was deleted.

132 changes: 132 additions & 0 deletions .github/workflows/.deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
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
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!

# Interrupt any previous jobs (status = pending-upgrade)
PREVIOUS=$(helm status ${{ env.repo_release }} -o json | jq .info.status || true)
if [[ ${PREVIOUS} =~ pending ]]; then
echo "Rollback triggered"
helm rollback ${{ env.repo_release }} || \
helm uninstall ${{ env.repo_release }}
fi

# Deploy Helm Chart
helm dependency update
helm package --app-version="${{ env.package_tag }}" --version=${{ inputs.tag }} .

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 }}" \
${{ 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
156 changes: 156 additions & 0 deletions .github/workflows/.push-helm-chart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
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
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: Setup SSH for Target Repository
run: |
mkdir -p ~/.ssh
echo "${{ secrets.MANIFEST_REPO_DEPLOY_KEY }}" > ~/.ssh/id_rsa
echo "${{ secrets.MANIFEST_REPO_DEPLOY_KEY_PUB }}" > ~/.ssh/id_rsa.pub
chmod 600 ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa.pub
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts

- name: Setup Git Config
run: |
git config --global user.name "${{ vars.GLOBAL_USER}}"
git config --global user.email "${{ vars.GLOBAL_EMAIL}}"


- name: Clone Target Repository
run: |
git clone [email protected]:${{ vars.GITOPS_REPO}}.git target-repo

- name: Copy Helm Chart
run: |
cp -r ./charts/* target-repo/helm-chart/

- name: Commit and Push Changes to Target Repository
run: |
cd target-repo
git config user.name "${{ vars.GLOBAL_USER}}"
git config user.email "${{ vars.GLOBAL_EMAIL}}"

# Stash any changes in the working directory
git stash --include-untracked

# Check if the branch exists
if git ls-remote --heads origin "update-helm-chart-${{ inputs.tag }}" ; then
# If branch exists, just check it out
git checkout "update-helm-chart-${{ inputs.tag }}"
else
# If branch doesn't exist, create a new one
git checkout -b "update-helm-chart-${{ inputs.tag }}"
fi

# Apply stashed changes, if any
git stash pop || true

git add .
# Check if there are any changes
if git diff --staged --quiet; then
echo "No changes to commit."
else
git commit -m "Update Helm chart"
git push --set-upstream origin "update-helm-chart-${{ inputs.tag }}"
fi
- name: Create Pull Request via GitHub API
env:
GITHUB_TOKEN: ${{ secrets.GITOPS_PAT }}
run: |
curl \
-X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ vars.GITOPS_REPO }}/pulls \
-d "{\"title\": \"Update Helm Chart\", \"head\": \"update-helm-chart-${{ inputs.tag }}\", \"base\": \"main\", \"body\": \"Automated update of Helm chart\"}"
74 changes: 74 additions & 0 deletions .github/workflows/.tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: .Tests

on:
workflow_call:
inputs:
### Required
target:
description: PR number, test or prod
required: true
type: string

jobs:
integration-tests:
name: Integration Tests
runs-on: ubuntu-22.04
timeout-minutes: 1
steps:
- uses: actions/checkout@v4
- id: cache-npm
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-build-cache-node-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-cache-node-modules-
${{ runner.os }}-build-
${{ runner.os }}-

- name: Integration tests
env:
API_NAME: nest
BASE_URL: https://${{ github.event.repository.name }}-${{ inputs.target }}-frontend.apps.silver.devops.gov.bc.ca
run: |
cd integration-tests
npm ci
node src/main.js

cypress-e2e:
name: E2E Tests
runs-on: ubuntu-22.04
defaults:
run:
working-directory: frontend
strategy:
matrix:
browser: [chrome, firefox, edge]
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- id: cache-npm
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-build-cache-node-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-cache-node-modules-
${{ runner.os }}-build-
${{ runner.os }}-

- uses: cypress-io/github-action@v6
name: Cypress run
env:
CYPRESS_baseUrl: https://${{ github.event.repository.name }}-${{ inputs.target }}-frontend.apps.silver.devops.gov.bc.ca/
with:
config: pageLoadTimeout=10000
working-directory: ./frontend
browser: ${{ matrix.browser }}

- uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots
path: ./cypress/screenshots
if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn`
Loading
Loading