Tracking pull request to merge release-1.30.0 to main #97
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: PR Build on Dev | |
on: | |
pull_request: | |
types: [labeled, synchronize] | |
# paths: | |
# - frontend/** | |
# - backend/** | |
env: | |
GIT_URL: https://github.com/bcgov/itvr.git | |
TOOLS_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-tools | |
DEV_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-dev | |
PR_NUMBER: ${{ github.event.pull_request.number }} | |
GIT_REF: ${{ github.event.pull_request.head.ref }} | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
install-oc: | |
runs-on: ubuntu-latest | |
outputs: | |
cache-hit: ${{ steps.cache.outputs.cache-hit }} | |
steps: | |
- name: Check out repository | |
uses: actions/[email protected] | |
- name: Set up cache for OpenShift CLI | |
id: cache | |
uses: actions/[email protected] | |
with: | |
path: /usr/local/bin/oc # Path where the `oc` binary will be installed | |
key: oc-cli-${{ runner.os }} | |
- name: Install OpenShift CLI (if not cached) | |
if: steps.cache.outputs.cache-hit != 'true' | |
run: | | |
curl -LO https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz | |
tar -xvf openshift-client-linux.tar.gz | |
sudo mv oc /usr/local/bin/ | |
oc version --client | |
- name: Confirm OpenShift CLI is Available | |
run: oc version --client | |
get-version: | |
if: > | |
(github.event.action == 'labeled' && github.event.label.name == 'build' && github.event.pull_request.base.ref == github.event.repository.default_branch) || | |
(github.event.action == 'synchronize' && contains(github.event.pull_request.labels.*.name, 'build') && github.event.pull_request.base.ref == github.event.repository.default_branch) | |
name: Retrieve version | |
runs-on: ubuntu-latest | |
needs: [install-oc] | |
outputs: | |
VERSION: ${{ steps.get-version.outputs.VERSION }} | |
steps: | |
- name: Restore oc command from Cache | |
uses: actions/[email protected] | |
with: | |
path: /usr/local/bin/oc | |
key: oc-cli-${{ runner.os }} | |
- name: Log in to Openshift | |
uses: redhat-actions/[email protected] | |
with: | |
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }} | |
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} | |
insecure_skip_tls_verify: true | |
namespace: ${{ env.TOOLS_NAMESPACE }} | |
- id: get-version | |
run: | | |
pr_deployed=$(helm -n ${{ env.DEV_NAMESPACE }} list | grep itvr-frontend-dev- | wc -l | tr -d '[:space:]') | |
if [ "$pr_deployed" -gt 1 ]; then | |
echo "There are at least 2 pull requests have been deployed on dev. Please uninstalled one of them in order to to have space to deploy this pull request. Exiting with code 99" | |
exit 99 | |
else | |
echo "There are $pr_deployed pull request builds on dev. Will deploy a new one." | |
version=$(echo "${{ github.event.repository.default_branch }}" | sed -E 's/release-(.*)/\1/') | |
echo "VERSION=$version" >> $GITHUB_OUTPUT | |
fi | |
build-backend: | |
if: > | |
(github.event.action == 'labeled' && github.event.label.name == 'build' && github.event.pull_request.base.ref == github.event.repository.default_branch) || | |
(github.event.action == 'synchronize' && contains(github.event.pull_request.labels.*.name, 'build') && github.event.pull_request.base.ref == github.event.repository.default_branch) | |
name: Build ITVR Backend | |
runs-on: ubuntu-latest | |
needs: [get-version] | |
timeout-minutes: 60 | |
env: | |
BUILD_SUFFIX: ${{ needs.get-version.outputs.VERSION }}-${{ github.event.pull_request.number }} | |
steps: | |
- name: Check out repository | |
uses: actions/[email protected] | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
- name: Restore oc command from Cache | |
uses: actions/[email protected] | |
with: | |
path: /usr/local/bin/oc | |
key: oc-cli-${{ runner.os }} | |
- name: Log in to Openshift | |
uses: redhat-actions/[email protected] | |
with: | |
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }} | |
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} | |
insecure_skip_tls_verify: true | |
namespace: ${{ env.TOOLS_NAMESPACE }} | |
- name: Build ITVR Backend | |
run: | | |
cd openshift/templates/backend | |
oc process -f ./backend-bc-docker.yaml NAME=itvr SUFFIX=-${{ env.BUILD_SUFFIX }} VERSION=${{ env.BUILD_SUFFIX }} GIT_URL=${{ env.GIT_URL }} GIT_REF=${{ env.GIT_REF }} | oc apply --wait=true -f - -n ${{ env.TOOLS_NAMESPACE }} | |
sleep 2s | |
for build in $(oc -n ${{ env.TOOLS_NAMESPACE }} get builds -l buildconfig=itvr-backend-${{ env.BUILD_SUFFIX }} -o jsonpath='{.items[?(@.status.phase=="Running")].metadata.name}'); do | |
echo "canceling $build" | |
oc -n ${{ env.TOOLS_NAMESPACE }} cancel-build $build | |
done | |
sleep 2s | |
oc -n ${{ env.TOOLS_NAMESPACE }} start-build itvr-backend-${{ env.BUILD_SUFFIX }} --wait=true | |
sleep 2s | |
oc tag ${{ env.TOOLS_NAMESPACE }}/itvr-backend:${{ env.BUILD_SUFFIX }} ${{ env.DEV_NAMESPACE }}/itvr-backend:${{ env.BUILD_SUFFIX }} | |
build-task-queue: | |
if: > | |
(github.event.action == 'labeled' && github.event.label.name == 'build' && github.event.pull_request.base.ref == github.event.repository.default_branch) || | |
(github.event.action == 'synchronize' && contains(github.event.pull_request.labels.*.name, 'build') && github.event.pull_request.base.ref == github.event.repository.default_branch) | |
name: Build ITVR Task Queue | |
runs-on: ubuntu-latest | |
needs: [get-version] | |
timeout-minutes: 60 | |
env: | |
BUILD_SUFFIX: ${{ needs.get-version.outputs.VERSION }}-${{ github.event.pull_request.number }} | |
steps: | |
- name: Check out repository | |
uses: actions/[email protected] | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
- name: Restore oc command from Cache | |
uses: actions/[email protected] | |
with: | |
path: /usr/local/bin/oc | |
key: oc-cli-${{ runner.os }} | |
- name: Log in to Openshift | |
uses: redhat-actions/[email protected] | |
with: | |
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }} | |
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} | |
insecure_skip_tls_verify: true | |
namespace: ${{ env.TOOLS_NAMESPACE }} | |
- name: Build ITVR Taskq | |
run: | | |
cd openshift/templates/task-queue | |
oc process -f ./task-queue-bc-docker.yaml NAME=itvr SUFFIX=-${{ env.BUILD_SUFFIX }} VERSION=${{ env.BUILD_SUFFIX }} GIT_URL=${{ env.GIT_URL }} GIT_REF=${{ env.GIT_REF }} | oc apply --wait=true -f - -n ${{ env.TOOLS_NAMESPACE }} | |
sleep 2s | |
for build in $(oc -n ${{ env.TOOLS_NAMESPACE }} get builds -l buildconfig=itvr-task-queue-${{ env.BUILD_SUFFIX }} -o jsonpath='{.items[?(@.status.phase=="Running")].metadata.name}'); do | |
echo "canceling $build" | |
oc -n ${{ env.TOOLS_NAMESPACE }} cancel-build $build | |
done | |
sleep 2s | |
oc -n ${{ env.TOOLS_NAMESPACE }} start-build itvr-task-queue-${{ env.BUILD_SUFFIX }} --wait=true | |
sleep 2s | |
oc tag ${{ env.TOOLS_NAMESPACE }}/itvr-task-queue:${{ env.BUILD_SUFFIX }} ${{ env.DEV_NAMESPACE }}/itvr-task-queue:${{ env.BUILD_SUFFIX }} | |
build-frontend: | |
if: > | |
(github.event.action == 'labeled' && github.event.label.name == 'build' && github.event.pull_request.base.ref == github.event.repository.default_branch) || | |
(github.event.action == 'synchronize' && contains(github.event.pull_request.labels.*.name, 'build') && github.event.pull_request.base.ref == github.event.repository.default_branch) | |
name: Build ITVR Frontend | |
runs-on: ubuntu-latest | |
needs: [get-version] | |
timeout-minutes: 60 | |
env: | |
BUILD_SUFFIX: ${{ needs.get-version.outputs.VERSION }}-${{ github.event.pull_request.number }} | |
steps: | |
- name: Check out repository | |
uses: actions/[email protected] | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
- name: Restore oc command from Cache | |
uses: actions/[email protected] | |
with: | |
path: /usr/local/bin/oc | |
key: oc-cli-${{ runner.os }} | |
- name: Log in to Openshift | |
uses: redhat-actions/[email protected] | |
with: | |
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }} | |
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} | |
insecure_skip_tls_verify: true | |
namespace: ${{ env.TOOLS_NAMESPACE }} | |
- name: Build ITVR Frontend | |
run: | | |
cd openshift/templates/frontend | |
oc process -f ./frontend-bc-docker.yaml NAME=itvr SUFFIX=-${{ env.BUILD_SUFFIX }} VERSION=${{ env.BUILD_SUFFIX }} GIT_URL=${{ env.GIT_URL }} GIT_REF=${{ env.GIT_REF }} | oc apply --wait=true -f - -n ${{ env.TOOLS_NAMESPACE }} | |
sleep 2s | |
for build in $(oc -n ${{ env.TOOLS_NAMESPACE }} get builds -l buildconfig=itvr-frontend-${{ env.BUILD_SUFFIX }} -o jsonpath='{.items[?(@.status.phase=="Running")].metadata.name}'); do | |
echo "canceling $build" | |
oc -n ${{ env.TOOLS_NAMESPACE }} cancel-build $build | |
done | |
sleep 2s | |
oc -n ${{ env.TOOLS_NAMESPACE }} start-build itvr-frontend-${{ env.BUILD_SUFFIX }} --wait=true | |
sleep 2s | |
oc tag ${{ env.TOOLS_NAMESPACE }}/itvr-frontend:${{ env.BUILD_SUFFIX }} ${{ env.DEV_NAMESPACE }}/itvr-frontend:${{ env.BUILD_SUFFIX }} | |
build-cra: | |
if: > | |
(github.event.action == 'labeled' && github.event.label.name == 'build' && github.event.pull_request.base.ref == github.event.repository.default_branch) || | |
(github.event.action == 'synchronize' && contains(github.event.pull_request.labels.*.name, 'build') && github.event.pull_request.base.ref == github.event.repository.default_branch) | |
name: Build ITVR CRA | |
runs-on: ubuntu-latest | |
needs: [get-version] | |
timeout-minutes: 60 | |
env: | |
BUILD_SUFFIX: ${{ needs.get-version.outputs.VERSION }}-${{ github.event.pull_request.number }} | |
steps: | |
- name: Check out repository | |
uses: actions/[email protected] | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
- name: Restore oc command from Cache | |
uses: actions/[email protected] | |
with: | |
path: /usr/local/bin/oc | |
key: oc-cli-${{ runner.os }} | |
- name: Log in to Openshift | |
uses: redhat-actions/[email protected] | |
with: | |
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }} | |
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} | |
insecure_skip_tls_verify: true | |
namespace: ${{ env.TOOLS_NAMESPACE }} | |
- name: Build ITVR CRA | |
run: | | |
cd openshift/templates/cra | |
oc process -f ./cra-bc-docker.yaml NAME=itvr SUFFIX=-${{ env.BUILD_SUFFIX }} VERSION=${{ env.BUILD_SUFFIX }} GIT_URL=${{ env.GIT_URL }} GIT_REF=${{ env.GIT_REF }} | oc apply --wait=true -f - -n ${{ env.TOOLS_NAMESPACE }} | |
sleep 2s | |
for build in $(oc -n ${{ env.TOOLS_NAMESPACE }} get builds -l buildconfig=itvr-cra-${{ env.BUILD_SUFFIX }} -o jsonpath='{.items[?(@.status.phase=="Running")].metadata.name}'); do | |
echo "canceling $build" | |
oc -n ${{ env.TOOLS_NAMESPACE }} cancel-build $build | |
done | |
sleep 2s | |
oc -n ${{ env.TOOLS_NAMESPACE }} start-build itvr-cra-${{ env.BUILD_SUFFIX }} --wait=true | |
sleep 2s | |
oc tag ${{ env.TOOLS_NAMESPACE }}/itvr-cra:${{ env.BUILD_SUFFIX }} ${{ env.DEV_NAMESPACE }}/itvr-cra:${{ env.BUILD_SUFFIX }} | |
deploy: | |
if: > | |
(github.event.action == 'labeled' && github.event.label.name == 'build' && github.event.pull_request.base.ref == github.event.repository.default_branch) || | |
(github.event.action == 'synchronize' && contains(github.event.pull_request.labels.*.name, 'build') && github.event.pull_request.base.ref == github.event.repository.default_branch) | |
name: Deploy ITVR | |
runs-on: ubuntu-latest | |
timeout-minutes: 60 | |
needs: [get-version, build-backend, build-frontend, build-cra, build-task-queue] | |
env: | |
VERSION: ${{ needs.get-version.outputs.VERSION }} | |
steps: | |
- name: Checkout Manifest repository | |
uses: actions/[email protected] | |
with: | |
repository: bcgov-c/tenant-gitops-ac294c | |
ref: main | |
ssh-key: ${{ secrets.MANIFEST_REPO_DEPLOY_KEY }} | |
- name: Replace VERSION in values-dev-pr.yaml | |
uses: jacobtomlinson/gha-find-replace@v3 | |
with: | |
find: "VERSION" | |
replace: "${{ env.VERSION }}" | |
include: "itvr/values-dev-pr.yaml" | |
regex: false | |
- name: Replace PRNUMBER in values-dev-pr.yaml | |
uses: jacobtomlinson/gha-find-replace@v3 | |
with: | |
find: "PRNUMBER" | |
replace: "${{ env.PR_NUMBER }}" | |
include: "itvr/values-dev-pr.yaml" | |
regex: false | |
- name: Restore oc command from Cache | |
uses: actions/[email protected] | |
with: | |
path: /usr/local/bin/oc | |
key: oc-cli-${{ runner.os }} | |
- name: Log in to Openshift | |
uses: redhat-actions/[email protected] | |
with: | |
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }} | |
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} | |
insecure_skip_tls_verify: true | |
namespace: ${{ env.TOOLS_NAMESPACE }} | |
- name: Show the values-dev-pr.yaml after replacement | |
shell: bash {0} | |
run: | | |
pwd | |
ls -l | |
cat itvr/values-dev-pr.yaml | |
- name: Helm Deployment | |
shell: bash {0} | |
run: | | |
cd postgres-pr | |
helm -n ${{ env.DEV_NAMESPACE }} -f ./values-dev-pr.yaml upgrade --install itvr-dev-${{ env.PR_NUMBER }}-postgresql oci://registry-1.docker.io/bitnamicharts/postgresql --version 15.5.17 | |
cd ../minio-pr | |
helm -n ${{ env.DEV_NAMESPACE }} -f ./values-dev-pr.yaml upgrade --install itvr-dev-${{ env.PR_NUMBER }}-minio oci://registry-1.docker.io/bitnamicharts/minio --version 14.8.0 | |
sleep 60s | |
cd ../itvr | |
helm -n ${{ env.DEV_NAMESPACE }} -f ./values-dev-pr.yaml upgrade --install itvr-dev-${{ env.PR_NUMBER }} . \ | |
--set frontend.podAnnotations.rolloutTriggered="A$(date +%s)E" \ | |
--set backend.podAnnotations.rolloutTriggered="A$(date +%s)E" \ | |
--set cra.podAnnotations.rolloutTriggered="A$(date +%s)E" \ | |
--set task-queue.podAnnotations.rolloutTriggered="A$(date +%s)E" |