Deploy to TEST #38
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: Deploy to TEST | |
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 }}-test | |
SPRING_BOOT_IMAGE_NAME: educ-rule-engine-api-dc | |
REPO_NAME: "educ-rule-engine-api" | |
APP_DOMAIN: ${{ secrets.APP_DOMAIN }} | |
NAMESPACE: ${{ secrets.GRAD_BUSINESS_NAMESPACE }} | |
TAG: "latest" | |
MIN_CPU: "20m" | |
MAX_CPU: "100m" | |
MIN_MEM: "200Mi" | |
MAX_MEM: "750Mi" | |
MIN_REPLICAS: "3" | |
MAX_REPLICAS: "7" | |
on: | |
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows | |
workflow_dispatch: | |
jobs: | |
deploy-to-openshift-test: | |
name: Deploy to OpenShift TEST | |
# ubuntu-20.04 can also be used. | |
runs-on: ubuntu-20.04 | |
environment: test | |
outputs: | |
ROUTE: ${{ steps.deploy-and-expose.outputs.route }} | |
SELECTOR: ${{ steps.deploy-and-expose.outputs.selector }} | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v2 | |
- name: Get latest tag | |
uses: actions-ecosystem/action-get-latest-tag@v1 | |
id: get-latest-tag | |
- name: Install oc | |
uses: redhat-actions/openshift-tools-installer@v1 | |
with: | |
oc: 4 | |
# https://github.com/redhat-actions/oc-login#readme | |
- uses: actions/checkout@v2 | |
- 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" | |
oc tag ${{ env.NAMESPACE }}-dev/${{ env.REPO_NAME }}:${{ steps.get-latest-tag.outputs.tag }} ${{ env.NAMESPACE }}-test/${{ env.REPO_NAME }}:${{ steps.get-latest-tag.outputs.tag }} | |
# 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=${{ steps.get-latest-tag.outputs.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 }} \ | |
| 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 }} |