skip to Main Content

How can I give a containerRegistry to a DevcontainersCi task in an Azure DevOps YAML Pipeline, like in a Docker@2 task?

Currently pushing from this task fails, apparently due to missing authentication (understandable).

The property containerRegistry like in the Docker@2 task is not accepted by the DevcontainersCi task task.

Or is there another task which allows me to achieve the same, which is to also get the features from the devcontainer already included?

2

Answers


  1. The DevcontainersCi task is an extension developed by Dev Containers. It doesn’t support the service connection (containerRegistry ).

    Currently pushing from this task fails, apparently due to missing authentication (understandable).

    In the extension introduce, it provides an example which shows logging in to an Azure Container Registry instance, and then building and running the dev container with the devcontainer-build-run action. You can follow the example to provide the authentication.

    trigger:
    - main
    
    pool:
      vmImage: ubuntu-latest
    
    steps:
    # Replace the username and registry name here with your own details
    # This step also uses an ACR_TOKEN specified as a secret variable
    - script: |
        docker login -u test -p $ACR_TOKEN yourregistry.azurecr.io
      displayName: 'Log in to Container Registry'
      env:
        ACR_TOKEN: $(ACR_TOKEN)
    
    - task: DevcontainersCi@0
      inputs:
        # Change this to point to your image name
        imageName: 'yourregistry.azurecr.io/example-dev-container'
        # Change this to be your CI task/script
        runCmd: 'make ci-build'
        # sourceBranchFilterForPush allows you to limit which branch's builds
        # are pushed to the registry
        sourceBranchFilterForPush: refs/heads/main
    

    If you need more help when using the extension, you can create issues here.

    Login or Signup to reply.
  2. Based on the documentation of the "Dev Container Build and Run Task" extension, the DevcontainersCi@0 task does not provide an input to receive the Docker Registry service connection.

    To connect with a Docker registry, you must add a step before the DevcontainersCi@0 task to login the registry at first.

    1. If you have an existing Docker Registry service connection set to connect with the target Docker registry, you can use a Docker@2 task to run the login with the Docker Registry service connection.

      steps:
      - task: Docker@2
        displayName: 'Docker Login'
        inputs:
          containerRegistry: 'Name of the Docker Registry service connection' 
          command: login
      
      - task: DevcontainersCi@0
        displayName: 'Build and Run Dev Container'
        inputs:
          imageName: registry/imageName
          imageTag: 'tag1, tag2'
          push: filter
          sourceBranchFilterForPush: refs/heads/main
          noCache: false
      
    2. If you do not have a Docker Registry service connection, you can create one for use. Or as @Miao Tian-MSFT suggested, you can use a script task to directly run the "docker login" command with your username and password.

    If using the script task to directly run the "docker login" command, you need to provide and store your username and password as variables in the pipeline. For the security of your sensitive information, I recommended you use the method #1 that login to the Docker registry with a Docker Registry service connection.


    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search