EXPRESS API-TEST Deploy #20
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
# GitHub Actions workflow for deploying API image to TEST env | |
name: EXPRESS API-TEST Deploy | |
on: | |
workflow_dispatch: | |
inputs: | |
image_tag: | |
description: 'Image Tag to deploy' | |
required: true | |
env: | |
IMAGE_TAG: ${{ github.event.inputs.image_tag }} | |
ENVIRONMENT: 'test' | |
OPENSHIFT_TOKEN: ${{ secrets.OPENSHIFT_SA_TEST_TOKEN }} | |
jobs: | |
# Job to deploy API image to OpenShift | |
Deploy-To-OpenShift: | |
name: Deploy to OpenShift | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Login to OpenShift | |
uses: redhat-actions/oc-login@v1 | |
with: | |
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }} | |
openshift_token: ${{env.OPENSHIFT_TOKEN}} | |
namespace: ${{ format('{0}-{1}', secrets.LICENSE_PLATE, env.ENVIRONMENT) }} | |
# Process and Apply API DeploymentConfig | |
- name: Process and Apply API DeploymentConfig | |
env: | |
NAMESPACE: ${{ format('{0}-{1}', secrets.LICENSE_PLATE, env.ENVIRONMENT) }} | |
DC_TEMPLATE: 'api-v2-dc-template.yaml' | |
IMAGE_TAG: ${{ env.IMAGE_TAG }} | |
APPLICATION_NAME: 'pims-api-v2' | |
LICENSE_PLATE: '${{ secrets.LICENSE_PLATE }}' | |
run: | | |
./.github/helpers/deploy.sh | |
# Job to check the health of the deployed API | |
Health-Check: | |
name: Check Deployment Health | |
runs-on: ubuntu-latest | |
needs: [Deploy-To-OpenShift] | |
steps: | |
# Login to OpenShift | |
- name: Login to OpenShift | |
uses: redhat-actions/oc-login@v1 | |
env: | |
OPENSHIFT_USER: github-actions | |
OPENSHIFT_PROJECT: ${{ format('{0}-{1}', secrets.LICENSE_PLATE, env.ENVIRONMENT) }} | |
with: | |
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }} | |
openshift_token: ${{env.OPENSHIFT_TOKEN}} | |
namespace: ${{ format('{0}-{1}', secrets.LICENSE_PLATE, env.ENVIRONMENT) }} | |
# Check Deployment Status | |
- name: Check Deployment Status | |
run: | | |
oc rollout status -n ${{ format('{0}-{1}', secrets.LICENSE_PLATE, env.ENVIRONMENT) }} dc/pims-api-v2 --watch | |
# Job to clean up previous objects in OpenShift | |
Clean-Up: | |
name: Clean Up | |
runs-on: ubuntu-latest | |
needs: [Health-Check] | |
steps: | |
# Login to OpenShift | |
- name: Login to OpenShift | |
uses: redhat-actions/oc-login@v1 | |
env: | |
OPENSHIFT_USER: github-actions | |
OPENSHIFT_PROJECT: ${{ format('{0}-{1}', secrets.LICENSE_PLATE, env.ENVIRONMENT) }} | |
with: | |
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }} | |
openshift_token: ${{env.OPENSHIFT_TOKEN}} | |
namespace: ${{ format('{0}-{1}', secrets.LICENSE_PLATE, env.ENVIRONMENT) }} | |
# Remove previous objects | |
- name: Remove previous objects | |
run: | | |
oc delete pod -n ${{ format('{0}-{1}', secrets.LICENSE_PLATE, env.ENVIRONMENT) }} --field-selector status.phase=Succeeded | |
# Remove previous replication controllers | |
- name: Remove previous replication controllers | |
run: | | |
oc delete rc -n ${{ format('{0}-{1}', secrets.LICENSE_PLATE, env.ENVIRONMENT) }} --field-selector status.replicas=0 | |
# Job to update the wiki with deployed image tag information | |
Update_Wiki_Tags: | |
needs: [Health-Check, Deploy-To-OpenShift] | |
name: Update table in wiki | |
runs-on: ubuntu-latest | |
env: | |
GH_TOKEN: ${{ github.token }} | |
steps: | |
# Checkout the repository | |
- name: Checkout | |
uses: actions/checkout@v3 | |
# Clone wiki repository | |
- name: Clone wiki repository | |
run: | | |
echo "Cloning wiki repo https://github.com/$GITHUB_REPOSITORY.wiki.git" | |
git clone "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY.wiki.git" ./wiki | |
# Setup Python | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
# Run update wiki python script | |
- name: Run update wiki python script | |
run: python ./.github/helpers/update-wiki-table.py ./wiki/Image-tags.md "API V2" "Deployed Image Tag in TEST" "${{ env.IMAGE_TAG }}" | |
# Commit and push changes to wiki | |
- name: Commit and push changes to wiki | |
run: | | |
cd ./wiki | |
git config user.name "$GITHUB_ACTOR" | |
git config user.email "$GITHUB_ACTOR@users.noreply.github.com" | |
git add . | |
if git diff-index --quiet HEAD; then | |
echo "Nothing changed" | |
exit 0 | |
fi | |
echo "Pushing changes to wiki" | |
git commit -m "Value populated at Deploy API" && git push "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY.wiki.git" |