Skip to content

development

development #317

name: On Promotion to Test or Production for Searchgate
on:
deployment
env:
PULL_NUMBER: ${{ fromJSON(github.event.deployment.payload).pr }}
MICRO_SERVICE: ${{ fromJSON(github.event.deployment.payload).microservice }}
DEPLOY_REF: ${{ github.event.deployment.ref }}
DEPLOYMENT_ID: ${{ github.event.deployment.id }}
ENVIRONMENT: ${{ github.event.deployment.environment }}
INFRA_NAME: searchgate
jobs:
promote-environment:
name: Promote Web to Environment
if: fromJSON(github.event.deployment.payload).microservice == 'searchgate' &&
(
github.event.deployment.environment == 'staging' ||
github.event.deployment.environment == 'qa' ||
github.event.deployment.environment == 'production'
)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: Change Deploy Status to In Progress
uses: unacast/actions-github-deployment-status@0.4.0
with:
github_token: ${{ github.token }}
status: in_progress
- name: Map the deployments environment to a valid Openshift Namespace
env:
TEST_NAMESPACE: ${{ secrets.TEST_NAMESPACE }}
PROD_NAMESPACE: ${{ secrets.PROD_NAMESPACE }}
DEV_NAMESPACE: ${{ secrets.DEV_NAMESPACE }}
SSO_TEST_URL: https://test.oidc.gov.bc.ca
SSO_PROD_URL: https://oidc.gov.bc.ca
run: |
_NAMESPACE=$(.github/helpers/github_env_to_namespace.sh ${{ github.event.deployment.environment }})
_IMAGE_TAG=$(.github/helpers/github_env_to_image_tag.sh ${{ github.event.deployment.environment }})
_SSO_BASE_URL=''
if [ "$_NAMESPACE" == "$TEST_NAMESPACE" ]; then
_SSO_BASE_URL=$SSO_TEST_URL
else
_SSO_BASE_URL=$SSO_PROD_URL
fi
echo "DEPLOY_NAMESPACE=$_NAMESPACE" >> $GITHUB_ENV
echo "IMAGE_TAG=$_IMAGE_TAG" >> $GITHUB_ENV
echo "SUFFIX=-$_IMAGE_TAG" >> $GITHUB_ENV
echo "SSO_BASE_URL=$_SSO_BASE_URL" >> $GITHUB_ENV
echo "Deploying to $_NAMESPACE"
- name: Cluster Login
uses: redhat-developer/openshift-actions@v1.1
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
parameters: '{"apitoken": "${{ secrets.OPENSHIFT_SA_PASSWORD }}"}'
cmd: |
'version'
- name: Import PR based Image to Environment
run: |
oc tag ${{ secrets.TOOLS_NAMESPACE }}/${{ env.INFRA_NAME }}:${{ env.PULL_NUMBER }} \
${{ env.DEPLOY_NAMESPACE }}/${{ env.INFRA_NAME }}:${{ env.IMAGE_TAG }}
- name: Run Deployment
env:
IMAGE_NAMESPACE: ${{ env.DEPLOY_NAMESPACE }}
IMAGE_TAG: ${{ env.IMAGE_TAG }}
DEPLOY_NAMESPACE: ${{ env.DEPLOY_NAMESPACE }}
SSO_BASE_URL: ${{ env.SSO_BASE_URL }}
SSO_CLIENT_ID: ${{ secrets.SSO_CLIENT }}
SSO_REALM_NAME: ${{ secrets.SSO_REALM }}
run: |
oc process -f openshift/templates/searchgate/dc.yaml -n $DEPLOY_NAMESPACE -p NAME=$INFRA_NAME -p SUFFIX=-$IMAGE_TAG -p IMAGE_TAG=$IMAGE_TAG -p ROCKETGATE_BASE_URL='' -p DOCUGATE_BASE_URL='' -p IMAGE_NAMESPACE=$IMAGE_NAMESPACE | oc apply -f - -n $DEPLOY_NAMESPACE
- name: Wait for Deployment and Update Status
env:
NAMESPACE: ${{ env.DEPLOY_NAMESPACE }}
run: |
DEPLOY_STATUS=$(.github/helpers/wait_for_deployment.sh dc/$INFRA_NAME$SUFFIX)
echo "DEPLOY_STATUS=$DEPLOY_STATUS" >> $GITHUB_ENV
- name: Change Deploy Status to Success or Failure
uses: unacast/actions-github-deployment-status@0.4.0
with:
github_token: ${{ github.token }}
status: ${{ env.DEPLOY_STATUS }}
- name: 'Comment PR'
uses: actions/github-script@0.3.0
if: env.DEPLOY_STATUS == 'success'
with:
github-token: ${{ github.token }}
script: |
const { repo: { owner, repo } } = context;
github.issues.createComment({ issue_number: ${{ env.PULL_NUMBER }}, owner, repo, body: 'Deployment to ${{ github.event.deployment.environment }} succeeded!' });
- name: Clean up artifacts
if: env.DEPLOY_STATUS == 'success' && github.event.deployment.environment == 'production'
env:
TOOLS_NAMESPACE: ${{ secrets.TOOLS_NAMESPACE }}
DEV_NAMESPACE: ${{ secrets.DEV_NAMESPACE }}
PULL_NUMBER: ${{ env.PULL_NUMBER }}
run: |
echo "deleting build artifacts"
oc -n $TOOLS_NAMESPACE delete bc -l build=$INFRA_NAME-$PULL_NUMBER
echo "deleting imagestream tag"
oc -n $TOOLS_NAMESPACE delete imagestreamtag/$INFRA_NAME:$PULL_NUMBER
echo "deleting dev artifacts"
oc -n $DEV_NAMESPACE delete dc,configmap -l app=$INFRA_NAME-$PULL_NUMBER
- name: 'Clean up PR comment'
uses: actions/github-script@0.3.0
if: env.DEPLOY_STATUS == 'success' && github.event.deployment.environment == 'production'
with:
github-token: ${{ github.token }}
script: |
const { repo: { owner, repo } } = context;
github.issues.createComment({ issue_number: ${{ env.PULL_NUMBER }}, owner, repo, body: 'Cleaning up dev artifacts and build artifacts' });