Build & Deploy to DEV from main branch #46
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: Build & Deploy to DEV from main branch | |
env: | |
# 🖊️ EDIT your repository secrets to log into your OpenShift cluster and set up the context. | |
# See https://github.com/redhat-actions/oc-login#readme for how to retrieve these values. | |
# To get a permanent token, refer to https://github.com/redhat-actions/oc-login/wiki/Using-a-Service-Account-for-GitHub-Actions | |
OPENSHIFT_SERVER: ${{ secrets.OPENSHIFT_SERVER }} | |
OPENSHIFT_TOKEN: ${{ secrets.OPENSHIFT_TOKEN }} | |
OPENSHIFT_NAMESPACE: ${{ secrets.GRAD_BUSINESS_NAMESPACE }}-dev | |
SPRING_BOOT_IMAGE_NAME: educ-grad-distribution-api-dc | |
DOCKER_ARTIFACTORY_REPO: artifacts.developer.gov.bc.ca/docker-remote | |
REPO_NAME: "educ-grad-distribution-api" | |
BRANCH_NAME: "main" | |
APP_DOMAIN: ${{ secrets.APP_DOMAIN }} | |
TAG: "latest" | |
MIN_CPU: "20m" | |
MAX_CPU: "250m" | |
MIN_MEM: "100Mi" | |
MAX_MEM: "2048Mi" | |
#GRAD2-1947 Resource Optimization | |
MIN_REPLICAS: "3" | |
MAX_REPLICAS: "5" | |
STORAGE_LIMIT: 16Gi | |
on: | |
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows | |
workflow_dispatch: | |
jobs: | |
openshift-ci-cd: | |
name: Build and deploy to OpenShift DEV | |
# ubuntu-20.04 can also be used. | |
runs-on: ubuntu-20.04 | |
environment: dev | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v3 | |
- name: Determine image tags | |
if: env.TAG == '' | |
run: | | |
echo "TAG=latest ${GITHUB_SHA::12}" | tee -a $GITHUB_ENV | |
# The path the image was pushed to is now stored in ${{ steps.push-image.outputs.registry-path }} | |
- name: Install oc | |
uses: redhat-actions/openshift-tools-installer@v1 | |
with: | |
oc: 4 | |
# https://github.com/redhat-actions/oc-login#readme | |
- name: Deploy | |
run: | | |
set -eux | |
# Login to OpenShift and select project | |
oc login --token=${{ env.OPENSHIFT_TOKEN }} --server=${{ env.OPENSHIFT_SERVER }} | |
oc project ${{ env.OPENSHIFT_NAMESPACE }} | |
# Cancel any rollouts in progress | |
oc rollout cancel dc/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \ | |
|| true && echo "No rollout in progress" | |
# run build | |
# apply build config | |
oc process -f https://raw.githubusercontent.com/bcgov/EDUC-GRAD-DISTRIBUTION-API/grad-release/tools/openshift/api.bc.yaml -p REPO_NAME=${{ env.REPO_NAME }} -p BRANCH_NAME=${{ env.BRANCH_NAME }} | oc apply -f - | |
# run build --follow shows log, --wait throws non-zero if fail | |
oc start-build ${{ env.REPO_NAME }}-bc --follow --wait | |
# Process and apply deployment template | |
oc process -f tools/openshift/api.dc.yaml -p IS_NAMESPACE=${{ env.OPENSHIFT_NAMESPACE }} -p REPO_NAME=${{ env.REPO_NAME }} -p TAG_NAME=${{ env.TAG }} -p HOST_ROUTE=${{ env.REPO_NAME }}-${{ env.OPENSHIFT_NAMESPACE }}.${{ env.APP_DOMAIN }} -p MIN_REPLICAS=${{ env.MIN_REPLICAS }} -p MAX_REPLICAS=${{ env.MAX_REPLICAS }} -p MIN_CPU=${{ env.MIN_CPU }} -p MAX_CPU=${{ env.MAX_CPU }} -p MIN_MEM=${{ env.MIN_MEM }} -p MAX_MEM=${{ env.MAX_MEM }} -p STORAGE_LIMIT=${{ env.STORAGE_LIMIT }} \ | |
| oc apply -f - | |
# Start rollout (if necessary) and follow it | |
oc rollout latest dc/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \ | |
|| true && echo "Rollout in progress" | |
oc logs -f dc/${{ env.SPRING_BOOT_IMAGE_NAME }} | |
# Get status, returns 0 if rollout is successful | |
oc rollout status dc/${{ env.SPRING_BOOT_IMAGE_NAME }} | |
# now hit it with a zap scan | |
- name: ZAP Scan | |
uses: zaproxy/action-api-scan@v0.1.0 | |
with: | |
target: 'https://${{ env.REPO_NAME }}-${{ env.OPENSHIFT_NAMESPACE }}-dev.apps.silver.devops.gov.bc.ca/api/v1/api-docs' |