Skip to content

Add env/secret and update image repository URL #1

Add env/secret and update image repository URL

Add env/secret and update image repository URL #1

Workflow file for this run

name: 🔨 Build and publish DB image to Artifactory
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
on:
push:
branches:
- dev
#- test
#- prod
paths:
- '**/config/mariadb/**'
- '**/workflows/build-push-db-image.yml'
pull_request:
branches:
- dev
#- test
#- prod
paths:
- '**/config/mariadb/**'
- '**/workflows/build-push-db-image.yml'
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: Set Env Vars
run: |
echo "Import .env 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
# Build DB Image
build-images:
name: '🔨 Build DB image'
needs: [checkEnv]
runs-on: ubuntu-latest
env:
OPENSHIFT_NAMESPACE: e66ac2-dev
https_proxy: http://198.161.14.25:8080
# no_proxy: ${{ secrets.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: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.AUTH_TOKEN_DEV }}
namespace: ${{ env.OPENSHIFT_NAMESPACE }}
# 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_NAMESPACE }}
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_NAMESPACE }}
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_NAMESPACE }}
oc rollout restart sts/${{ env.DB_DEPLOYMENT_NAME }}
fi