-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (130 loc) · 6.33 KB
/
prddeploy.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# 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