Add TaskRun ARM template sample files

This commit is contained in:
Huangli Wu 2019-11-18 17:52:49 -08:00
Родитель ef2a4c2110
Коммит df4ed7aa3d
12 изменённых файлов: 754 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,55 @@
# Quick docker build
## Create a resource group
```bash
az group create \
-n mytaskrunrg \
-l westus
```
## Deploy a registry and a task run which builds/pushes to the registry
```bash
registry=$(az group deployment create \
-g mytaskrunrg \
--template-file azuredeploy.json \
--parameters azuredeploy.parameters.json \
--query 'properties.outputs.registry.value' \
-o tsv)
```
## List the image tag
```bash
az acr repository list -n $registry -o tsv \
| xargs -I% az acr repository show-tags -n $registry --repository % --detail -o table
```
## Crate a user assigned identity
identity=$(az identity create \
-g mytaskrunrg \
-n myquickdockerbuildrunwithidentity \
--query 'id' \
-o tsv)
## Deploy a task run which is associated with the user assigned identity and builds/pushes an image to the registry
```bash
registry=$(az group deployment create \
-g mytaskrunrg \
--template-file azuredeploy.json \
--parameters azuredeploy.parameters.json \
--parameters userAssignedIdentity=$identity \
--parameters taskRunName=mytaskrunwithidentity \
--query 'properties.outputs.registry.value' \
-o tsv)
```
## List the image tag
```bash
az acr repository list -n $registry -o tsv \
| xargs -I% az acr repository show-tags -n $registry --repository % --detail -o table
```

Просмотреть файл

@ -0,0 +1,140 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"registryName": {
"type": "string",
"minLength": 5,
"maxLength": 50,
"metadata": {
"description": "Name of your Azure Container Registry"
}
},
"registrySku": {
"type": "string",
"metadata": {
"description": "Tier of your Azure Container Registry"
},
"defaultValue": "Basic",
"allowedValues": [
"Basic",
"Standard",
"Premium"
]
},
"registryAdminUserEnabled": {
"type": "bool",
"defaultValue": false,
"metadata": {
"description": "Enable admin user that have push / pull permission to the registry"
}
},
"taskRunName": {
"type": "string",
"minLength": 5,
"maxLength": 50,
"metadata": {
"description": "Name of your Task Run"
}
},
"userAssignedIdentity": {
"type": "string",
"metadata": {
"description": "The user assigned identity to be bound to the task run"
},
"defaultValue": ""
},
"sourceLocation": {
"type": "string",
"metadata": {
"description": "The location of the source to build the image"
}
},
"dockerFilePath": {
"type": "string",
"metadata": {
"description": "The relative path of the dockerfile in the source location"
},
"defaultValue": "Dockerfile"
}
},
"variables": {
"repository": "hello-world-node",
"tag": "parameters('taskRunName')",
"imageName": "[concat(variables('repository'), ':', parameters('taskRunName'))]",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"[parameters('userAssignedIdentity')]": {}
}
}
},
"resources": [
{
"type": "Microsoft.ContainerRegistry/registries",
"name": "[parameters('registryName')]",
"apiVersion": "2017-10-01",
"location": "[parameters('location')]",
"comments": "Container registry for storing docker images",
"tags": {
"displayName": "Container Registry",
"container.registry": "[parameters('registryName')]"
},
"sku": {
"name": "[parameters('registrySku')]",
"tier": "[parameters('registrySku')]"
},
"properties": {
"adminUserEnabled": "[parameters('registryAdminUserEnabled')]"
},
"resources": [
{
"type": "taskRuns",
"name": "[parameters('taskRunName')]",
"location": "[parameters('location')]",
"apiVersion": "2019-06-01-preview",
"dependsOn": [
"[parameters('registryName')]"
],
"identity": "[if(not(empty(parameters('userAssignedIdentity'))), variables('identity'), '')]",
"properties": {
"runRequest": {
"type": "DockerBuildRequest",
"dockerFilePath": "[parameters('dockerFilePath')]",
"imageNames": [
"[variables('imageName')]"
],
"sourceLocation": "[parameters('sourceLocation')]",
"isPushEnabled": true,
"platform": {
"os": "linux",
"architecture": "amd64"
}
}
}
}
]
}
],
"outputs": {
"registry": {
"type": "string",
"value": "[parameters('registryName')]"
},
"repository": {
"type": "string",
"value": "[variables('repository')]"
},
"tag": {
"type": "string",
"value": "[variables('tag')]"
}
}
}

