From 968c1344bac7bf282aebba105d28dcad8b2e1dcf Mon Sep 17 00:00:00 2001 From: Sajay Antony <1821104+sajayantony@users.noreply.github.com> Date: Tue, 19 Nov 2019 16:34:56 -0800 Subject: [PATCH] Removed registry deployment from taskruns (#309) * Add simple examples for docker build on existing registry Signed-off-by: Sajay Antony * Moved to tasks2 * move tasks * Adding to doc Signed-off-by: Sajay Antony --- docs/.vuepress/config.js | 2 +- docs/tasks/run-as-deployment/README.md | 13 +++ .../README.md | 22 ++++ .../azuredeploy.json | 104 ++++++++++++++++++ .../azuredeploy.parameters.json | 18 +++ .../quickdockerbuild/azuredeploy.json | 33 +++--- .../azuredeploy.parameters.json | 29 ++--- .../azuredeploy.json | 2 +- 8 files changed, 195 insertions(+), 28 deletions(-) create mode 100644 docs/tasks/run-as-deployment/README.md create mode 100644 docs/tasks/run-as-deployment/quickdockerbuild-on-existing-registry/README.md create mode 100644 docs/tasks/run-as-deployment/quickdockerbuild-on-existing-registry/azuredeploy.json create mode 100644 docs/tasks/run-as-deployment/quickdockerbuild-on-existing-registry/azuredeploy.parameters.json diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 8879d25..b748ad4 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -28,7 +28,7 @@ module.exports = { { title: 'Tasks', collapsible: true, - children: ['/tasks/container-registry-tasks-overview'] + children: ['/tasks/container-registry-tasks-overview', '/tasks/run-as-deployment/'] }, { title: 'Authentication', diff --git a/docs/tasks/run-as-deployment/README.md b/docs/tasks/run-as-deployment/README.md new file mode 100644 index 0000000..e9e78ba --- /dev/null +++ b/docs/tasks/run-as-deployment/README.md @@ -0,0 +1,13 @@ +--- +title: Deploy with ARM templates +--- + +# Running ACR Tasks as a deployment + +The following set of samples show how to use an ARM template to execute various Task workflows. + +1. [Deploy a docker build on an existing registry](https://github.com/azure/acr/tasks/run-as-deployment/quickdockerbuild-on-existing-registry) +1. [Create a Registry and perform a docker build from a GitHub repository](https://github.com/azure/acr/tasks/run-as-deployment/quickdockerbuild) +1. [Create a Registry and perform a docker build from a GitHub repository with a Managed Identity](https://github.com/azure/acr/tasks/run-as-deployment/quickdockerbuild) +1. [Create a registry and schedule a quick task with task definition as an argument](https://github.com/azure/acr/tasks/run-as-deployment/quickrun) +1. [Create a registry and schedule a predefined task](https://github.com/azure/acr/tasks/run-as-deployment/taskrun) diff --git a/docs/tasks/run-as-deployment/quickdockerbuild-on-existing-registry/README.md b/docs/tasks/run-as-deployment/quickdockerbuild-on-existing-registry/README.md new file mode 100644 index 0000000..652f1e9 --- /dev/null +++ b/docs/tasks/run-as-deployment/quickdockerbuild-on-existing-registry/README.md @@ -0,0 +1,22 @@ +# Quick docker build on an existing registry + +The sample shows how to schedule a deployment which will perform a quick docker build on an existing registry from a source located in a GitHub repository. The tag of the image is derived from the `taskRunName` provided during deployment. + +## Deploy the Task + +```bash +registry=$(az group deployment create \ + -g mytaskrunrg \ + --template-file azuredeploy.json \ + --parameters azuredeploy.parameters.json \ + --parameters taskRunName=mytaskrunwithidentity \ + --query 'properties.outputs.registry.value' \ + -o tsv) +``` +## + +```bash +export registry=mytaskrunregistry +export repository=helloworld-node +az acr repository show-tags -n $registry --repository $repository --detail -o table +``` \ No newline at end of file diff --git a/docs/tasks/run-as-deployment/quickdockerbuild-on-existing-registry/azuredeploy.json b/docs/tasks/run-as-deployment/quickdockerbuild-on-existing-registry/azuredeploy.json new file mode 100644 index 0000000..c561a6a --- /dev/null +++ b/docs/tasks/run-as-deployment/quickdockerbuild-on-existing-registry/azuredeploy.json @@ -0,0 +1,104 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-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" + } + }, + "taskRunName": { + "type": "string", + "minLength": 5, + "maxLength": 50, + "metadata": { + "description": "Name of your Task Run and tag generated" + } + }, + "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" + }, + "repository": { + "type": "string", + "metadata": { + "description": "Repository name for the the build output" + } + } + }, + "variables": { + "tag": "parameters('taskRunName')", + "imageName": "[concat(parameters('repository'), ':', parameters('taskRunName'))]", + "identity": { + "type": "UserAssigned", + "userAssignedIdentities": { + "[parameters('userAssignedIdentity')]": { + } + } + } + }, + "resources": [ + { + "type": "Microsoft.ContainerRegistry/registries/taskRuns", + "apiVersion": "2019-06-01-preview", + "name": "[concat(parameters('registryName'), '/', parameters('taskRunName'))]", + "location": "[parameters('location')]", + "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": "[parameters('repository')]" + }, + "tag": { + "type": "string", + "value": "[variables('tag')]" + } + } +} \ No newline at end of file diff --git a/docs/tasks/run-as-deployment/quickdockerbuild-on-existing-registry/azuredeploy.parameters.json b/docs/tasks/run-as-deployment/quickdockerbuild-on-existing-registry/azuredeploy.parameters.json new file mode 100644 index 0000000..a2a13a7 --- /dev/null +++ b/docs/tasks/run-as-deployment/quickdockerbuild-on-existing-registry/azuredeploy.parameters.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "registryName": { + "value": "mytaskrunregistry" + }, + "taskRunName": { + "value": "myquickdockerbuildrun" + }, + "repository": { + "value": "helloworld-node" + }, + "sourceLocation": { + "value": "https://github.com/Azure-Samples/acr-build-helloworld-node.git" + } + } +} \ No newline at end of file diff --git a/docs/tasks/run-as-deployment/quickdockerbuild/azuredeploy.json b/docs/tasks/run-as-deployment/quickdockerbuild/azuredeploy.json index e660758..eb0937d 100644 --- a/docs/tasks/run-as-deployment/quickdockerbuild/azuredeploy.json +++ b/docs/tasks/run-as-deployment/quickdockerbuild/azuredeploy.json @@ -1,5 +1,5 @@ { - "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "location": { @@ -41,7 +41,7 @@ "minLength": 5, "maxLength": 50, "metadata": { - "description": "Name of your Task Run" + "description": "Name of your Task Run and tag generated" } }, "userAssignedIdentity": { @@ -63,19 +63,26 @@ "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')]": {} + }, + "repository": { + "type": "string", + "metadata": { + "description": "Repository name for the the build output" } } }, + "variables": { + "tag": "parameters('taskRunName')", + "imageName": "[concat(parameters('repository'), ':', parameters('taskRunName'))]", + "identity": { + "type": "UserAssigned", + "userAssignedIdentities": { + "[parameters('userAssignedIdentity')]": { + } + } + } + }, + "resources": [ { "type": "Microsoft.ContainerRegistry/registries", @@ -130,7 +137,7 @@ }, "repository": { "type": "string", - "value": "[variables('repository')]" + "value": "[parameters('repository')]" }, "tag": { "type": "string", diff --git a/docs/tasks/run-as-deployment/quickdockerbuild/azuredeploy.parameters.json b/docs/tasks/run-as-deployment/quickdockerbuild/azuredeploy.parameters.json index 8751ca5..a2a13a7 100644 --- a/docs/tasks/run-as-deployment/quickdockerbuild/azuredeploy.parameters.json +++ b/docs/tasks/run-as-deployment/quickdockerbuild/azuredeploy.parameters.json @@ -1,15 +1,18 @@ { - "$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" - } + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "registryName": { + "value": "mytaskrunregistry" + }, + "taskRunName": { + "value": "myquickdockerbuildrun" + }, + "repository": { + "value": "helloworld-node" + }, + "sourceLocation": { + "value": "https://github.com/Azure-Samples/acr-build-helloworld-node.git" } - } \ No newline at end of file + } +} \ No newline at end of file diff --git a/docs/tasks/run-as-deployment/quickdockerbuildwithidentity/azuredeploy.json b/docs/tasks/run-as-deployment/quickdockerbuildwithidentity/azuredeploy.json index 94d3bfa..41e98b0 100644 --- a/docs/tasks/run-as-deployment/quickdockerbuildwithidentity/azuredeploy.json +++ b/docs/tasks/run-as-deployment/quickdockerbuildwithidentity/azuredeploy.json @@ -1,5 +1,5 @@ { - "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "location": {