Skip to content

trigger build

trigger build #83

name: "api-build-and-push"
on:
workflow_dispatch:
push:
branches:
- emerald-stage
paths-ignore:
- database/**
- package.json
- package-lock.json
- CHANGELOG.md
- .conventional-changelog.mjs
- .release-it.json
- postman/**
- localdb/**
- postgres/**
- crunchydb/**
jobs:
build-backend:
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.400'
- uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget
- name: Setup Tools
uses: ./.github/actions/setup-tools
- name: Build backend
run: |
pwd
dotnet build ./server/server.sln
- name: Test backend
run: dotnet test ./server/server.sln --no-build
# # SonarQube integration for backend
# - name: SonarQube Scan Backend
# uses: sonarsource/sonarcloud-github-action@v2
# env:
# SONAR_HOST_URL: https://sonarcloud.io
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_TEST }}
build-frontend:
runs-on: ubuntu-22.04
timeout-minutes: 10
permissions:
contents: read
packages: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install Angular CLI
run: |
cd ./frontend
npm install -g @angular/cli
- name: Install project dependencies
run: |
cd ./frontend
npm install
- name: Build frontend
run: |
cd ./frontend
ng build --configuration=production
- name: Run frontend tests
run: |
cd ./frontend
ng test --watch=false --progress=false --browsers=ChromeHeadless --code-coverage --source-map=false
continue-on-error: true
# # SonarQube integration frontend
# - name: SonarQube Scan
# uses: sonarsource/sonarcloud-github-action@v2
# env:
# SONAR_HOST_URL: https://sonarcloud.io
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_TEST }}
docker-build-backend:
needs: [build-backend]
runs-on: ubuntu-22.04
timeout-minutes: 10
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Setup Tools
uses: ./.github/actions/setup-tools
- name: Build Docker image
run: cd server && docker build -t strdss-backend -f Dockerfile .
- name: Tag Docker image
run: docker tag strdss-backend artifacts.developer.gov.bc.ca/sf4a-strdss/server:dev-6cd0e88
- name: Push Docker image to Artifactory
run: |
docker login artifacts.developer.gov.bc.ca -u ${{ secrets.JFROG_USERNAME }} -p ${{ secrets.JFROG_PASSWORD }}
docker push artifacts.developer.gov.bc.ca/sf4a-strdss/server:dev-6cd0e88
# Update API Specification in the service registry - RBA skip for initial implmentation
# - name: Publish API Specification
# if: steps.helm.outcome == 'success'
# run: |
# set -e # Exit on error
# IMAGE="${{ steps.meta.outputs.tags || steps.meta-test.outputs.tags || steps.meta-prod.outputs.tags }} "
# IMAGE_TAG=$(echo "$IMAGE" | awk -F':' '{print $NF}')
# echo $IMAGE_TAG
# # Get access token from auth endpoint
# export TOKEN=$(curl -X POST \
# ${{ secrets.AUTH_TOKEN_ENDPOINT }} \
# -H 'Content-Type: application/x-www-form-urlencoded' \
# -d grant_type=client_credentials \
# -d client_id=${{ secrets.REGISTRY_CLIENT_ID }} \
# -d client_secret=${{ secrets.REGISTRY_CLIENT_SECRET }} | jq -r '.access_token')
# echo "Access Token: $TOKEN"
# http_response=$(curl -s -o response.txt -w "%{http_code}" -X POST \
# -H "Authorization: Bearer $TOKEN" \
# -H "Content-type: application/json; artifactType=OPENAPI" \
# -H "Authorization: Bearer $TOKEN" \
# -H "X-Registry-ArtifactId: justin-claim" \
# -d @CustomClaimApiSpec.json \
# ${{ secrets.SERVICE_REGISTRY_HOST_URL }}/apis/registry/v2/groups/JUSTIN/artifacts?ifExists=UPDATE)
# if [ $http_response != "200" ]; then
# echo "Error: Failed to publish artifacts"
# echo "Server returned:"
# cat response.txt
# exit 1
# else
# echo "Server returned:"
# cat response.txt
# fi
# working-directory: ${{env.working-directory}}
docker-build-frontend:
needs: [build-frontend]
runs-on: ubuntu-22.04
timeout-minutes: 10
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Setup Tools
uses: ./.github/actions/setup-tools
- name: Render style_nonce
id: render_style_nonce
run: echo "::set-output name=style_nonce::$(echo -n ${{ github.sha }} | base64)"
- name: Build Docker image
run: cd frontend && docker build -t strdss-frontend -f Dockerfile .
- name: Tag Docker image
run: docker tag strdss-frontend artifacts.developer.gov.bc.ca/sf4a-strdss/frontend:dev-6cd0e88
- name: Push Docker image to Artifactory
run: |
docker login artifacts.developer.gov.bc.ca -u ${{ secrets.JFROG_USERNAME }} -p ${{ secrets.JFROG_PASSWORD }}
docker push artifacts.developer.gov.bc.ca/sf4a-strdss/frontend:dev-6cd0e88
package-h-chart-backend:
needs: [docker-build-backend]
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- name: Checkout ArgoCD Repo
id: gitops
# if: steps.publish.outcome == 'success'
uses: actions/checkout@v4
with:
repository: bcgov-c/tenant-gitops-b0471a
ref: develop
token: ${{ secrets.GITOPS }} # `GITOPS` is a secret that contains your PAT
path: gitops
- name: Update Helm Values and Commit backend
id: helm
# if: steps.gitops.outcome == 'success' # Only run if the previous step (publish) was successful
run: |
pwd
# Navigate to the directory containing your Helm values file for the environment develop -> DEV, test -> test and
#cd gitops
cd gitops/charts/backend
IMAGE="${{ steps.meta.outputs.tags || steps.meta-test.outputs.tags || steps.meta-prod.outputs.tags }} "
IMAGE_TAG=$(echo "$IMAGE" | awk -F':' '{print $NF}')
echo "Image Tag:"
echo $IMAGE_TAG
# Update the Helm values file with the new image tag or (SHA)
DATETIME=$(date +'%Y-%m-%d %H:%M:%S') # Get current date and time
# check if branch is dev update dev_values with sed if branch is test update test value if branch is main update prod values
if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
echo "This is the main branch"
sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/prod_values.yaml
elif [[ "$GITHUB_REF" == "refs/heads/emerald" ]]; then
echo "This is the emerald branch"
sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/dev_values.yaml
elif [[ "$GITHUB_REF" == "refs/heads/test" ]]; then
echo "This is the test branch"
sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/test_values.yaml
else
echo updating dev values for CIs
sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/dev_values.yaml
fi
# Commit and push the changes
git config --global user.email "[email protected]"
git config --global user.name "Rick Anderson"
git add ../../deploy/dev_values.yaml
git add ../../deploy/prod_values.yaml
git add ../../deploy/test_values.yaml
pwd
# Repackage Helm Chart
cd ../gitops/charts
helm package ../../backend/
git add .
git commit -m "Update image tag to $IMAGE_TAG on $DATETIME"
git push origin develop # Update the branch name as needed
package-h-chart-frontend:
needs: [docker-build-frontend]
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- name: Checkout ArgoCD Repo
id: gitops
# if: steps.publish.outcome == 'success'
uses: actions/checkout@v4
with:
repository: bcgov-c/tenant-gitops-b0471a
ref: develop
token: ${{ secrets.GITOPS }} # `GITOPS` is a secret that contains your PAT
path: gitops
- name: Update Helm Values and Commit backend
id: helm
# if: steps.gitops.outcome == 'success' # Only run if the previous step (publish) was successful
run: |
pwd
# Navigate to the directory containing your Helm values file for the environment develop -> DEV, test -> test and
#cd gitops
cd gitops/charts/frontend
IMAGE="${{ steps.meta.outputs.tags || steps.meta-test.outputs.tags || steps.meta-prod.outputs.tags }} "
IMAGE_TAG=$(echo "$IMAGE" | awk -F':' '{print $NF}')
echo "Image Tag:"
echo $IMAGE_TAG
# Update the Helm values file with the new image tag or (SHA)
DATETIME=$(date +'%Y-%m-%d %H:%M:%S') # Get current date and time
# check if branch is dev update dev_values with sed if branch is test update test value if branch is main update prod values
if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
echo "This is the main branch"
sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/prod_values.yaml
elif [[ "$GITHUB_REF" == "refs/heads/emerald" ]]; then
echo "This is the emerald branch"
sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/dev_values.yaml
elif [[ "$GITHUB_REF" == "refs/heads/test" ]]; then
echo "This is the test branch"
sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/test_values.yaml
else
echo updating dev values for CIs
sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/dev_values.yaml
fi
# Commit and push the changes
git config --global user.email "[email protected]"
git config --global user.name "Rick Anderson"
git add ../../deploy/dev_values.yaml
git add ../../deploy/prod_values.yaml
git add ../../deploy/test_values.yaml
pwd
# Repackage Helm Chart
cd ../gitops/charts
helm package ../../frontend/
git add .
git commit -m "Update image tag to $IMAGE_TAG on $DATETIME"
git push origin develop # Update the branch name as needed
# package-h-chart-database:
#needs: [docker-build-frontend]
# runs-on: ubuntu-22.04
# timeout-minutes: 10
# steps:
# - name: Checkout ArgoCD Repo
# id: gitops
# if: steps.publish.outcome == 'success'
# uses: actions/checkout@v4
# with:
# repository: bcgov-c/tenant-gitops-b0471a
# ref: develop
# token: ${{ secrets.GITOPS }} # `GITOPS` is a secret that contains your PAT
# path: gitops
# - name: Update Helm Values and Commit database
# id: helm
# if: steps.gitops.outcome == 'success' # Only run if the previous step (publish) was successful
# run: |
# pwd
# ls -ARl gitops/
# Navigate to the directory containing your Helm values file for the environment develop -> DEV, test -> test and
#cd gitops
# cd gitops/charts/database
# IMAGE="${{ steps.meta.outputs.tags || steps.meta-test.outputs.tags || steps.meta-prod.outputs.tags }} "
# IMAGE_TAG=$(echo "$IMAGE" | awk -F':' '{print $NF}')
# echo "Image Tag:"
# echo $IMAGE_TAG
# # Update the Helm values file with the new image tag or (SHA)
# DATETIME=$(date +'%Y-%m-%d %H:%M:%S') # Get current date and time
# check if branch is dev update dev_values with sed if branch is test update test value if branch is main update prod values
# if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
# echo "This is the main branch"
# sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/prod_values.yaml
# elif [[ "$GITHUB_REF" == "refs/heads/emerald" ]]; then
# echo "This is the emerald branch"
# sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/dev_values.yaml
# elif [[ "$GITHUB_REF" == "refs/heads/test" ]]; then
# echo "This is the test branch"
# sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/test_values.yaml
# else
# echo updating dev values for CIs
# sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/dev_values.yaml
# fi
# Commit and push the changes
# git config --global user.email "[email protected]"
# git config --global user.name "Rick Anderson"
# git add ../../deploy/dev_values.yaml
# git add ../../deploy/prod_values.yaml
# git add ../../deploy/test_values.yaml
# pwd
# Repackage Helm Chart
# cd ../gitops/charts
# helm package ../../database/
# git add .
# ls -s
# git commit -m "Update image tag to $IMAGE_TAG on $DATETIME"
# git push origin develop # Update the branch name as needed