DEV Community

Eliise
Eliise

Posted on

Dockerizing DevOps V2 - AzDO container jobs

This is a follow up to my previous blog post of Dockerizing DevOps, because I've discovered a better way to run containers within AzDO by using container jobs with step targeting:

trigger: none

resources:
  containers:
    - container: devcontainer
      image: $(imageRepository):$(Build.BuildId)
      endpoint: demoacr
      options: --name devcontainer

variables:
  - name: dockerRegistryServiceConnection
    value: "demoserviceconnection"
  - name: imageRepository
    value: "demoacr.azurecr.io/foo-devcontainer"

stages:
  - stage: BUILD
    displayName: Docker build & push
    jobs:
      - job:
        displayName: Devcontainer build & push
        steps:
          - task: Docker@2
            displayName: Login to ACR
            inputs:
              command: login
              containerRegistry: $(dockerRegistryServiceConnection)

          - task: Docker@2
            displayName: Build and push an image to container registry
            inputs:
              command: buildAndPush
              repository: $(imageRepository)
              dockerfile: ".devcontainer/Dockerfile"
              containerRegistry: $(dockerRegistryServiceConnection)
              tags: |
                $(Build.BuildId)
                latest

  - stage: TEST
    displayName: Run tests and linters
    dependsOn:
      - BUILD
    jobs:
      - job: Tests
        steps:
          - task: Docker@2
            displayName: Login to ACR
            inputs:
              command: login
              containerRegistry: $(dockerRegistryServiceConnection)

          - script: |
              make lint
            displayName: "Lint"
            target: devcontainer

          - script: |
              make test
            displayName: "Run all tests"
            target: devcontainer

Enter fullscreen mode Exit fullscreen mode

Top comments (0)