Просмотреть файл

@ -0,0 +1,15 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"registryName": {
"value": "mytaskrunregistry"
},
"taskRunName": {
"value": "myquickdockerbuildrun"
},
"sourceLocation": {
"value": "https://github.com/Azure-Samples/acr-build-helloworld-node.git"
}
}
}

Просмотреть файл

@ -0,0 +1,42 @@
# Quick Docker build using identity and credential
## Create a resource group
```bash
az group create \
-n mytaskrunrg \
-l westus
```
## Crate a Registry
```bash
az acr create \
-n myreg -g mytaskrunrg --sku Standard
```
## Create a User Identity
```bash
az identity create \
-g mytaskrunrg \
-n myquickdockerbuildrunwithidentity
```
## Add role assignment to the remote registry (You need fill the right information below)
```bash
az role assignment create --assignee "c5e2807e-4bbf-4faa-80fb-0a37f316113a" \
--scope "/subscriptions/f9d7ebed-adbd-4cb4-b973-aaf82c136138/resourceGroups/huanwutest/providers/Microsoft.ContainerRegistry/registries/huanwudftest2" \
--role acrpull
```
## Deploy a quick run
Fill the right credential azuredeploy.json
```bash
az group deployment create --resource-group "huanwutest" --template-file azuredeploy.json \
--parameters azuredeploy.parameters.json --parameters registryName="huanwudftest6" --parameters taskRunName="huanwudfwesttaskrun03" \
--parameters userAssignedIdentity="/subscriptions/f9d7ebed-adbd-4cb4-b973-aaf82c136138/resourcegroups/huanwudfwestgroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/huanwudfidentity"
```

Просмотреть файл

@ -0,0 +1,130 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"registryName": {
"type": "string",
"minLength": 5,
"maxLength": 50,
"metadata": {
"description": "Name of your Azure Container Registry"
}
},
"registrySku": {
"type": "string",
"metadata": {
"description": "Tier of your Azure Container Registry"
},
"defaultValue": "Basic",
"allowedValues": [
"Basic",
"Standard",
"Premium"
]
},
"registryAdminUserEnabled": {
"type": "bool",
"defaultValue": false,
"metadata": {
"description": "Enable admin user that have push / pull permission to the registry"
}
},
"taskRunName": {
"type": "string",
"minLength": 5,
"maxLength": 50,
"metadata": {
"description": "Name of your Task Run"
}
},
"userAssignedIdentity": {
"type": "string",
"metadata": {
"description": "The user assigned identity to be bound to the task run"
},
"defaultValue": ""
},
"sourceLocation": {
"type": "string",
"metadata": {
"description": "The location of the source to build the image"
}
},
"dockerFilePath": {
"type": "string",
"metadata": {
"description": "The relative path of the dockerfile in the source location"
},
"defaultValue": "Dockerfile"
}
},
"variables": {
"repository": "hello-world-node",
"tag": "parameters('taskRunName')",
"imageName": "[concat(variables('repository'), ':', parameters('taskRunName'))]",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"[parameters('userAssignedIdentity')]": {}
}
}
},
"resources": [
{
"type": "Microsoft.ContainerRegistry/registries/taskRuns/",
"name": "[concat(parameters('registryName'), '/', parameters('taskRunName'))]",
"location": "[parameters('location')]",
"apiVersion": "2019-06-01-preview",
"identity": "[if(not(empty(parameters('userAssignedIdentity'))), variables('identity'), '')]",
"properties": {
"runRequest": {
"type": "DockerBuildRequest",
"imageNames": [
"mytest2:123"
],
"sourceLocation": "https://github.com/huanwu/armtemplates.git",
"dockerFilePath": "Dockerfile-test",
"values": [],
"isPushEnabled": true,
"platform": {
"os": "linux",
"architecture": "amd64"
},
"credentials": {
"apiVersion": "2018-09-01",
"customRegistries": {
"huanwudftest2.azurecr-test.io":
{
"identity": "98d4358f-fd01-4255-aac4-7256f7eb5483"
}
},
"sourceRegistry": {
"loginMode": "Default"
}
}
}
}
}
],
"outputs": {
"registry": {
"type": "string",
"value": "[parameters('registryName')]"
},
"repository": {
"type": "string",
"value": "[variables('repository')]"
},
"tag": {
"type": "string",
"value": "[variables('tag')]"
}
}
}

Просмотреть файл

