SMK Update #48
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
# This action should: | |
# - trigger on merge of pr | |
# - tag the master with the image tag | |
# - deploy to prod | |
# | |
# https://github.community/t/run-action-only-when-a-pr-is-merged/18268 | |
name: "PROD deploy" | |
on: | |
pull_request: | |
branches: | |
- master | |
types: | |
- closed | |
# debugging | |
# on: | |
# push: | |
# branches: ['dev'] | |
jobs: | |
deployprod: | |
# Commented out for testing | |
if: github.event.pull_request.merged == true | |
defaults: | |
run: | |
shell: bash | |
runs-on: ubuntu-latest | |
outputs: | |
dockerversiontag: ${{ steps.retrieveimagetag.outputs.DOCKER_VERSION_TAG }} | |
steps: | |
# CHECKOUT THE CODE | |
- uses: actions/checkout@v4 | |
id: checkout | |
with: | |
fetch-depth: 0 | |
# GETTING THE IMAGE TAG FROM THE ARTIFACTS | |
- name: Retrieve tag from the artifacts | |
id: retrieveimagetag | |
run: | | |
#--- set the artifacts url | |
artifactsUrl="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/actions/artifacts" | |
echo artifacts url is $artifactsUrl | |
# --- get the last artifacts download url | |
artifactDlUrl=$(curl --location --header "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" --request GET $artifactsUrl | jq '.artifacts[0].archive_download_url' | tr -d '"') | |
echo artifact download link is $artifactDlUrl | |
# --- download the last artifact and unzip it | |
curl --location --request GET $artifactDlUrl --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' --data-raw '' --output arty.zip | |
echo downloaded artifact arty.zip | |
unzip arty.zip | |
# -- populate the env var IMAGE_TAG | |
IMAGE_TAG=$(cat docker_image_tag.txt) | |
echo image tag is $IMAGE_TAG | |
echo ::set-output name=DOCKER_VERSION_TAG::$IMAGE_TAG | |
# APPLY THE RELEASE TAG TO THE MERGED COMMIT | |
- name: Apply the tag | |
id: applyreleasetag | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token | |
with: | |
tag_name: ${{ steps.retrieveimagetag.outputs.DOCKER_VERSION_TAG }} | |
release_name: Release ${{ steps.retrieveimagetag.outputs.DOCKER_VERSION_TAG }} | |
body: | | |
automatically created release tag | |
draft: false | |
prerelease: false | |
# LOGGING INTO OC PROD | |
- name: OpenShift Action | |
id: GHAOCAuthenticationPrd | |
uses: redhat-developer/[email protected] | |
with: | |
openshift_server_url: ${{ secrets.OPENSHIFT4_SERVER_URL }} | |
parameters: '{"apitoken": "${{ secrets.OPENSHIFT4_TOKEN_PRD }}", "acceptUntrustedCerts": "true"}' | |
cmd: 'version' | |
# DEPLOY TO PROD | |
- name: Deploy to prod | |
id: proddeploy | |
run: | | |
echo deploying to prod | |
DEPLOY_NAMESPACE=${{ secrets.OPENSHIFT4_PRD_NAMESPACE }} | |
# extract deploy name from the template | |
DEPLOYNAME=$(oc process -f ./openshift/deployTemplate.yaml -p ENV=prd | jq '.items[] | select(.kind=="DeploymentConfig") | .metadata.name'| tr -d '"') | |
# process the template, extract only the deploy config, replace the DeploymentConfig | |
oc process -f ./openshift/deployTemplate.yaml -p ENV=prd -p CONTAINER_SRC_SECRET_NAME=bcdcsmk-image-secret -p IMAGE_LABEL=${{ steps.retrieveimagetag.outputs.DOCKER_VERSION_TAG }} -p DEPLOY_NAMESPACE=$DEPLOY_NAMESPACE | python3 openshift/extractFromTemplate.py DeploymentConfig | oc replace -n $DEPLOY_NAMESPACE -f - | |
echo waiting for the oc deploy to complete | |
oc rollout status dc/$DEPLOYNAME -n $DEPLOY_NAMESPACE | |
# LOGGING INTO OC DEV | |
- name: OpenShift Action | |
id: GHAOCAuthenticationDev | |
uses: redhat-developer/[email protected] | |
with: | |
openshift_server_url: ${{ secrets.OPENSHIFT4_SERVER_URL }} | |
parameters: '{"apitoken": "${{ secrets.OPENSHIFT4_TOKEN_DEV }}", "acceptUntrustedCerts": "true"}' | |
cmd: 'version' | |
# TEAR DOWN THE DEV ENV | |
# ----- commented out while testing is going on in BCDC stage deployment ---- | |
# - name: tear down dev env | |
# id: teardowndev | |
# run: | | |
# # tearing down what is deployed in dev | |
# DEPLOY_NAMESPACE=${{ secrets.OPENSHIFT_DEV_NAMESPACE }} | |
# echo deploy namespace is $DEPLOY_NAMESPACE | |
# DOCKER_VERSION_TAG=${{ steps.retrieveimagetag.outputs.DOCKER_VERSION_TAG }} | |
# echo docker tag $DOCKER_VERSION_TAG | |
# #echo tag version is ${{ steps.retrieveimagetag.outputs.DOCKER_VERSION_TAG }} | |
# # ------------------- extract the object names from the template ------------------- | |
# ROUTENAME=$(oc process -f ./openshift/deployTemplate.yaml -p ENV=dev -p IMAGE_LABEL=$DOCKER_VERSION_TAG | jq '.items[] | select(.kind=="Route") | .metadata.name' | tr -d '"') | |
# DEPLOYNAME=$(oc process -f ./openshift/deployTemplate.yaml -p ENV=dev -p IMAGE_LABEL=$DOCKER_VERSION_TAG | jq '.items[] | select(.kind=="DeploymentConfig") | .metadata.name'| tr -d '"') | |
# SERVICENAME=$(oc process -f ./openshift/deployTemplate.yaml -p ENV=dev -p IMAGE_LABEL=$DOCKER_VERSION_TAG | jq '.items[] | select(.kind=="Service") | .metadata.name' | tr -d '"') | |
# echo routename $ROUTENAME | |
# echo depoloyname $DEPLOYNAME | |
# echo servicename $SERVICENAME | |
# # ------------------- delete objects if they exist ------------------- | |
# EXISTINGDEPLOYNAME=$(oc get deploymentconfigs -n $DEPLOY_NAMESPACE -o json | jq '.items[] | select(.metadata.name=="'$DEPLOYNAME'") | .metadata.name' | tr -d '"') | |
# echo existing deploy name $EXISTINGDEPLOYNAME | |
# if [ ! -z "$EXISTINGDEPLOYNAME" ] | |
# then | |
# echo deleting $EXISTINGDEPLOYNAME | |
# oc delete deploymentconfig $EXISTINGDEPLOYNAME | |
# fi | |
# echo route name is $ROUTENAME | |
# EXISTINGROUTENAME=$(oc get routes -n $DEPLOY_NAMESPACE -o json | jq '.items[] | select(.metadata.name=="'$ROUTENAME'") | .metadata.name' | tr -d '"') | |
# if [ ! -z "$EXISTINGROUTENAME" ] | |
# then | |
# oc delete route $EXISTINGROUTENAME | |
# fi | |
# EXISTINGSERVICENAME=$(oc get services -n $DEPLOY_NAMESPACE -o json | jq '.items[] | select(.metadata.name=="'$SERVICENAME'") | .metadata.name' | tr -d '"') | |
# echo service name is $EXISTINGSERVICENAME | |
# if [ ! -z "$EXISTINGSERVICENAME" ] | |
# then | |
# oc delete service $EXISTINGSERVICENAME | |
# fi |