-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.bicep
394 lines (367 loc) · 12.7 KB
/
main.bicep
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
var shareName = 'open-test-data'
var storageAccountName = uniqueString(resourceGroup().id, deployment().name)
var roleAssignmentName = guid('${resourceGroup().name}contributor')
var acrName = uniqueString(resourceGroup().id, deployment().name)
var managedIdentityName = uniqueString(resourceGroup().id, deployment().name)
var contributorRoleDefinitionId = resourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')
var containerImageName = 'osdu-data-load-tno:latest'
var templateSpecName = 'osdu-data-load-tno'
var templateSpecVersionName = '1.0'
resource userAssignedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2021-09-30-preview' = {
name: managedIdentityName
location: resourceGroup().location
}
resource storage 'Microsoft.Storage/storageAccounts@2021-04-01' = {
name: storageAccountName
location: resourceGroup().location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
properties: {
allowBlobPublicAccess: false
}
resource fileService 'fileServices' = {
name: 'default'
resource dataShare 'shares' = {
name: shareName
}
resource outputShare 'shares' = {
name: 'output'
}
}
}
resource registry 'Microsoft.ContainerRegistry/registries@2021-06-01-preview' = {
name: acrName
location: resourceGroup().location
sku: {
name: 'Standard'
}
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${userAssignedIdentity.id}': {}
}
}
properties: {
anonymousPullEnabled: true
}
}
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2020-10-01-preview' = {
name: roleAssignmentName
scope: resourceGroup()
properties: {
description: 'Managed identity access for the RG'
roleDefinitionId: contributorRoleDefinitionId
principalId: userAssignedIdentity.properties.principalId
principalType: 'ServicePrincipal'
}
}
resource uploadDeploymentScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: 'fileshare-load'
location: resourceGroup().location
kind: 'AzureCLI'
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${userAssignedIdentity.id}': {}
}
}
properties: {
azCliVersion: '2.37.0'
timeout: 'PT3H'
retentionInterval: 'PT1H'
cleanupPreference: 'OnSuccess'
environmentVariables: [
{
name: 'AZURE_STORAGE_ACCOUNT'
value: storage.name
}
{
name: 'AZURE_STORAGE_KEY'
secureValue: storage.listKeys().keys[0].value
}
{
name: 'AZURE_STORAGE_SHARE'
value: 'open-test-data'
}
]
scriptContent: '''
#!/bin/bash
set -e
LOG=script_log.txt
FILE_NAME=open-test-data.gz
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
DATA_DIR="/tmp/${AZURE_STORAGE_SHARE}"
echo -e "Retrieving data from OSDU..." 2>&1 | tee -a $LOG
wget -O $FILE_NAME https://community.opengroup.org/osdu/platform/data-flow/data-loading/open-test-data/-/archive/v0.17.0/open-test-data-v0.17.0.tar.gz 2>&1 | tee -a $LOG
# Create Directory structure
echo -e "Creating Directory structure..." 2>&1 | tee -a $LOG
mkdir -p $DATA_DIR/datasets/documents
mkdir -p $DATA_DIR/datasets/markers
mkdir -p $DATA_DIR/datasets/trajectories
mkdir -p $DATA_DIR/datasets/well-logs
mkdir -p $DATA_DIR/schema
mkdir -p $DATA_DIR/templates
mkdir -p $DATA_DIR/TNO/contrib
mkdir -p $DATA_DIR/TNO/provided
ls -l $DATA_DIR | tee -a $LOG
tar -xzvf $FILE_NAME -C $DATA_DIR/datasets/documents --strip-components=5 open-test-data-v0.17.0/rc--1.0.0/1-data/3-provided/USGS_docs
echo -e "Extracted Dataset Documents" 2>&1 | tee -a $LOG
tar -xzvf $FILE_NAME -C $DATA_DIR/datasets/markers --strip-components=5 open-test-data-v0.17.0/rc--1.0.0/1-data/3-provided/markers
echo -e "Extracted Dataset Markers" 2>&1 | tee -a $LOG
tar -xzvf $FILE_NAME -C $DATA_DIR/datasets/trajectories --strip-components=5 open-test-data-v0.17.0/rc--1.0.0/1-data/3-provided/trajectories
echo -e "Extracted Dataset Trajectories" 2>&1 | tee -a $LOG
tar -xzvf $FILE_NAME -C $DATA_DIR/datasets/well-logs --strip-components=5 open-test-data-v0.17.0/rc--1.0.0/1-data/3-provided/well-logs
echo -e "Extracted Dataset Well Logs" 2>&1 | tee -a $LOG
tar -xzvf $FILE_NAME -C $DATA_DIR/schema --strip-components=3 open-test-data-v0.17.0/rc--3.0.0/3-schema
echo -e "Extracted Schemas" 2>&1 | tee -a $LOG
tar -xzvf $FILE_NAME -C $DATA_DIR/templates --strip-components=3 open-test-data-v0.17.0/rc--3.0.0/5-templates
echo -e "Extracted Templates" 2>&1 | tee -a $LOG
tar -xzvf $FILE_NAME -C $DATA_DIR/TNO/contrib --strip-components=5 open-test-data-v0.17.0/rc--3.0.0/1-data/3-provided/TNO
echo -e "Extracted TNO Contrib" 2>&1 | tee -a $LOG
tar -xzvf $FILE_NAME -C $DATA_DIR/TNO/provided --strip-components=3 open-test-data-v0.17.0/rc--3.0.0/4-instances/TNO
echo -e "Extracted TNO Provided" 2>&1 | tee -a $LOG
# Upload to Azure Storage
echo -e "Files Uploading..." 2>&1 | tee -a $LOG
az storage file upload-batch --destination $AZURE_STORAGE_SHARE --source $DATA_DIR | tee -a $LOG
echo -e "Upload Complete" 2>&1 | tee -a $LOG
echo '{"status": {"download": "Success", "extract": "Success", "upload": "Success"}}' | jq > $AZ_SCRIPTS_OUTPUT_PATH
'''
}
}
resource acrDockerImage 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: 'build-and-push-image'
location: resourceGroup().location
kind: 'AzureCLI'
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${userAssignedIdentity.id}': {}
}
}
properties: {
azCliVersion: '2.37.0'
timeout: 'PT2H'
retentionInterval: 'PT1H'
cleanupPreference: 'OnSuccess'
environmentVariables: [
{
name: 'CONTAINER_IMAGE_NAME'
value: containerImageName
}
{
name: 'REGISTRY_NAME'
value: acrName
}
{
name: 'AZURE_TENANT'
value: subscription().tenantId
}
]
scriptContent: '''
#!/bin/bash
set -e
LOG=script_log.txt
FILE_NAME=main.zip
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
DATA_DIR="/tmp/osdu-data-load-tno-main"
echo -e "Retrieving Source..." 2>&1 | tee -a $LOG
wget -O $FILE_NAME https://github.com/Azure/osdu-data-load-tno/archive/refs/heads/main.zip 2>&1 | tee -a $LOG
unzip $FILE_NAME -d /tmp
echo -e "Extracted Source" 2>&1 | tee -a $LOG
echo -e "Build and Import Image: ${CONTAINER_IMAGE_NAME} into ACR: ${REGISTRY_NAME}" 2>&1 | tee -a $LOG
az acr build --build-arg AZURE_TENANT=$AZURE_TENANT --image ${CONTAINER_IMAGE_NAME} --registry ${REGISTRY_NAME} --file ${DATA_DIR}/Dockerfile $DATA_DIR | tee -a $LOG
echo '{"status": {"download": "Success", "extract": "Success", "docker": "Success"}}' | jq > $AZ_SCRIPTS_OUTPUT_PATH
'''
}
}
resource createTemplateSpec 'Microsoft.Resources/templateSpecs@2021-05-01' = {
name: templateSpecName
location: resourceGroup().location
properties: {
description: 'Load OSDU with Open Test Data.'
displayName: 'Open Test Data Load'
}
}
resource createTemplateSpecVersion 'Microsoft.Resources/templateSpecs/versions@2021-05-01' = {
parent: createTemplateSpec
name: templateSpecVersionName
location: resourceGroup().location
properties: {
mainTemplate: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
'contentVersion': '1.0.0.0'
'parameters': {
'endpoint': {
'type': 'string'
'metadata': {
'description': 'OSDU API Endpoint - Example https://myosdu.energy.azure.com'
}
}
'dataPartition': {
'type': 'string'
'defaultValue': 'opendes'
'metadata': {
'description': 'OSDU Data Partition Name'
}
}
'viewerGroup': {
'type': 'string'
'defaultValue': 'data.default.viewers'
'metadata': {
'description': 'OSDU Reader Group ACL'
}
}
'ownerGroup': {
'type': 'string'
'defaultValue': 'data.default.owners'
'metadata': {
'description': 'OSDU Owner Group ACL'
}
}
'dataDomain': {
'type': 'string'
'defaultValue': 'dataservices.energy'
'metadata': {
'description': 'OSDU ACL Group Domain'
}
}
'legalTag': {
'type': 'string'
'metadata': {
'description': 'OSDU Legal Tag Name'
}
}
'clientId': {
'type': 'string'
'metadata': {
'description': 'OSDU Client Id'
}
}
'clientSecret': {
'type': 'securestring'
'metadata': {
'description': 'OSDU Client Secret'
}
}
'logLevel': {
'type': 'string'
'defaultValue': 'INFO'
'allowedValues': [
'DEBUG'
'INFO'
'WARN'
'ERROR'
]
'metadata': {
'description': 'Log level for data load'
}
}
}
'variables': {
'acrName': acrName
'imageName': containerImageName
}
'resources': [
{
'type': 'Microsoft.ContainerInstance/containerGroups'
'apiVersion': '2021-09-01'
'name': '[concat(\'osdu-data-load-\', parameters(\'dataPartition\'))]'
'location': '[resourcegroup().location]'
'properties': {
'containers': [
{
'name': 'load'
'properties': {
'image': '[concat(variables(\'acrName\'), \'.azurecr.io/\', variables(\'imageName\'))]'
'command': []
'environmentVariables': [
{
'name': 'OSDU_ENDPOINT'
'value': '[parameters(\'endpoint\')]'
}
{
'name': 'DATA_PARTITION'
'value': '[parameters(\'dataPartition\')]'
}
{
'name': 'ACL_VIEWER'
'value': '[parameters(\'viewerGroup\')]'
}
{
'name': 'ACL_OWNER'
'value': '[parameters(\'ownerGroup\')]'
}
{
'name': 'DOMAIN'
'value': '[parameters(\'dataDomain\')]'
}
{
'name': 'LEGAL_TAG'
'value': '[parameters(\'legalTag\')]'
}
{
'name': 'CLIENT_ID'
'value': '[parameters(\'clientId\')]'
}
{
'name': 'CLIENT_SECRET'
'secureValue': '[parameters(\'clientSecret\')]'
}
{
'name': 'WORKERS'
'value': 50
}
{
'name': 'LOG_LEVEL'
'value': '[parameters(\'logLevel\')]'
}
]
'ports': []
'volumeMounts': [
{
'name': 'opentestdata'
'mountPath': '/app/open-test-data'
}
{
'name': 'output'
'mountPath': '/app/output'
}
]
'resources': {
'requests': {
'cpu': 4
'memoryInGB': 16
}
}
}
}
]
'osType': 'Linux'
'restartPolicy': 'Never'
'volumes': [
{
'name': 'opentestdata'
'azureFile': {
'shareName': shareName
'storageAccountName': storage.name
'storageAccountKey': storage.listKeys().keys[0].value
}
}
{
'name': 'output'
'azureFile': {
'shareName': 'output'
'storageAccountName': storage.name
'storageAccountKey': storage.listKeys().keys[0].value
}
}
]
}
}
]
}
}
}
output scriptLogs string = reference('${uploadDeploymentScript.id}/logs/default', uploadDeploymentScript.apiVersion, 'Full').properties.log