Skip to content

Frontend - Prod specific frontend image tagging and deploy #11

Frontend - Prod specific frontend image tagging and deploy

Frontend - Prod specific frontend image tagging and deploy #11

# This is the workflow that creates three new images for CSRS prod
# Credit goes to Suganth /his CDDS and SCSS templates
name: Frontend - Prod specific frontend image tagging and deploy
# Controls when the workflow will run
# This one is triggered only manually as an extra pre-caution
on:
# Allows you to run this workflow manually from the Actions tab
# retrsict execution to limited set of people
workflow_dispatch:
inputs:
app:
description: 'App Name (jag-csrs)'
required: true
default: jag-csrs
env:
#change this to suit your need/environment that you are targetting
#note to self : restrict who can execute this workflow
description: 'Image Target Env'
required: true
default: 'test'
# By default keeping it as test
# If we want it for prod we have to specify that
# This is to be cautious/this is an extra level of defense
gittag:
description: 'Release Tag'
required: true
default: latest
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build-push-image:
# The type of runner that the job will run on
runs-on: ubuntu-latest
#https://stackoverflow.com/a/70868036
environment: prod
env:
app: ${{github.event.inputs.app}}
env: ${{github.event.inputs.env}}
gittag: ${{github.event.inputs.gittag}}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Git Checkout
uses: actions/checkout@v2
# Get Git latest short Sha# from the release branch used. This Sha# will be used in image tagging as well as DC Pod labelling.
- name: Get git tag
run: |
if [[ -z "$gittag" ]]; then
echo "Exiting"
exit 1
fi
- name: env variables
run: |
if [[ -z "$app" ]]; then
echo "Exiting"
exit 1
fi
if [[ -z "$env" ]]; then
echo "Exiting"
exit 1
fi
- name: print env variables
run: |
echo "Release Application: ${{ env.app }}"
echo "Release Git tag: ${{env.gittag}}"
echo "Deployment env: ${{env.env}}"
# Login to OpenShift Tools Space to tag images appropriately
# It assumes that the images are already built for test by running .github/workflows/build-all-on-tagging.yml
- name: Login to OpenShift Tools Space
uses: redhat-actions/oc-login@v1
env:
OPENSHIFT_NAMESPACE: ${{secrets.OPENSHIFT_LICENSE_PLATE}}-tools
OPENSHIFT_USER: ${{secrets.OPENSHIFT_TOOLS_DEPLOYER_SA_USERNAME}}
with:
#username: ${{secrets.OPENSHIFT_BUILDER_SA_USERNAME_TOOLs}}
openshift_token: ${{secrets.OPENSHIFT_TOOLS_DEPLOYER_SA_PASSWORD}}
openshift_server_url: ${{secrets.OPENSHIFT_SERVER_URL}}
namespace: ${{secrets.OPENSHIFT_LICENSE_PLATE}}-tools
- name: ENV Specific Image Tagging
run: |
oc tag -n ${{secrets.OPENSHIFT_LICENSE_PLATE}}-tools ${{secrets.OPENSHIFT_INTERNAL_REPOSITORY}}/${{secrets.OPENSHIFT_LICENSE_PLATE}}-tools/${{env.app}}-frontend:${{env.gittag}} "${{env.app}}-frontend:${{ env.env }}"
# Login to Openshift using OC SA and Token of respective env.
- name: Authenticate OC Env Specific SA
uses: redhat-actions/oc-login@v1
env:
#filling out all these values with github environment specific values if defined in the scope
# of environment
#If not defined then the values are being looked up in the repository context
OPENSHIFT_NAMESPACE: ${{secrets.OPENSHIFT_LICENSE_PLATE}}-${{ env.env }}
OPENSHIFT_USER: ${{secrets.OPENSHIFT_DEPLOYER_SA_USERNAME}}
#OPENSHIFT_USER: ${{secrets.OPENSHIFT_DEFAULT_SA_USERNAME}}
with:
openshift_server_url: ${{secrets.OPENSHIFT_SERVER_URL}}
openshift_token: ${{secrets.OPENSHIFT_DEPLOYER_SA_PASSWORD}}
#openshift_token: ${{secrets.OPENSHIFT_DEFAULT_SA_TOKEN}}
namespace: ${OPENSHIFT_NAMESPACE}
# This change will trigger a deployment
- name: Labelling DC to release version - this would trigger deployment
env:
appName: ${{ env.app }}
openshiftEnvNamespace: ${{secrets.OPENSHIFT_LICENSE_PLATE}}-${{ env.env }}
toolsSpace: ${{secrets.OPENSHIFT_LICENSE_PLATE}}-tools
run: |
oc patch dc "${appName}-frontend" -n "${openshiftEnvNamespace}" --patch '{"spec":{"template":{"metadata":{"labels":{"version":"${{ env.gittag }}"}}}}}'