Michael
Michael

Reputation: 3641

Deploy helm chart from Azure Container Registry

I have a multistage pipeline with the following

Stage build:

  1. build docker image
  2. push image to ACR
  3. package helm chart
  4. push helm chart to ACR

Stage deployment:

  1. helm upgrade

Push helm chart to AKS:

 task: HelmDeploy@0
 displayName: 'helm publish'
 inputs:
   azureSubscriptionForACR: '$(azureSubscription)'
   azureResourceGroupForACR: '$(resourceGroup)'
   azureContainerRegistry: '$(containerRegistry)'
   command: 'save'
   arguments: '--app-version $(Version)'
   chartNameForACR: 'charts/$(imageRepository):$(Version)'
   chartPathForACR: $(chartPath)

Deploy helm chart to AKS:

  task: HelmDeploy@0
  inputs:
    connectionType: 'Kubernetes Service Connection'
    kubernetesServiceConnection: '$(kubernetesServiceConnection)'
    command: 'upgrade'
    chartType: 'Name'
    chartName: '$(containerRegistry)/charts/$(imageRepository):$(Version)'
    chartVersion: '$(Version)'
    azureSubscriptionForACR: '$(azureSubscription)'
    azureResourceGroupForACR: '$(resourceGroup)'
    azureContainerRegistry: '$(containerRegistry)'
    install: true
    releaseName: $(Version)

Error:

failed to download "<ACR>/charts/<repository>:0.9.26" at version "0.9.26" (hint: running `helm repo update` may help)

ACR: az acr repository show-manifests --name <org> --repository helm/charts/<repository> --detail

  {
    "changeableAttributes": {
      "deleteEnabled": true,
      "listEnabled": true,
      "readEnabled": true,
      "writeEnabled": true
    },
    "configMediaType": "application/vnd.cncf.helm.config.v1+json",
    "createdTime": "2021-02-02T11:54:54.1623765Z",
    "digest": "sha256:fe7924415c4e76df370630bbb0248c9296f27186742e9272eeb87b2322095c83",
    "imageSize": 3296,
    "lastUpdateTime": "2021-02-02T11:54:54.1623765Z",
    "mediaType": "application/vnd.oci.image.manifest.v1+json",
    "tags": [
      "0.9.26"
    ]
  }

What am I doing wrong? Do I have to export the helm chart from ACR before I can deploy it?

Upvotes: 1

Views: 3768

Answers (4)

Michael
Michael

Reputation: 3641

I never manage to find a fix for this, so I ended up with a another solution.

Instead of trying to publish the package to the registry, I published it as an artifact to the pipeline. In the step for deployment, I downloaded the artifact and applied it to kubernetes.

The benefits about doing it like this is that it is easy to rollback to a specific version, just be rerunning a specific deployment stage in the desired pipeline.

Sudo pipeline:

Stage: build
  build
  test
  generate image
  publish image to registry
  generate helm package (setting helm version and image tag)
  publish package as azure artifacts
Stage: Test deployment
  download artifacts
  apply helm package
Stage: Prod deployment
  download artifacts
  apply helm package

Upvotes: 0

JMag
JMag

Reputation: 71

The answer from @sshepel actually helped somewhat, you need to login to the registry before being able to pull. However, it is sufficient with a simple AzureCLI login.

    - task: AzureCLI@2
      displayName: Login to Azure Container Registry
      inputs:
        azureSubscription: <Azure Resource Manager service connection to your subscription and resource group>
        scriptType: bash
        scriptLocation: inlineScript
        inlineScript: |
          az acr login --name <container registry name>.azurecr.io

After that it worked perfectly with the undocumented HelmDeploy task.

Upvotes: 4

sshepel
sshepel

Reputation: 890

I have faced with the same issue, and only option that helped me is to add registry login step before helm upgrade.

- task: Bash@3
  name: registryLogin
  displayName: Login registry
  env:
   SERVICE_PRINCIPAL_APPLICATION_ID: <SPN_APP_ID>
   SERVICE_PRINCIPAL_APPLICATION_KEY: <SPN_APP_KEY>
   HELM_EXPERIMENTAL_OCI: 1 # just in case...
  input:
   targetType: inline
   script:
     echo $SERVICE_PRINCIPAL_APPLICATION_KEY | helm registry login <acr_name>.azurecr.io --username $SERVICE_PRINCIPAL_APPLICATION_ID --password-stdin

Upvotes: 0

Cece Dong - MSFT
Cece Dong - MSFT

Reputation: 31075

The syntax of helm upgrade should be like:

- task: HelmDeploy@0
  displayName: 'helm upgrade'
  inputs:
    connectionType: 'Kubernetes Service Connection'
    kubernetesServiceConnection: connection
    command: upgrade
    chartName: '$(name)'
    chartVersion: '$(Version)'
    releaseName: azuredevopsdemo

Try to replace the chartName value to charts/$(imageRepository).

Upvotes: -1

Related Questions