.github/workflows/app-build-deploy.yaml
name: Build and Deploy APP
on:
push:
branches: [ main ]
paths:
- "app/**"
workflow_dispatch:
jobs:
build-tag-push:
name: Build, Tag, Push to Artifactory
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Log In to Docker
run: |
docker login ${{ secrets.ARTIFACTORY_URL }} -u ${{ secrets.ARTIFACTORY_USERNAME }} -p ${{ secrets.ARTIFACTORY_PASSWORD }}
- name: Build APP Image
run: |
docker-compose build spr-app
- name: List Docker Images
run: |
docker images
- name: Tag Image
run: |
docker tag citz-imb-staff-purchasing-reimbursement_spr-app ${{ secrets.ARTIFACTORY_URL }}/${{ secrets.IMAGE_REPOSITORY }}/spr-app:latest
- name: Push Image
run: |
docker push ${{ secrets.ARTIFACTORY_URL }}/${{ secrets.IMAGE_REPOSITORY }}/spr-app:latest
deploy:
name: Deploy to OpenShift
runs-on: ubuntu-latest
needs: [ build-tag-push ]
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Login to Openshift
uses: redhat-actions/oc-login@v1
env:
OPENSHIFT_USER: github-actions
OPENSHIFT_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE }}
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
namespace: ${{ secrets.OPENSHIFT_NAMESPACE }}
- name: Apply DeploymentConfig
env:
OPENSHIFT_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE }}
APPLICATION_NAME: staff-purchase-reimbursement
CONTAINER_NAME: spr-app
DEPLOYMENT_CONFIG: app-dc-template.yaml
IMAGE_REPOSITORY: ${{ secrets.IMAGE_REPOSITORY }}
ARTIFACTORY_URL: ${{ secrets.ARTIFACTORY_URL }}
run: |
./.github/helpers/deploy.sh
- name: Rollout Pod
continue-on-error: true
run: |
oc rollout latest dc/spr-app
healthcheck:
name: Determine Rollout Success
runs-on: ubuntu-latest
needs: [ deploy ]
steps:
- name: Login to Openshift
uses: redhat-actions/oc-login@v1
env:
OPENSHIFT_USER: github-actions
OPENSHIFT_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE }}
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
namespace: ${{ secrets.OPENSHIFT_NAMESPACE }}
- name: Check Status of Rollout
run: |
oc rollout status -n ${{ secrets.OPENSHIFT_NAMESPACE }} dc/spr-app --watch
cleanup:
name: Clean Up Old Objects
runs-on: ubuntu-latest
needs: [ healthcheck ]
steps:
- name: Login to Openshift
uses: redhat-actions/oc-login@v1
env:
OPENSHIFT_USER: github-actions
OPENSHIFT_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE }}
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
namespace: ${{ secrets.OPENSHIFT_NAMESPACE }}
- name: Remove old pod objects
run: |
oc delete pod --namespace=${{ secrets.OPENSHIFT_NAMESPACE }} --field-selector status.phase=Succeeded
- name: Remove old replication controllers
run: |
oc delete rc --namespace=${{ secrets.OPENSHIFT_NAMESPACE }} --field-selector status.replicas=0