Update environment variable setup and add check for DB_IMAGE #7
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 and publish DB image to Artifactory | |
concurrency: | |
group: ${{ github.workflow }}-github.ref }} | |
cancel-in-progress: false | |
on: | |
push: | |
branches: | |
- dev | |
#- test | |
#- prod | |
paths: | |
- '**/config/mariadb/**' | |
- '**/workflows/**' | |
- '**/**.env' | |
pull_request: | |
branches: | |
- dev | |
#- test | |
#- prod | |
paths: | |
- '**/config/mariadb/**' | |
#- '**/workflows/build-push-db-image.yml' | |
- '**/workflows/**' | |
- '**/**.env' | |
jobs: | |
#Print variables for logging and debugging purposes | |
checkEnv: | |
name: 📋 Environment Check | |
runs-on: ubuntu-latest | |
steps: | |
- name: 📤 Checkout Target Branch | |
uses: actions/checkout@v4 | |
with: | |
sparse-checkout: | | |
config/mariadb | |
example.env | |
example.versions.env | |
# - name: Setup Env Vars | |
# id: dotenv | |
# uses: falti/dotenv-action@v1 | |
# with: | |
# path: example.env | |
# export-variables: true | |
# keys-case: upper | |
# - name: Setup Env Version Vars | |
# id: dotenv_versions | |
# uses: falti/dotenv-action@v1 | |
# with: | |
# path: example.versions.env | |
# export-variables: true | |
# keys-case: upper | |
- name: Setup All Env Vars | |
run: | | |
echo "Import .env files to $GITHUB_ENV (ignoring any commented [#] or empty lines)" | |
grep -v '^#' ./example.env | grep -v '^$' >> $GITHUB_ENV | |
grep -v '^#' ./example.versions.env | grep -v '^$' >> $GITHUB_ENV | |
cat /.env | |
- name: Check Env Vars | |
run: | | |
echo Building and pushing DB_IMAGE: ${{ env.DB_IMAGE }} | |
# Build DB Image | |
build-images: | |
name: '🔨 Build DB image' | |
needs: [checkEnv] | |
runs-on: ubuntu-latest | |
#env: | |
# Proxy settings for local development / testing | |
#https_proxy: http://198.161.14.25:8080 | |
# no_proxy: ${{ env.OPENSHIFT_SERVER }} | |
if: ${{ needs.checkEnv.SKIP_BUILDS != 'YES' }} && (github.ref_name == 'dev' || github.ref_name == 'test' || github.ref_name == 'prod') | |
steps: | |
# 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: 🛠️ Pull latest DB base image then push to Artifactory | |
run: | | |
docker pull ${{ env.DB_IMAGE }} | |
docker tag ${{ env.DB_IMAGE }} ${{ secrets.ARTIFACTORY_URL }}/${{ env.DB_IMAGE }} | |
docker push ${{ secrets.ARTIFACTORY_URL }}/${{ env.DB_IMAGE }} | |
- name: Install oc | |
uses: redhat-actions/openshift-tools-installer@v1 | |
with: | |
oc: 4.11.0 | |
# 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 }} ) | |
if: success() | |
uses: redhat-actions/oc-login@v1 | |
with: | |
insecure_skip_tls_verify: false | |
reveal_cluster_name: false | |
openshift_server_url: ${{ env.OPENSHIFT_SERVER }} | |
openshift_token: ${{ secrets.AUTH_TOKEN_DEV }} | |
namespace: ${{ env.OPENSHIFT_DEPLOY_PROJECT }} | |
# For a graceful termination, set the replica count of the Pods in the mariadb-galera StatefulSet to 0: | |
# oc scale sts ${{ env.DB_DEPLOYMENT_NAME }} --replicas=0 | |
# To uninstall/delete the my-release release: | |
# helm delete --purge ${{ env.DB_DEPLOYMENT_NAME }} | |
- name: 🚀 Deploy ${{ env.DB_DEPLOYMENT_NAME }} to ${{ env.OPENSHIFT_DEPLOY_PROJECT }} | |
if: success() | |
run: | | |
if [[ `oc describe sts ${{ env.DB_DEPLOYMENT_NAME }} 2>&1` =~ "NotFound" ]]; then | |
echo "${{ env.DB_DEPLOYMENT_NAME }} NOT FOUND: Beginning deployment..." | |
oc create -f ./config/mariadb/config.yaml -n ${{ env.OPENSHIFT_DEPLOY_PROJECT }} | |
else | |
echo "${{ env.DB_DEPLOYMENT_NAME }} Installation FOUND...UPDATING..." | |
oc annotate --overwrite sts/${{ env.DB_DEPLOYMENT_NAME }} kubectl.kubernetes.io/restartedAt=`date +%FT%T` -n ${{ env.OPENSHIFT_DEPLOY_PROJECT }} | |
oc rollout restart sts/${{ env.DB_DEPLOYMENT_NAME }} | |
fi |