Adjust SKIP_BUILDS #137
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: 🔨 Build on OpenShift | |
concurrency: | |
group: ${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
APP: moodle | |
USER: ${{ github.actor }} | |
# Skip builds for faster deployments / testing ("YES" or build) | |
SKIP_BUILDS: "YES" | |
PROJECT: ${{ vars.OPENSHIFT_DEPLOY_PROJECT }} | |
APP_HOST_URL: moodle-${{ vars.OPENSHIFT_DEPLOY_PROJECT }}-${{ github.ref_name }}.apps.silver.devops.gov.bc.ca | |
BASE_IMAGE_TAG: ${{ github.ref_name }} | |
BUILD_NAMESPACE: ${{ vars.OPENSHIFT_DEPLOY_PROJECT }}-tools | |
DEPLOY_NAMESPACE: ${{ vars.OPENSHIFT_DEPLOY_PROJECT }}-${{ github.ref_name }} | |
BUILD_ID: ${{ github.event.number }} | |
BRANCH: ${{ github.ref_name }} | |
SOURCE_REPOSITORY_URL: "https://github.com/${{ github.repository }}" | |
INSPECT_JOB_URL: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
BUILD_ICON_URL: https://cdn-icons-png.flaticon.com/128/5110/5110294.png | |
SUCCESS_ICON_URL: https://cdn-icons-png.flaticon.com/128/1356/1356479.png | |
FAIL_ICON_URL: https://www.flaticon.com/free-icon/rocket_6818114 | |
on: | |
push: | |
branches: | |
- dev | |
- test | |
- prod | |
paths: | |
- '**.Dockerfile' | |
- '**.conf' | |
- '**.ini' | |
- '**.php' | |
- '**.yml' | |
- '**.json' | |
- 'php-fpm-healthcheck.sh' | |
pull_request: | |
branches: | |
- dev | |
- test | |
- prod | |
paths: | |
- '**.Dockerfile' | |
- '**.conf' | |
- '**.ini' | |
- '**.php' | |
- '**.yml' | |
- 'php-fpm-healthcheck.sh' | |
jobs: | |
#Print variables for logging and debugging purposes | |
checkEnv: | |
name: 📋 Environment Check | |
runs-on: ubuntu-latest | |
steps: | |
- name: Print Env Vars | |
run: | | |
echo Deploying ${{ env.APP }} on ${{ env.PROJECT }} | |
echo "-----------------------" | |
echo Deploy to Namespace: ${{ env.DEPLOY_NAMESPACE }} | |
echo URL: https://${{ env.APP_HOST_URL }} | |
echo "CLEAN_BUILDS: ${{ env.CLEAN_BUILDS }}" | |
if [[ "${{ env.CLEAN_BUILDS }}" != "false" ]]; then | |
echo "CLEAN_BUILDS is not false, setting CLEAN_BUILDS_TEXT to TRUE" | |
echo CLEAN_BUILDS_TEXT="TRUE" >> $GITHUB_OUTPUT | |
else | |
echo "CLEAN_BUILDS is false, setting CLEAN_BUILDS_TEXT to FALSE" | |
echo CLEAN_BUILDS_TEXT="FALSE" >> $GITHUB_OUTPUT | |
fi | |
echo "SKIP_BUILDS: $SKIP_BUILDS" | |
if [[ $SKIP_BUILDS == "YES" ]]; then | |
echo "SKIP_BUILDS is YES, setting SKIP_BUILDS to YES" | |
echo SKIP_BUILDS="YES" >> $GITHUB_OUTPUT | |
else | |
echo "SKIP_BUILDS is NOT YES, setting SKIP_BUILDS to NO" | |
echo SKIP_BUILDS="NO" >> $GITHUB_OUTPUT | |
fi | |
# Build PHP Image | |
build-images: | |
name: 🔨 Build Application Images (${{ github.ref_name }}) | |
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 | |
# 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 | |
run: | | |
oc login --token=${{ secrets.SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443 | |
# Get Environment Variables from file | |
- name: 📋 Setup Environment from File | |
id: dotenv | |
uses: falti/dotenv-action@v1 | |
with: | |
path: example.env | |
export-variables: true | |
log-variables: true | |
keys-case: upper | |
# Build the PHP image | |
- name: 🚧 Build PHP (SKIP? ${{ env.SKIP_BUILDS }}) | |
id: build-php | |
if: success() && ${{ env.SKIP_BUILDS != 'YES' }} | |
working-directory: "./" | |
run: | | |
echo "Building ${{ steps.dotenv.outputs.PHP_DEPLOYMENT_NAME }}:${{ env.BRANCH }}" | |
echo "Using ${{ steps.dotenv.outputs.PHP_IMAGE }}" | |
if [ ${{ env.SKIP_BUILDS == false }} == true ]; then | |
echo "STARTING BUILD..." | |
else | |
echo "SKIPPING BUILD (Environment variable SKIP_BUILDS=true)" | |
fi | |
sh ./openshift/scripts/build-docker-image.sh | |
env: | |
DOCKER_FROM_IMAGE: ${{ steps.dotenv.outputs.PHP_IMAGE }} | |
DOCKER_FILE_PATH: ${{ env.PHP_DOCKER_FILE_PATH }} | |
DEPLOYMENT_NAME: ${{ steps.dotenv.outputs.PHP_DEPLOYMENT_NAME }} | |
SOURCE_CONTEXT_DIR: ${{ env.PHP_SOURCE_CONTEXT_DIR }} | |
BRANCH: ${{ env.BRANCH }} | |
BUILD_NAMESPACE: ${{ env.BUILD_NAMESPACE }} | |
IMAGE_REPO: ${{ steps.dotenv.outputs.IMAGE_REPO }} | |
IMAGE_TAG: ${{ env.BASE_IMAGE_TAG }} | |
SOURCE_REPOSITORY_URL: ${{ env.SOURCE_REPOSITORY_URL }} | |
CLEAN_BUILDS_TEXT: ${{ needs.checkEnv.outputs.CLEAN_BUILDS_TEXT }} | |
# Build the Cron image | |
- name: 🚧 Build Cron (SKIP? ${{ env.SKIP_BUILDS }}) | |
id: build-cron | |
if: success() && ${{ env.SKIP_BUILDS != 'YES' }} | |
working-directory: "./" | |
run: | | |
echo "Building ${{ steps.dotenv.outputs.CRON_DEPLOYMENT_NAME }}:${{ env.BRANCH }}" | |
echo "Using ${{ steps.dotenv.outputs.CRON_IMAGE }}" | |
if [ ${{ env.SKIP_BUILDS == false }} == true ]; then | |
echo "STARTING BUILD..." | |
else | |
echo "SKIPPING BUILD (Environment variable SKIP_BUILDS=true)" | |
fi | |
sh ./openshift/scripts/build-docker-image.sh | |
env: | |
DOCKER_FROM_IMAGE: ${{ steps.dotenv.outputs.CRON_IMAGE }} | |
DOCKER_FILE_PATH: ${{ env.CRON_DOCKER_FILE_PATH }} | |
DEPLOYMENT_NAME: ${{ steps.dotenv.outputs.CRON_DEPLOYMENT_NAME }} | |
SOURCE_CONTEXT_DIR: ${{ env.CRON_SOURCE_CONTEXT_DIR }} | |
BRANCH: ${{ env.BRANCH }} | |
BUILD_NAMESPACE: ${{ env.BUILD_NAMESPACE }} | |
IMAGE_REPO: ${{ steps.dotenv.outputs.IMAGE_REPO }} | |
IMAGE_TAG: ${{ env.BASE_IMAGE_TAG }} | |
SOURCE_REPOSITORY_URL: ${{ env.SOURCE_REPOSITORY_URL }} | |
outputs: | |
APP: ${{ steps.dotenv.outputs.APP }} | |
DB_NAME: ${{ steps.dotenv.outputs.DB_NAME }} | |
DB_USER: ${{ steps.dotenv.outputs.DB_USER }} | |
DB_PASSWORD: ${{ steps.dotenv.outputs.DB_PASSWORD }} | |
IMAGE_REPO: ${{ steps.dotenv.outputs.IMAGE_REPO }} | |
WEB_DEPLOYMENT_NAME: ${{ steps.dotenv.outputs.WEB_DEPLOYMENT_NAME }} | |
DB_DEPLOYMENT_NAME: ${{ steps.dotenv.outputs.DB_DEPLOYMENT_NAME }} | |
PHP_IMAGE: ${{ steps.dotenv.outputs.PHP_IMAGE }} | |
PHP_DEPLOYMENT_NAME: ${{ steps.dotenv.outputs.PHP_DEPLOYMENT_NAME }} | |
CRON_IMAGE: ${{ steps.dotenv.outputs.CRON_IMAGE }} | |
CRON_DEPLOYMENT_NAME: ${{ steps.dotenv.outputs.CRON_DEPLOYMENT_NAME }} | |
REDIS_REPO: ${{ steps.dotenv.outputs.REDIS_REPO }} | |
REDIS_DEPLOYMENT_NAME: ${{ steps.dotenv.outputs.REDIS_DEPLOYMENT_NAME }} | |
REDIS_IMAGE: ${{ steps.dotenv.outputs.REDIS_IMAGE }} | |
WEB_IMAGE: ${{ steps.dotenv.outputs.WEB_IMAGE }} | |
DB_IMAGE: ${{ steps.dotenv.outputs.DB_IMAGE }} | |
APP_HOST_URL: ${{ env.APP_HOST_URL }} | |
BUILD_NAMESPACE: ${{ env.BUILD_NAMESPACE }} | |
DEPLOY_NAMESPACE: ${{ env.DEPLOY_NAMESPACE }} | |
BRANCH: ${{ env.BRANCH }} | |
call-cleanup-workflow: | |
name: 🧹️ Clean Build ( ${{ needs.checkEnv.CLEAN_BUILDS_TEXT }} ) | |
uses: ./.github/workflows/cleanup.yml | |
needs: [checkEnv, build-images] | |
if: success() && ${{ needs.checkEnv.CLEAN_BUILDS_TEXT != 'FALSE' }} | |
secrets: inherit | |
with: | |
APP: ${{ needs.build-images.outputs.APP }} | |
APP_HOST_URL: ${{ needs.build-images.outputs.APP_HOST_URL }} | |
BRANCH: ${{ needs.build-images.outputs.BRANCH }} | |
BUILD_NAMESPACE: ${{ needs.build-images.outputs.BUILD_NAMESPACE }} | |
DEPLOY_NAMESPACE: ${{ needs.build-images.outputs.DEPLOY_NAMESPACE }} | |
DB_DEPLOYMENT_NAME: ${{ needs.build-images.outputs.DB_DEPLOYMENT_NAME }} | |
WEB_DEPLOYMENT_NAME: ${{ needs.build-images.outputs.WEB_DEPLOYMENT_NAME }} | |
PHP_DEPLOYMENT_NAME: ${{ needs.build-images.outputs.PHP_DEPLOYMENT_NAME }} | |
CRON_DEPLOYMENT_NAME: ${{ needs.build-images.outputs.CRON_DEPLOYMENT_NAME }} | |
REDIS_DEPLOYMENT_NAME: ${{ needs.build-images.outputs.REDIS_DEPLOYMENT_NAME }} | |
call-deploy-workflow: | |
name: 🚀 Deploy to OpenShift | |
uses: ./.github/workflows/deploy.yml | |
needs: [checkEnv, build-images, call-cleanup-workflow] | |
if: needs.build-images.outcome == 'success' || needs.build-images.outcome == 'skipped' || ${{ needs.checckEnv.SKIP_BUILDS == 'FALSE' }} | |
secrets: inherit | |
with: | |
BASE_IMAGE_TAG: ${{ github.ref_name }} | |
APP: ${{ needs.build-images.outputs.APP }} | |
DB_NAME: ${{ needs.build-images.outputs.DB_NAME }} | |
DB_USER: ${{ needs.build-images.outputs.DB_USER }} | |
DB_PASSWORD: ${{ needs.build-images.outputs.DB_PASSWORD }} | |
WEB_DEPLOYMENT_NAME: ${{ needs.build-images.outputs.WEB_DEPLOYMENT_NAME }} | |
WEB_IMAGE: ${{ needs.build-images.outputs.WEB_IMAGE }} | |
PHP_DEPLOYMENT_NAME: ${{ needs.build-images.outputs.PHP_DEPLOYMENT_NAME }} | |
PHP_IMAGE: ${{ needs.build-images.outputs.PHP_IMAGE }} | |
DB_DEPLOYMENT_NAME: ${{ needs.build-images.outputs.DB_DEPLOYMENT_NAME }} | |
DB_IMAGE: ${{ needs.build-images.outputs.DB_IMAGE }} | |
CRON_IMAGE: ${{ needs.build-images.outputs.CRON_IMAGE }} | |
CRON_DEPLOYMENT_NAME: ${{ needs.build-images.outputs.CRON_DEPLOYMENT_NAME }} | |
REDIS_REPO: ${{ needs.build-images.outputs.REDIS_REPO }} | |
REDIS_DEPLOYMENT_NAME: ${{ needs.build-images.outputs.REDIS_DEPLOYMENT_NAME }} | |
REDIS_IMAGE: ${{ needs.build-images.outputs.REDIS_IMAGE }} | |
APP_HOST_URL: ${{ needs.build-images.outputs.APP_HOST_URL }} | |
BUILD_NAMESPACE: ${{ needs.build-images.outputs.BUILD_NAMESPACE }} | |
DEPLOY_NAMESPACE: ${{ needs.build-images.outputs.DEPLOY_NAMESPACE }} | |
IMAGE_REPO: ${{ needs.build-images.outputs.IMAGE_REPO }} | |
BRANCH: ${{ needs.build-images.outputs.BRANCH }} | |
notify: | |
name: 📫 Send Notifications (via Rocket.Chat) | |
needs: [build-images, call-deploy-workflow] | |
if: success() || failure() | |
runs-on: ubuntu-latest | |
steps: | |
- name: ⚠️ Failure | |
if: failure() | |
uses: muinmomin/[email protected] | |
with: | |
url: ${{ secrets.ROCKETCHAT_WEBHOOK_URL }} | |
data: '{ | |
"alias":"FAILED GitHub Action by ${{ env.USER }}", | |
"text":"Job: ${{ github.job }} in | |
${{ github.workflow }} of | |
${{ github.repository }}:${{ github.ref_name }} >> | |
Deploy1: ${{ needs.call-deploy-workflow.outputs.deploy1 }} | |
Deploy2: ${{ needs.call-deploy-workflow.outputs.deploy2 }}", | |
"attachments":[{ | |
"title":"${{ github.job }} ${{ job.status }} to ${{ github.ref_name }}", | |
"title_link": "${{ env.INSPECT_JOB_URL }}", | |
"text":"Failure detected in ${{ github.repository }}:${{ github.ref_name }}", | |
"image_url": "${{ env.FAIL_ICON_URL }}", | |
"color":"#e7e076" | |
}]}' | |
- name: ✅ Success | |
uses: muinmomin/[email protected] | |
with: | |
url: ${{ secrets.ROCKETCHAT_WEBHOOK_URL }} | |
data: '{ | |
"alias":"Successful ${{ github.job }} by ${{ env.USER }}", | |
"text":"${{ github.job }} in ${{ github.workflow }} | |
of ${{ github.repository }}:${{ github.ref_name }}", | |
"attachments":[{ | |
"title":"${{ github.job }} ${{ job.status }} to ${{ github.ref_name }}", | |
"title_link": "${{ env.INSPECT_JOB_URL }}", | |
"text":"Successful deployment of: ${{ github.repository }}:${{ github.ref_name }}", | |
"image_url": "${{ env.SUCCESS_ICON_URL }}", | |
"color":"#05a227" | |
}]}' |