-
Notifications
You must be signed in to change notification settings - Fork 2
170 lines (153 loc) · 6.31 KB
/
Copy path.tools-deploy.yml
File metadata and controls
170 lines (153 loc) · 6.31 KB
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
name: Tools deployment
on:
pull_request:
concurrency:
# PR open and close use the same group, allowing only one at a time
group: tools-${{ github.event.number }}
cancel-in-progress: true
permissions: {}
jobs:
builds:
name: Builds
runs-on: ubuntu-24.04
permissions:
packages: write
steps:
- name: Build (legacydb)
uses: bcgov/action-builder-ghcr@cb2629351c87dd1c2130073e4ebb7233a9653a63 # v4.4.1
with:
package: legacydb
tag_fallback: latest
triggers: ('legacydb/')
- name: Build (backend) with Sectigo PEM
uses: bcgov/action-builder-ghcr@cb2629351c87dd1c2130073e4ebb7233a9653a63 # v4.4.1
with:
package: backend
tag_fallback: latest
triggers: ('backend/')
build_args: |
--build-arg SECTIGO_R46_PEM=${{ secrets.SECTIGO_R46_PEM }}
pre-tools:
name: Pre Deploy Tools
needs: [builds]
runs-on: ubuntu-24.04
steps:
- name: Scale down legacy
continue-on-error: true
uses: bcgov/action-oc-runner@09b5eeae15bdbc7f7a21b406ee2c66a1d5819f8c # v1.6.0
with:
oc_namespace: ${{ secrets.oc_namespace }}
oc_token: ${{ secrets.oc_token }}
oc_server: ${{ secrets.oc_server }}
commands: |
oc scale deployment/nr-forest-client-${{ github.event.number }}-legacy --replicas=0 -n ${{ secrets.OC_NAMESPACE }}
undesired_replicas=0
while true; do
available_replicas=$(oc get deployment/nr-forest-client-${{ github.event.number }}-legacy -n ${{ secrets.OC_NAMESPACE }} -o jsonpath='{.status.availableReplicas}')
if [[ "$available_replicas" -ge "$undesired_replicas" ]]; then
echo "DeploymentConfig ${{ secrets.OC_NAMESPACE }}-${{ github.event.number }}-legacy is now available with $available_replicas replicas."
break
fi
echo "Waiting... ($available_replicas pods available)"
sleep 5
done
deploy-oracle:
name: Deploy Oracle Database
needs: [pre-tools, builds]
runs-on: ubuntu-24.04
steps:
- name: Initializing Deployment
uses: bcgov/action-deployer-openshift@fc51e6a5849eb0fdb9395ceed9c1059aa25b3815 # v4.1.1
with:
file: legacydb/openshift.deploy.yml
oc_namespace: d2723f-tools
oc_server: ${{ secrets.oc_server }}
oc_token: ${{ secrets.oc_token_tools }}
oc_version: "4.13"
overwrite: false
parameters:
-p ZONE=tools
-p ORACLEDB_PASSWORD=${{ secrets.ORACLEDB_PASSWORD }}
-p TAG=${{ github.event.number }}
remove-tools:
name: Remove database and user
needs: [deploy-oracle]
secrets: inherit
uses: ./.github/workflows/.tools-cleanup.yml
deploy-tools:
name: Deploy Tools
needs: [remove-tools, deploy-oracle]
runs-on: ubuntu-24.04
steps:
- name: Create the PR database
continue-on-error: true
uses: bcgov/action-oc-runner@09b5eeae15bdbc7f7a21b406ee2c66a1d5819f8c # v1.6.0
with:
oc_namespace: d2723f-tools
oc_server: ${{ secrets.oc_server }}
oc_token: ${{ secrets.oc_token_tools }}
commands: |
# This creates a new pluggable database for the PR
for i in {1..5}; do
POD_NAME=$(oc get pods -l app=nr-forest-client-tools -l deployment=nr-forest-client-tools-legacydb -o jsonpath='{.items[0].metadata.name}' 2>/dev/null)
if [ -n "$POD_NAME" ]; then
echo "Pod found: $POD_NAME"
oc exec $POD_NAME -- /opt/oracle/createDatabase PR_${{ github.event.number }}
break
else
echo "Pod not found, retrying in 10 seconds... ($i/5)"
sleep 10
fi
done
if [ -z "$POD_NAME" ]; then
echo "Failed to find the pod after 5 attempts."
fi
- name: Create the PR user
continue-on-error: true
uses: bcgov/action-oc-runner@09b5eeae15bdbc7f7a21b406ee2c66a1d5819f8c # v1.6.0
with:
oc_namespace: d2723f-tools
oc_server: ${{ secrets.oc_server }}
oc_token: ${{ secrets.oc_token_tools }}
commands: |
# This creates a new pluggable database for the PR
for i in {1..5}; do
POD_NAME=$(oc get pods -l app=nr-forest-client-tools -l deployment=nr-forest-client-tools-legacydb -o jsonpath='{.items[0].metadata.name}' 2>/dev/null)
if [ -n "$POD_NAME" ]; then
echo "Pod found: $POD_NAME"
oc exec $POD_NAME -- /opt/oracle/createAppUser "THE" "${{ secrets.ORACLEDB_PASSWORD }}" "PR_${{ github.event.number }}"
break
else
echo "Pod not found, retrying in 10 seconds... ($i/5)"
sleep 10
fi
done
if [ -z "$POD_NAME" ]; then
echo "Failed to find the pod after 5 attempts."
fi
- name: Migrate the PR database
continue-on-error: true
uses: bcgov/action-oc-runner@09b5eeae15bdbc7f7a21b406ee2c66a1d5819f8c # v1.6.0
with:
oc_namespace: d2723f-tools
oc_server: ${{ secrets.oc_server }}
oc_token: ${{ secrets.oc_token_tools }}
commands: |
BRANCH_NAME="${{ github.head_ref }}"
ESCAPED_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[\/&]/\\&/g')
oc create job --from=cronjob/nr-forest-client-tools-migratedb migrate-pr${{ github.event.number }}-${{ github.run_attempt }}-$(date +%s) --dry-run=client -o yaml | sed "s/value: main/value: ${ESCAPED_BRANCH_NAME}/" | sed "s/value: \"0\"/value: \"${{ github.event.number }}\"/" | oc apply -f -
scale-up-legacy:
name: Scale up legacy
needs: [deploy-tools]
if: always()
runs-on: ubuntu-24.04
steps:
- name: Start the Legacy Service
continue-on-error: true
uses: bcgov/action-oc-runner@09b5eeae15bdbc7f7a21b406ee2c66a1d5819f8c # v1.6.0
with:
oc_namespace: ${{ secrets.oc_namespace }}
oc_token: ${{ secrets.oc_token }}
oc_server: ${{ secrets.oc_server }}
commands: |
oc scale deployment/nr-forest-client-${{ github.event.number }}-legacy --replicas=1