Update deployment restart command in web.yml #2
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
name: 🔨 Push Web Image to Artifactory and Deploy to OpenShift | |
concurrency: | |
group: ${{ github.workflow }}-github.ref }} | |
cancel-in-progress: false | |
env: | |
APP: web | |
USER: ${{ github.actor }} | |
on: | |
workflow_call: | |
push: | |
branches: | |
- dev | |
#- test | |
#- prod | |
paths: | |
- 'PHP.Dockerfile' | |
- '**/config/nginx/**' | |
- '**/workflows/web.yml' | |
- '**/**.env' | |
pull_request: | |
branches: | |
- dev | |
#- test | |
#- prod | |
paths: | |
- 'PHP.Dockerfile' | |
- '**/config/nginx/**' | |
- '**/workflows/web.yml' | |
- '**/**.env' | |
jobs: | |
#Print variables for logging and debugging purposes | |
checkEnv: | |
name: 📋 Environment Check | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check Env Vars | |
run: | | |
echo Building ${{ env.WEB_DEPLOYMENT_NAME }}:${{ env.OPENSHIFT_DEPLOY_PROJECT }}-${{ github.ref_name }} | |
# Build Images | |
build-images: | |
name: '🔨 Build Moodle and PHP images' | |
needs: [checkEnv] | |
runs-on: ubuntu-latest | |
if: ${{ needs.checkEnv.SKIP_BUILDS != 'YES' }} && (github.ref_name == 'dev' || github.ref_name == 'test' || github.ref_name == 'prod') | |
steps: | |
# Checkout the PR branch | |
- name: 📤 Checkout Target Branch | |
uses: actions/checkout@v2 | |
# Login to Artifactory | |
- name: 🔑 Login to Artifactory | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ secrets.ARTIFACTORY_URL }} | |
username: ${{ secrets.ARTIFACTORY_USER }} | |
password: ${{ secrets.ARTIFACTORY_PASSWORD }} | |
- name: Setup Env Vars | |
id: dotenv | |
uses: falti/dotenv-action@v1 | |
with: | |
path: example.env | |
export-variables: true | |
keys-case: upper | |
- name: Setup Versions Env Vars | |
id: dotenv_versions | |
uses: falti/dotenv-action@v1 | |
with: | |
path: example.versions.env | |
export-variables: true | |
keys-case: upper | |
# Pull latest WEB image and push to Artifactory | |
- name: 🛠️ Pull WEB base image and push to Artifactory | |
run: | | |
docker pull ${{ env.WEB_IMAGE }} | |
docker tag ${{ env.WEB_IMAGE }} ${{ secrets.ARTIFACTORY_URL }}/${{ env.WEB_IMAGE }} | |
docker push ${{ secrets.ARTIFACTORY_URL }}/${{ env.WEB_IMAGE }} | |
# Log in to OpenShift. | |
# Note: The secrets needed to log in are NOT available if the PR comes from a FORK. | |
# PR's must originate from a branch off the original repo or else all openshift `oc` commands will fail. | |
- name: 🔑 Log in to OpenShift ( ${{ github.ref_name }} ) | |
run: | | |
server=https://api.silver.devops.gov.bc.ca:6443 | |
if [[ ${{ github.ref_name == 'test' }} ]]; then | |
oc login --token=${{ secrets.AUTH_TOKEN_DEV }} --server=$server | |
elif [[ ${{ github.ref_name == 'test' }} ]]; then | |
oc login --token=${{ secrets.AUTH_TOKEN_TEST }} --server=$server | |
elif [[ ${{ github.ref_name == 'prod' }} ]]; then | |
oc login --token=${{ secrets.AUTH_TOKEN_PROD }} --server=$server | |
else | |
echo "No AUTH_TOKEN found for ${{ github.ref_name }} branch" | |
fi | |
# For a graceful termination, set the replica count of the Pods in the mariadb-galera StatefulSet to 0: | |
# oc scale dc ${{ env.WEB_DEPLOYMENT_NAME }} --replicas=0 | |
# To uninstall/delete the my-release release: | |
# helm delete --purge ${{ env.WEB_DEPLOYMENT_NAME }} | |
- name: 🚀 Deploy ${{ env.WEB_DEPLOYMENT_NAME }} to ${{ env.OPENSHIFT_DEPLOY_PROJECT }}-${{ github.ref_name }} | |
if: success() | |
run: | | |
if [[ `oc describe dc ${{ env.WEB_DEPLOYMENT_NAME }} 2>&1` =~ "NotFound" ]]; then | |
echo "${{ env.WEB_DEPLOYMENT_NAME }} NOT FOUND: Beginning deployment..." | |
oc create configmap ${{ env.WEB_DEPLOYMENT_NAME }}-config --from-file=./config/nginx/default.conf -n ${{ env.OPENSHIFT_DEPLOY_PROJECT }}-${{ github.ref_name }} | |
else | |
echo "${{ env.WEB_DEPLOYMENT_NAME }} Installation FOUND...UPDATING..." | |
oc annotate --overwrite dc/${{ env.WEB_DEPLOYMENT_NAME }} kubectl.kubernetes.io/restartedAt=`date +%FT%T` -n ${{ env.OPENSHIFT_DEPLOY_PROJECT }}-${{ github.ref_name }} | |
oc rollout latest dc/${{ env.WEB_DEPLOYMENT_NAME }} | |
fi |