@ -0,0 +1,15 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"registryName": {
"value": "mytaskrunregistry"
},
"taskRunName": {
"value": "myquickdockerbuildrun"
},
"sourceLocation": {
"value": "https://github.com/Azure-Samples/acr-build-helloworld-node.git"
}
}
}

Просмотреть файл

@ -0,0 +1,35 @@
# Quick run
## Create a resource group
```bash
az group create \
-n mytaskrunrg \
-l westus
```
## Create a user assigned identity
identity=$(az identity create \
-g mytaskrunrg \
-n mytaskrunidentity \
--query 'id' \
-o tsv)
## Deploy a registry and a task run which is associated with the user assigned identity and run a multi-step task
```bash
registry=$(az group deployment create \
-g mytaskrunrg \
--template-file azuredeploy.json \
--parameters azuredeploy.parameters.json \
--parameters userAssignedIdentity=$identity \
--query 'properties.outputs.registry.value' \
-o tsv)
```
## Output the run log
```bash
az acr task list-runs -r $registry --query '[0].runId' -o tsv | xargs -I% az acr task logs -r $registry --run-id %
```

Просмотреть файл

@ -0,0 +1,118 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"registryName": {
"type": "string",
"minLength": 5,
"maxLength": 50,
"metadata": {
"description": "Name of your Azure Container Registry"
}
},
"registrySku": {
"type": "string",
"metadata": {
"description": "Tier of your Azure Container Registry"
},
"defaultValue": "Basic",
"allowedValues": [
"Basic",
"Standard",
"Premium"
]
},
"registryAdminUserEnabled": {
"type": "bool",
"defaultValue": false,
"metadata": {
"description": "Enable admin user that have push / pull permission to the registry"
}
},
"taskRunName": {
"type": "string",
"minLength": 5,
"maxLength": 50,
"metadata": {
"description": "Name of your Task Run"
}
},
"userAssignedIdentity": {
"type": "string",
"metadata": {
"description": "The user assigned identity to be bound to the task run"
},
"defaultValue": ""
},
"taskContent": {
"type": "string",
"metadata": {
"description": "The content of multi-step task template"
}
}
},
"variables": {
"encodedTaskContent": "[base64(parameters('taskContent'))]",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"[parameters('userAssignedIdentity')]": {}
}
}
},
"resources": [
{
"type": "Microsoft.ContainerRegistry/registries",
"name": "[parameters('registryName')]",
"apiVersion": "2017-10-01",
"location": "[parameters('location')]",
"comments": "Container registry for storing docker images",
"tags": {
"displayName": "Container Registry",
"container.registry": "[parameters('registryName')]"
},
"sku": {
"name": "[parameters('registrySku')]",
"tier": "[parameters('registrySku')]"
},
"properties": {
"adminUserEnabled": "[parameters('registryAdminUserEnabled')]"
},
"resources": [
{
"type": "taskRuns",
"name": "[parameters('taskRunName')]",
"location": "[parameters('location')]",
"apiVersion": "2019-06-01-preview",
"dependsOn": [
"[parameters('registryName')]"
],
"identity": "[if(not(empty(parameters('userAssignedIdentity'))), variables('identity'), '')]",
"properties": {
"runRequest": {
"type": "EncodedTaskRunRequest",
"encodedTaskContent": "[variables('encodedTaskContent')]",
"platform": {
"os": "linux",
"architecture": "amd64"
}
}
}
}
]
}
],
"outputs": {
"registry": {
"type": "string",
"value": "[parameters('registryName')]"
}
}
}

Просмотреть файл

@ -0,0 +1,15 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"registryName": {
"value": "mytaskrunregistry"
},
"taskRunName": {
"value": "myquickrun"
},
"taskContent": {
"value": "version: v1.0.0\nsteps:\n - cmd: microsoft/azure-cli az cloud register -n dogfood --endpoint-active-directory https://login.windows-ppe.net --endpoint-active-directory-graph-resource-id https://graph.ppe.windows.net/ --endpoint-active-directory-resource-id https://management.core.windows.net/ --endpoint-gallery https://current.gallery.azure-test.net/ --endpoint-management https://management.core.windows.net/ --endpoint-resource-manager https://api-dogfood.resources.windows-int.net/ --suffix-storage-endpoint core.test-cint.azure-test.net --suffix-acr-login-server-endpoint .azurecr-test.io --suffix-keyvault-dns .vault-int.azure-int.net\n - cmd: microsoft/azure-cli az cloud set -n dogfood\n - cmd: microsoft/azure-cli az login --identity\n - cmd: microsoft/azure-cli az account list -o table"
}
}
}

