Friday, December 1, 2017

Azure Container Instance (3): Introducing ACI gitRepo Volume

A new type of volume named gitRepo volume was supported in Azure Container Instance since version 2017-12-01-preview.

What is gitRepo volume?

A gitRepo volume mounts an empty directory and clones a git repository into it for your container group to use.

When to use gitRepo volume?

The gitRepo is very useful when we are using GitHub as the source version control tool and we’d like to have containers to work on the source code, such as build and deploy automatically.

How to use gitRepo volume?

Firstly, a gitRepo object is added into the volumes array of the container group, and then a volume mount is added into the volumeMounts of a container. The name of the volume mount should match the name of the volume.

The following is an example container group definition in JSON:

{
  "properties": {
    "containers": [
      {
        "name": "demo1",
        "properties": {
          "command": [
            "bin/bash",
            "-c",
            "cp -R /mnt/gitrepos /mnt/azurefile && while sleep 50000; do echo sleep; done"
          ],
          "image": "nginx",
          "ports": [
            {
              "port": 80
            }
          ],
          "resources": {
            "requests": {
              "cpu": 1,
              "memoryInGb": 1.5
            }
          },
          "volumeMounts": [
            {
              "name": "gitrepo",
              "mountPath": "/mnt/gitrepos",
              "readOnly": false
            },
            {
              "name": "azurefile",
              "mountPath": "/mnt/azurefile",
              "readOnly": false
            }
          ]
        }
      }
    ],
    "volumes": [
      {
        "name": "gitrepo",
        "gitRepo": {
          "repository": "https://github.com/Azure-Samples/aci-helloworld.git"
        }
      },
      {
        "name": "azurefile",
        "azureFile": {
          "shareName": "<YourAzureFileShare>",
          "storageAccountName": "<YourAzureStorageAccountName>",
          "storageAccountKey": "<YouAzureStorageAccountKey>"
        }
      }
    ],
    "osType": "Linux",
    "ipAddress": {
      "ports": [
        {
          "protocol": "TCP",
          "port": 80
        }
      ],
      "type": "Public"
    }
  },
  "location": "westus"
}

In the JSON definition above, the source code files in GitHub reprository https://github.com/Azure-Samples/aci-helloworld are cloned to the path “/mnt/gitrepos”. Since we copy the directory “/mnt/gitrepos” to “/mnt/azurefile”, which is the mounted path of Azure file share. You may find all source code in the GitHub are uploaded to your Azure file storage if you check on your Azure portal.

The sample above just uploads source code in GitHub to Azure file storage. In your scenario you may do anything on the GitHub source code as you like, such as building and deploying code automatically.

Besides property “repository”, a gitRepo object can also have two properties: One is “directory”, which is target directory name. It must not contain or start with '..'.  If '.' is supplied, the volume directory will be the git repository.  Otherwise, if specified the volume will contain the git repository in the subdirectory with the given name. The other is “revision”, which is the commit hash for the specified revision.

No comments:

Post a Comment

Azure Container Instance (5): Building HTTPS Websites

HTTPS websites are more and more popular recently. Now you can also build websites with HTTPS connections via Azure Container Instance, w...