LoginSignup
1
0

More than 3 years have passed since last update.

[Microsoft] Azure Pipelines (VSTS) AgentをDockerあるいはAzure Container Instanceで動かす

Posted at

Azure PipelinesエージェントをDockerで動かします。

Azure Pipelinesとは

Jenkinsのようなビルド/デプロイを行うサービスです。

Azure Pipelinesエージェントとは

Azure Pipelinesから指示を受け、実際にビルドやデプロイの処理が動くデーモンです。

Azure Pipelinesに無料版が付いてきますが、毎月の実行時間に上限があります。
自前でエージェントを用意することで、上限時間なく利用できます。

あらかじめ必要なもの

組織名

Azure DevOpsのURLを見てください。https://dev.azure.com/hogehoge のようになっていると思います。この hogehoge の部分です。

Personal Access Token

エージェントがAzure DevOpsへ接続するときに必要なものです。

こちらにPersonal Access Tokenの取得方法があります。

スコープとしては、以下を設定します。

  • Agent Pools
    • Read & manage
  • Code
    • Read
  • Connected server
    • Connected server
  • Deployment Groupos
    • Read & manage

Dockerで動かす

Micorosoft公式イメージはDeprecatedになっているので、拙いながらも作成しました。
sengokyu/azure-pipelines-agent:latest
いつものようにpullしてください。

docker pull sengokyu/azure-pipelines-agent

実行時に、あらかじめ用意しておいた組織名とPersonal Access Tokenを環境変数として与えてください。

変数名
ORG 組織名
TOKEN Personal Access Token
docker run -d -e TOKEN=${PAT} -e ORG=${ORG} sengokyu/azure-pipelines-agent

Azure Container Instanceで動かす

ARMテンプレートを使用してデプロイします。

ARMテンプレートのリソース定義部分です。全体はGitHubに置いてます。

template.json
  "resources": [
    {
      "name": "[parameters('containerGroupName')]",
      "type": "Microsoft.ContainerInstance/containerGroups",
      "apiVersion": "2019-12-01",
      "location": "[resourceGroup().location]",
      "properties": {
        "containers": [
          {
            "name": "[parameters('agent')]",
            "properties": {
              "image": "[variables('containerImage')]",
              "resources": {
                "requests": {
                  "cpu": "[parameters('cpu')]",
                  "memoryInGb": "[parameters('memoryInGb')]"
                }
              },
              "environmentVariables": [
                { "name": "TOKEN", "secureValue": "[parameters('token')]" },
                { "name": "ORG", "value": "[parameters('org')]" },
                { "name": "POOL", "value": "[parameters('pool')]" },
                { "name": "AGENT", "value": "[parameters('agent')]" }
              ]
            }
          }
        ],
        "osType": "Linux",
        "restartPolicy": "Never"
      }
    }
  ]

各パラメータを記載したファイルを作成します。

parameters.json
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "containerGroupName": { "value": "vsts-agent" },
    "pool": { "value": "Default" },
    "agent": { "value": "vsts-agent-on-aci" },
    "token": { "value": "YourPersonalAccessToken" },
    "org": { "value": "YourOrganizationName" },
    "cpu": { "value": 4 },
    "memoryInGb": { "value": 8 }
  }
}

azコマンドを実行します。

az deployment group create -f template.json -p @parameters.json -g ResourceGroupName
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0