-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure.Rmd
222 lines (135 loc) · 8.52 KB
/
azure.Rmd
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
---
editor_options:
markdown:
wrap: sentence
---
# Deploying to Azure {#azure}
The Azure DevOps site for PIP currently consists of two repos:
- ITSES-POVERTYSCORE (docker file repo)
- ITSES-POVERTYSCORE-DATA (data repo)
Each repo consists of three branches:
- DEV
- QA
- PROD
The PIP Technical Team will handle deployments to DEV and QA, while ITS needs to approve deployments to Production.
## Poverty Calculator Data {#azure-pc-data}
[Note: The Azure Data repo has now been directly synced with pipeline outputs folder on the PIP network drive. There is thus no longer any need to push changes from your local computer.]{style="color:red"}
### Deploying data on DEV
Deploying the data to DEV consists of four main stages:
- Sync local data to remote Git repository on TFS
- Run the Continuous Integration pipeline (CI)
- Run the Continuous Deployment pipeline (CD) to move the data to Azure blob storage
- Data is moved to the Virtual Machine (VM) running the API This stage is completed automatically every 30 minutes (as of 11/02/2021)
You can deploy data to DEV by following the steps below:
#### Sync data to remote repo on TFS
**Step 1:** Sync you local DEV branch with the remote.
**Step 2:** Commit and push any data changes to the remote.
#### Run CI pipeline
**Step 3:** Nagivate to the [Azure DevOps Data repo](https://github.com/PIP-Technical-Team/PIP_private/blob/main/README.md#resources).
Click on Pipelines.
![](img/azure_pc_data_pipeline_step2.png)
**Step 4:** Select the FILE-COPY-DEV-CI pipeline.
![](img/azure_pc_data_pipeline_step3.png)
**Step 5:** Click on Run pipeline.
![](img/azure_pc_data_pipeline_step4.png)
**Step 6:** Click on Variables -\> FolderName, and add the name of the folder which should be copied to the Cloud Blob Store.
[Note: This step is likely to change when the Data pipeline is re-written to handle mulitiple data version folders.]{style="color:red"}
![](img/azure_pc_data_pipeline_step5-1.png)
![](img/azure_pc_data_pipeline_step5-2.png)
![](img/azure_pc_data_pipeline_step5-3.png)
**Step 7:** Click on Run.
![](img/azure_pc_data_pipeline_step6.png)
**Step 8:** View the new build.
![](img/azure_pc_data_pipeline_step7.png)
#### Run CD pipeline
**Step 9:** Click on Releases and select the FILE-COPY-DEV-CD release.
Approve the pending request.
![](img/azure_pc_data_pipeline_step8-1.png)
![](img/azure_pc_data_pipeline_step8-2.png)
![](img/azure_pc_data_pipeline_step8-3.png)
**Step 10:** Verify that the build completed.
![](img/azure_pc_data_pipeline_step9.png)
#### Move data to VM
**Step 11:** Wait for the data on the VM to be updated.
There is an automatic cron job that runs behind the scenes to copy the data from the blob storage to the VM.
This runs at regular intervals, every 30 (?) minutes.
You can use the `/data-timestamp` endpoint to verify that the transfer has completed.
For additional information you can also use the `/dir-info` endpoint.
#### Restart the Docker container
**Step 12:** Restart the Docker container by running the `RESTARTCONTAINER-DEV-CD` release pipeline.
#### Clear the VM cache
**Step 13:** If you conducted a data update that includes changes to survey data or the estimation tables for an already existing version folder you will need to clear the cache on the VM.
Use the specific API endpoints for cache handling to do this.
[Note: If in doubt always clear the cache.]{style="color:red"}
### Deploying data on QA
**Step 1:** Nagivate to the [Azure DevOps Data repo](https://github.com/PIP-Technical-Team/PIP_private/blob/main/README.md#resources).
**Step 2:** Click on Create pull request.
Select from DEV to QA.
**Step 3:** Go through the steps to commit and approve the pull request.
Please make sure that the **"Delete source branch" box is NOT checked**, ie.
don't delete the DEV branch.
(This default should be modified going forward)
**Step 5:** Go to Pipelines -\> Pipelines and select the FILE-COPY-QA-CI pipeline.
Verify that the pipeline is building.
If it wasn't triggered you will need to trigger it manually.
**Step 6:** Go to Pipelines -\> Releases and select the FILE-COPY-QA-CD release.
Approve the request, and verify that the build completes.
**Step 7:** Run the `RESTARTCONTAINER-QA-CD` release pipeline after the data transfer to the VMs has completed.
**Step 8:** Clear the cache on the VMs if needed.
[Note: If in doubt always clear the cache.]{style="color:red"}
### Deploying data to Production
**Step 1:** Nagivate to the [Azure DevOps Data repo](https://github.com/PIP-Technical-Team/PIP_private/blob/main/README.md#resources).
**Step 2:** Click on Create pull request.
Select from QA to PROD.
**Step 3:** Go through the steps to commit and approve the pull request.
Please make sure that the "Delete source branch" box is unchecked, ie.
don't delete the QA branch.
**Step 5:** Go to Pipelines -\> Pipelines and select the FILE-COPY-PROD-CI pipeline.
Verify that the pipeline is building.
If it wasn't triggered you will need to trigger it manually.
**Step 6:** Go to Pipelines -\> Releases and select the FILE-COPY-QA-CD release.
Wait for ITS to approve the request, and then verify that the build completes.
**Step 7:** Run the `RESTARTCONTAINER-PROD-CD` release pipeline after the data transfer to the VMs has completed.
**Step 8:** Clear the cache on the VMs.
## Poverty Calculator Docker image {#azure-pc-docker}
Before you start with the application deployment process you will need to clone the [Azure DevOps Docker](https://github.com/PIP-Technical-Team/PIP_private/blob/main/README.md#resources) repo (DEV branch) to your local machine.
You will only need to do this once.
After that you can follow the step by step guide below.
Please note that it is important that data changes are pushed through and released before deploying the Docker image.
This is because the Docker container will need to restart in order to pick up changes in the mounted folder or volume.
The best way to do this is to deploy the data, and then use the API restart pipeline to ensure a restart of the Docker container.
### Deploying image on DEV
**Step 1:** Verify that the latest code in the master branches of {wbpip} and {pipapi} works with the latest data on DEV.
This can be done by running the {pipapi} package in a local RStudio session.
**Step 2:** $$Optional$$ Verify that the most recent Dockerfile builds on your local machine.
This is certainly something that should be done if the contents of the Dockerfile has changed, or before major releases.
But in a continuous workflow where you know that Dockerfile hasn't changed, it might be sufficient to verify that the R packages in question are working.
**Step 3:** Navigate to the [Azure DevOps Docker repo](https://github.com/PIP-Technical-Team/PIP_private/blob/main/README.md#resources).
Go Pipelines -\> Pipelines.
Trigger the CONTAINER-DEV-CI pipeline, either by\
a) Pushing an updated Dockerfile to the remote repo or\
b) Running the Pipeline manually.
**Step 4:** Go to the Pipelines -\> Releases, and select "Create release" in order to run a new deployment.
View the logs to see results from the image build and security scan.
**Step 5:**.
Visit the [DEV API website](https://github.com/PIP-Technical-Team/PIP_private/blob/main/README.md#resources) for further testing.
### Deploying image on QA
**Step 1:** Check that the DEV deployment is working correctly.
**Step 2:** Make sure the data on QA is up-to-date (in sync with DEV).
If it isn't you will need to create a PR and merge the data first.
**Step 3:** Create a pull request from DEV to QA.
Go through the steps to commit and approve the pull request.
Please make sure that the **"Delete source branch" box is NOT checked**, ie.
don't delete the DEV branch.
**Step 4:** Go to the Release pipeline to see results from the image build and security scan.
**Step 5:** Visit the [QA API website](https://github.com/PIP-Technical-Team/PIP_private/blob/main/README.md#resources) for further testing.
### Deploying image to Production
**Step 1:** Check that the QA deployment is working correctly.
**Step 2:** Make sure the data on PROD is up-to-date (in sync with QA).
If it isn't you will need to create a PR and merge the data first.
**Step 3:** Create a pull request from QA to PROD.
Go through the steps to commit and approve the pull request.
Please make sure that the **"Delete source branch" box is NOT checked**, ie.
don't delete the QA branch.
**Step 4:** Go to the Release pipeline to see results from the image build and security scan.
**Step 5:** Visit the [PROD API website](https://github.com/PIP-Technical-Team/PIP_private/blob/main/README.md#resources) for further testing.