Merge pull request #502 from JustinMacaulay/feature/adding-postal-str… #445
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
# This is the workflow that creates a new image for CSRS front end | |
# Credit goes to Suganth /his CDDS and SCSS templates | |
name: Frontend - Build Frontend Image and Push to Openshift Registry for Dev Deployment | |
# Controls when the workflow will run | |
on: | |
# Trigger the this workflow on push/merge on main | |
push: | |
branches: | |
- 'main' | |
paths: | |
- 'src/frontend/**' | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
inputs: | |
app: | |
description: 'App Name (jag-csrs-frontend)' | |
required: true | |
default: jag-csrs-frontend | |
env: | |
description: 'Image Target Env' | |
required: true | |
default: 'dev' | |
# 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 | |
environment: ${{ github.event.inputs.env }} | |
env: | |
app: ${{github.event.inputs.app}} | |
env: ${{github.event.inputs.env}} | |
app_from_gh_secret: ${{ secrets.APP_NAME }} | |
env_from_gh_secret: ${{secrets.OPENSHIFT_ENV_TAG}} | |
# 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 commit short sha | |
id: sha | |
run: | | |
shortSha=$(echo $(git rev-parse --short HEAD) | cut -c1-7) | |
echo "gitsha=$shortSha" >> $GITHUB_ENV | |
- name: env variables | |
run: | | |
if [[ -z "$app" ]]; then | |
echo "app=$app_from_gh_secret" >> $GITHUB_ENV | |
fi | |
if [[ -z "$env" ]]; then | |
echo "env=$env_from_gh_secret" >> $GITHUB_ENV | |
fi | |
- name: print env variables | |
run: | | |
echo "Release Application: ${{ env.app }}" | |
echo "Release Environment: ${{ env.env }}" | |
echo "Release Git Sha: ${{env.gitsha}}" | |
#Login to OpenShift Container Repository | |
- name: Login to OpenShift Container Repository | |
uses: docker/login-action@v1 | |
with: | |
registry: ${{secrets.OPENSHIFT_EXTERNAL_REPOSITORY}} | |
username: ${{secrets.OPENSHIFT_BUILDER_SA_USERNAME}} | |
password: ${{secrets.OPENSHIFT_BUILDER_SA_PASSWORD}} | |
#Build and push image to OpenShift Image stream | |
- name: Build & Push Image to Openshift Image Stream | |
env: | |
COMPOSE_DOCKER_CLI_BUILD: 1 | |
DOCKER_BUILDKIT: 1 | |
CONTEXT: ./src/frontend/csrs-portal | |
#Right now do not have enough permission to manipulate RBAC, creating imagestream under tools and then using that from dev, test, prod | |
IMAGE: ${{secrets.OPENSHIFT_EXTERNAL_REPOSITORY}}/${{secrets.OPENSHIFT_LICENSE_PLATE}}-${{env.env}}/${{env.app}}:${{env.env}} | |
run: | | |
docker build \ | |
--tag ${IMAGE} \ | |
${CONTEXT} | |
docker push ${IMAGE} | |
# Would uncomment when we are able to execute patch on dc | |
# Login to Openshift using OC SA and Token of respective env. | |
#- name: Authenticate OC Env Specific SA | |
# uses: redhat-actions/oc-login@v1 | |
# env: | |
# 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} | |
# The steps below would not work until some additional role binding work is done | |
# On corresponding namesapce. However at present none of us has that privilege. | |
# Versions the deployment config of the application with release version number - | |
# This change will trigger a deployment | |
#- name: Labelling DC to release version | |
# env: | |
# appName: ${{ env.app }} | |
# openshiftEnvNamespace: ${{secrets.OPENSHIFT_LICENSE_PLATE}}-${{ env.env }} | |
# run: | | |
# oc patch dc ${appName} -n ${openshiftEnvNamespace} --patch '{"spec":{"template":{"metadata":{"labels":{"version":"${{ env.gitsha }}"}}}}}' |