Skip to content

Promote the role sync image to test or prod on Gold and GoldDR cluster #29

Promote the role sync image to test or prod on Gold and GoldDR cluster

Promote the role sync image to test or prod on Gold and GoldDR cluster #29

#This workflow requires an input and based on that input pulls the appropriate image and tags it with the next environments name
name: Promote the role sync image to test or prod on Gold and GoldDR cluster
on:
workflow_dispatch:
inputs:
environment:
type: choice
description: Select the environment
required: true
options:
- test
- prod
jobs:
run-test:
runs-on: ubuntu-latest
environment:
name: Testing
if: ${{ github.event.inputs.environment == 'test' }}
steps:
- uses: actions/checkout@v2
- name: Cluster Login
uses: redhat-developer/openshift-actions@v1.1
with:
openshift_server_url: ${{ secrets.OPENSHIFT4_SERVER_URL }}
parameters: '{"apitoken": "${{ secrets.OPENSHIFT4_SA_PASSWORD }}"}'
cmd: |
'version'
- name: Login to Openshift Docker Registry
uses: docker/login-action@v1
with:
registry: ${{ secrets.OPENSHIFT4_REGISTRY }}
username: ${{ secrets.OPENSHIFT4_SA_USERNAME }}
password: ${{ secrets.OPENSHIFT4_SA_PASSWORD }}
- name: Login to Openshift Docker Registry GoldDR
uses: docker/login-action@v1
with:
registry: ${{ secrets.OPENSHIFT4_REGISTRY_GOLDDR }}
username: ${{ secrets.OPENSHIFT4_SA_USERNAME }}
password: ${{ secrets.OPENSHIFT4_SA_PASSWORD_GOLDDR }}
- name: Pull Dev Image
run: |
docker pull ${{ secrets.OPENSHIFT4_REGISTRY }}/${{ secrets.LICENSE_PLATE }}-tools/cccm-role-sync:dev
- name: Docker Tag Version Test
run: |
docker tag ${{ secrets.OPENSHIFT4_REGISTRY }}/${{ secrets.LICENSE_PLATE }}-tools/cccm-role-sync:dev ${{ secrets.OPENSHIFT4_REGISTRY }}/${{ secrets.LICENSE_PLATE }}-tools/cccm-role-sync:test
- name: Docker Push Version Test to Gold and GoldDR
run: |
docker push ${{ secrets.OPENSHIFT4_REGISTRY }}/${{ secrets.LICENSE_PLATE }}-tools/cccm-role-sync:test
docker tag ${{ secrets.OPENSHIFT4_REGISTRY }}/${{ secrets.LICENSE_PLATE }}-tools/cccm-role-sync:test ${{ secrets.OPENSHIFT4_REGISTRY_GOLDDR }}/${{ secrets.LICENSE_PLATE }}-tools/cccm-role-sync:test
docker push ${{ secrets.OPENSHIFT4_REGISTRY_GOLDDR }}/${{ secrets.LICENSE_PLATE }}-tools/cccm-role-sync:test
- name: Set GitOps SSH Key
uses: webfactory/ssh-agent@v0.5.4
with:
ssh-private-key: ${{ secrets.GIT_OPS_SSH_KEY }}
# Getting the SHA from the latest image in the image stream and setting it to a variable to use
# at a later step
- name: Get and Store Current Image SHA
run: |
IMAGE_SHA=$(oc describe istag/cccm-role-sync:test -n abb712-tools | grep 'Image Name' | awk '{ print $3 }')
echo "::set-output name=IMAGE_SHA::$IMAGE_SHA"
id: image_sha
# Cloning the GitOps repo so that the kutomization file that holds the image tag information can be
# synced with what is live in openshift
- name: Git Clone Repo
run: |
git config --global user.name "Github Action - CCCM Repo Frontend Promote Dev Image to Test"
git config --global user.email "cccm-frontend@githubaction.com"
git clone git@github.com:bcgov-c/tenant-gitops-abb712.git
cd tenant-gitops-abb712/cccm/overlays/gold/test
kustomize edit set image cccm-role-sync-image=image-registry.openshift-image-registry.svc:5000/abb712-tools/cccm-role-sync@${{ steps.image_sha.outputs.IMAGE_SHA }}
git add kustomization.yaml
cd ../../golddr/test
kustomize edit set image cccm-role-sync-image=image-registry.openshift-image-registry.svc:5000/abb712-tools/cccm-role-sync@${{ steps.image_sha.outputs.IMAGE_SHA }}
git add kustomization.yaml
git commit -m "Updated cccm-role-sync image sha in Kustomization file from CCCM Github Action"
git push
run-prod:
runs-on: ubuntu-latest
environment:
name: Production
if: ${{ github.event.inputs.environment == 'prod' }}
steps:
- uses: actions/checkout@v2
- name: Cluster Login
uses: redhat-developer/openshift-actions@v1.1
with:
openshift_server_url: ${{ secrets.OPENSHIFT4_SERVER_URL }}
parameters: '{"apitoken": "${{ secrets.OPENSHIFT4_SA_PASSWORD }}"}'
cmd: |
'version'
- name: Login to Openshift Docker Registry
uses: docker/login-action@v1
with:
registry: ${{ secrets.OPENSHIFT4_REGISTRY }}
username: ${{ secrets.OPENSHIFT4_SA_USERNAME }}
password: ${{ secrets.OPENSHIFT4_SA_PASSWORD }}
- name: Login to Openshift Docker Registry GoldDR
uses: docker/login-action@v1
with:
registry: ${{ secrets.OPENSHIFT4_REGISTRY_GOLDDR }}
username: ${{ secrets.OPENSHIFT4_SA_USERNAME }}
password: ${{ secrets.OPENSHIFT4_SA_PASSWORD_GOLDDR }}
- name: Pull Test Image
run: |
docker pull ${{ secrets.OPENSHIFT4_REGISTRY }}/${{ secrets.LICENSE_PLATE }}-tools/cccm-role-sync:test
- name: Docker Tag Version Prod
run: |
docker tag ${{ secrets.OPENSHIFT4_REGISTRY }}/${{ secrets.LICENSE_PLATE }}-tools/cccm-role-sync:test ${{ secrets.OPENSHIFT4_REGISTRY }}/${{ secrets.LICENSE_PLATE }}-tools/cccm-role-sync:prod
- name: Docker Push Version Prod to Gold and GoldDR
run: |
docker push ${{ secrets.OPENSHIFT4_REGISTRY }}/${{ secrets.LICENSE_PLATE }}-tools/cccm-role-sync:prod
docker tag ${{ secrets.OPENSHIFT4_REGISTRY }}/${{ secrets.LICENSE_PLATE }}-tools/cccm-role-sync:prod ${{ secrets.OPENSHIFT4_REGISTRY_GOLDDR }}/${{ secrets.LICENSE_PLATE }}-tools/cccm-role-sync:prod
docker push ${{ secrets.OPENSHIFT4_REGISTRY_GOLDDR }}/${{ secrets.LICENSE_PLATE }}-tools/cccm-role-sync:prod
- name: Set GitOps SSH Key
uses: webfactory/ssh-agent@v0.5.4
with:
ssh-private-key: ${{ secrets.GIT_OPS_SSH_KEY }}
# Getting the SHA from the latest image in the image stream and setting it to a variable to use
# at a later step
- name: Get and Store Current Image SHA
run: |
IMAGE_SHA=$(oc describe istag/cccm-role-sync:prod -n abb712-tools | grep 'Image Name' | awk '{ print $3 }')
echo "::set-output name=IMAGE_SHA::$IMAGE_SHA"
id: image_sha
# Cloning the GitOps repo so that the kutomization file that holds the image tag information can be
# synced with what is live in openshift
- name: Git Clone Repo
run: |
git config --global user.name "Github Action - CCCM Repo Frontend Promote Test Image to Prod"
git config --global user.email "cccm-frontend@githubaction.com"
git clone git@github.com:bcgov-c/tenant-gitops-abb712.git
cd tenant-gitops-abb712/cccm/overlays/gold/prod
kustomize edit set image cccm-role-sync-image=image-registry.openshift-image-registry.svc:5000/abb712-tools/cccm-role-sync@${{ steps.image_sha.outputs.IMAGE_SHA }}
git add kustomization.yaml
cd ../../golddr/prod
kustomize edit set image cccm-role-sync-image=image-registry.openshift-image-registry.svc:5000/abb712-tools/cccm-role-sync@${{ steps.image_sha.outputs.IMAGE_SHA }}
git add kustomization.yaml
git commit -m "Updated cccm-role-sync image sha in Kustomization file from CCCM Github Action"
git push