-
Notifications
You must be signed in to change notification settings - Fork 0
188 lines (158 loc) · 8.2 KB
/
devdeploy.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: "DEV Deploy"
#TODO: once working change the event the action is associated to the one below
on:
workflow_run:
workflows: ["BUILD Package", "build"]
types:
- completed
jobs:
deploydev:
defaults:
run:
shell: bash
runs-on: ubuntu-18.04
outputs:
dockerversiontag: ${{ steps.retrieveimagetag.outputs.DOCKER_VERSION_TAG }}
issue_url: ${{ steps.retrieveimagetag.outputs.ISSUE_URL }}
routepath: ${{ steps.deploydev.outputs.ROUTEPATH }}
eventinfo: ${{ steps.retrieveimagetag.outputs.EVENT_INFO }}
steps:
# Checking out code to get access to the openshift deploy template later on
# could also reference the github url?
- uses: actions/checkout@v2
id: checkout
with:
fetch-depth: 0
# RETRIEVE THE IMAGE TAG
- name: Retrieve image tag
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
# -- populate the issue url
ISSUE_URL=$(cat issue_url.txt)
echo issue url is $ISSUE_URL
echo "::set-output name=ISSUE_URL::$ISSUE_URL"
EVENT_INFO=$(cat git_event.txt)
echo event info is $EVENT_INFO
echo "::set-output name=EVENT_INFO::$EVENT_INFO"
# Clean up the downloaded artifact
rm docker_image_tag.txt
rm arty.zip
# LOGGING INTO OC
- name: OpenShift Action
id: GHAOpenshiftTest
uses: redhat-developer/[email protected]
with:
openshift_server_url: ${{ secrets.OPENSHIFT4_SERVER_URL }}
parameters: '{"apitoken": "${{ secrets.OPENSHIFT4_TOKEN_DEV }}", "acceptUntrustedCerts": "true"}'
cmd: 'version'
# PERFORM THE DEPLOY
- name: deploy dev
id: deploydev
run: |
DEPLOY_NAMESPACE=${{ secrets.OPENSHIFT4_DEV_NAMESPACE }}
DEV_DEPLOY_ROUTE_HOST=bcdc-smk-dev.data.gov.bc.ca
DOCKER_VERSION_TAG=${{ steps.retrieveimagetag.outputs.DOCKER_VERSION_TAG }}
echo docker tag $DOCKER_VERSION_TAG
# ------------------- extract the object names from the template -------------------
ROUTENAME_KONG=$(oc process -f ./openshift/deployTemplate.yaml -p ENV=dev -p IMAGE_LABEL=$DOCKER_VERSION_TAG | jq '.items[] | select(.kind=="Route") | .metadata.name' | tr -d '"' | grep extrt)
ROUTENAME_OC=$(oc process -f ./openshift/deployTemplate.yaml -p ENV=dev -p IMAGE_LABEL=$DOCKER_VERSION_TAG | jq '.items[] | select(.kind=="Route") | .metadata.name' | tr -d '"' | grep "\-rt")
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_KONG
EXISTINGROUTENAME=$(oc get routes -n $DEPLOY_NAMESPACE -o json | jq '.items[] | select(.metadata.name=="'$ROUTENAME_KONG'") | .metadata.name' | tr -d '"')
if [ ! -z "$EXISTINGROUTENAME" ]
then
oc delete route $EXISTINGROUTENAME
fi
echo route name is $ROUTENAME_OC
EXISTINGROUTENAME=$(oc get routes -n $DEPLOY_NAMESPACE -o json | jq '.items[] | select(.metadata.name=="'$ROUTENAME_OC'") | .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
# ------------------- NOW CREATE THE OBJECTS -------------------
oc process -f ./openshift/deployTemplate.yaml -p ENV=dev -p CONTAINER_SRC_SECRET_NAME=bcdcsmk-image-secret -p IMAGE_LABEL=${{ steps.retrieveimagetag.outputs.DOCKER_VERSION_TAG }} -p DEPLOY_NAMESPACE=$DEPLOY_NAMESPACE -p ROUTE_HOST=$DEV_DEPLOY_ROUTE_HOST | python3 openshift/extractFromTemplate.py Route Service DeploymentConfig | oc create -n $DEPLOY_NAMESPACE -f -
echo waiting for the oc deploy to complete
oc rollout status dc/$DEPLOYNAME -n $DEPLOY_NAMESPACE
echo route name is $ROUTENAME
# ---- get the path associated with the route
ROUTEPATH_KONG=$(oc get routes -n $DEPLOY_NAMESPACE -o json | jq '.items[] | select(.metadata.name=="'$ROUTENAME_KONG'") | .spec.host' | tr -d '"')
# ------------------- SET THE ROUTEPATH ouptut
echo ::set-output name=ROUTEPATH::$ROUTEPATH_KONG
# ADD A DEPLOY MONITOR STEP TO MAKE SURE IT WAS SUCCESSFUL
# ADD THE ROUTE TO THE ISSUE
- name: Update issue
id: updateissue
run: |
echo the GITHUB_EVENT_PATH
cat $GITHUB_EVENT_PATH
ROUTEPATH=${{ steps.deploydev.outputs.ROUTEPATH }}
# GET THE ISSUE URL
#issue_url=$(jq --raw-output .pull_request.issue_url "$GITHUB_EVENT_PATH")
#echo issue url is $issue_url
## for debugging using existing pull_request
#if [ -z "$issue_url" ] || [ "$issue_url" = "null" ]
# then
# issue_url="https://api.github.com/repos/bcgov/bcdc-smk/issues/19/comments"
#fi
#echo issue url $issue_url
ISSUE_URL=${{ steps.retrieveimagetag.outputs.ISSUE_URL }}
# ADD COMMENT TO THE ISSUE
echo 'adding route to the comment for the issue'
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
ISSUE_COMMENT="link to demo deployment of app\n https://${{ steps.deploydev.outputs.ROUTEPATH }}\n\nVerify that it looks good, if so merge the pr, otherwise close"
ISSUE_BODY='{"body": "'$ISSUE_COMMENT'"}'
curl $ISSUE_URL -X POST --header "Authorization: Bearer $GITHUB_TOKEN" \
--header "Accept: application/vnd.github.v3+json" \
--data-raw "$ISSUE_BODY"
- name: "Send Review Request 2"
id: requestreview
run: |
# git_event.txt
EVENT_INFO=$(cat git_event.txt)
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
PR_NUMBER=$(echo $EVENT_INFO | jq ".number")
echo pr number is $PR_NUMBER
PR_URL=$(echo $EVENT_INFO | jq ".pull_request.url" | tr -d '"')
echo pr url is $PR_URL
REVIEW_URL="$PR_URL/requested_reviewers"
echo review url $REVIEW_URL
REVIEWERS='{"reviewers":["GuyTheFlower", "NicoledeGreef"]}'
echo reviewers are $REVIEWERS
curl --location --request POST "$REVIEW_URL" \
--header "Authorization: Bearer $GITHUB_TOKEN" \
--header 'Content-Type: text/plain' \
--data-raw "$REVIEWERS"