Просмотреть файл

@ -0,0 +1,18 @@
# Task run
## Create a resource group
```bash
az group create \
-n mytaskrunrg \
-l westus
```
## Deploy a task run, which will create the registry, task and schedule a run using the following command
```bash
az group deployment create \
--resource-group "mytaskrunrg" --template-file azuredeploy.json --parameters azuredeploy.parameters.json \
--parameters registryName="mytaskrunrg" --parameters --parameters taskName="huanwudfwesttask02" taskRunName="mytaskname"
```

Просмотреть файл

@ -0,0 +1,156 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"registryName": {
"type": "string",
"minLength": 5,
"maxLength": 50,
"metadata": {
"description": "Name of your Azure Container Registry"
}
},
"registrySku": {
"type": "string",
"metadata": {
"description": "Tier of your Azure Container Registry"
},
"defaultValue": "Basic",
"allowedValues": [
"Basic",
"Standard",
"Premium"
]
},
"registryAdminUserEnabled": {
"type": "bool",
"defaultValue": false,
"metadata": {
"description": "Enable admin user that have push / pull permission to the registry"
}
},
"taskName": {
"type": "string",
"minLength": 5,
"maxLength": 50,
"metadata": {
"description": "Name of your Task Run"
}
},
"taskRunName": {
"type": "string",
"minLength": 5,
"maxLength": 50,
"metadata": {
"description": "Name of your Task Run"
}
},
"userAssignedIdentity": {
"type": "string",
"metadata": {
"description": "The user assigned identity to be bound to the task run"
},
"defaultValue": ""
},
"taskContent": {
"type": "string",
"metadata": {
"description": "The content of multi-step task template"
},
"defaultValue": ""
},
"sourceLocation": {
"type": "string",
"metadata": {
"description": "The location of the source to build the image"
}
}
},
"variables": {
"repository": "hello-world-node",
"tag": "parameters('taskRunName')",
"imageName": "[concat(variables('repository'), ':', parameters('taskRunName'))]",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"[parameters('userAssignedIdentity')]": {}
}
}
},
"resources": [
{
"type": "Microsoft.ContainerRegistry/registries",
"apiVersion": "2017-10-01",
"name": "[parameters('registryName')]",
"location": "[parameters('location')]",
"comments": "Container registry for storing docker images",
"tags": {
"displayName": "Container Registry",
"container.registry": "[parameters('registryName')]"
},
"sku": {
"name": "Standard",
"tier": "Standard"
},
"properties": {
"adminUserEnabled": false
}
},
{
"type": "Microsoft.ContainerRegistry/registries/tasks/",
"name": "[concat(parameters('registryName'), '/', parameters('taskName'))]",
"location": "[parameters('location')]",
"apiVersion": "2019-06-01-preview",
"dependsOn": [
"[resourceId('Microsoft.ContainerRegistry/registries', parameters('registryName'))]"
],
"properties": {
"platform": {
"os": "Linux",
"architecture": "amd64"
},
"step": {
"type": "Docker",
"imageNames": [
"[variables('imageName')]"
],
"dockerFilePath": "Dockerfile",
"contextPath": "[parameters('sourceLocation')]",
"isPushEnabled": true,
"noCache": false
},
"trigger": {}
}
},
{
"type": "Microsoft.ContainerRegistry/registries/taskRuns/",
"name": "[concat(parameters('registryName'), '/', parameters('taskRunName'))]",
"location": "[parameters('location')]",
"apiVersion": "2019-06-01-preview",
"dependsOn": [
"[resourceId('Microsoft.ContainerRegistry/registries/tasks', parameters('registryName'), parameters('taskName'))]"
],
"identity": "[if(not(empty(parameters('userAssignedIdentity'))), variables('identity'), '')]",
"properties": {
"runRequest": {
"type": "TaskRunRequest",
"taskName": "[parameters('taskName')]",
"taskId": "[resourceId('Microsoft.ContainerRegistry/registries/tasks', parameters('registryName'), parameters('taskName'))]",
"values": [],
"platform": {
"os": "linux",
"architecture": "amd64"
},
"credentials": {}
}
}
}
]
}

Просмотреть файл

@ -0,0 +1,15 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"registryName": {
"value": "mytaskrunregistry"
},
"taskRunName": {
"value": "myquickdockerbuildrun"
},
"sourceLocation": {
"value": "https://github.com/Azure-Samples/acr-build-helloworld-node.git"
}
}
}