Docker Scout를 Microsoft Azure DevOps Pipelines와 통합하기

Docker Scout를 Microsoft Azure DevOps Pipelines와 통합하기

다음 예시는 Docker 이미지 정의와 내용을 포함한 Azure DevOps 연결 저장소에서 실행돼요. main 브랜치에 대한 커밋으로 트리거된 파이프라인은 이미지를 빌드하고 Docker Scout를 사용해 CVE 보고서를 만들어요.

먼저 나머지 워크플로를 설정하고 모든 파이프라인 단계에서 사용할 수 있는 변수를 설정하세요. azure-pipelines.yml 파일에 다음을 추가하세요.

trigger:
  - main

resources:
  - repo: self

variables:
  tag: "$(Build.BuildId)"
  image: "vonwig/nodejs-service"

이것은 워크플로가 애플리케이션용 특정 컨테이너 이미지를 사용하고 각각의 새 이미지 빌드를 빌드 ID로 태그하도록 설정해요.

YAML 파일에 다음을 추가하세요.

stages:
  - stage: Build
    displayName: Build image
    jobs:
      - job: Build
        displayName: Build
        pool:
          vmImage: ubuntu-latest
        steps:
          - task: Docker@2
            displayName: Build an image
            inputs:
              command: build
              dockerfile: "$(Build.SourcesDirectory)/Dockerfile"
              repository: $(image)
              tags: |
                $(tag)
          - task: CmdLine@2
            displayName: Find CVEs on image
            inputs:
              script: |
                # Docker Scout CLI 설치 (Install the Docker Scout CLI)
                curl -sSfL https://raw.githubusercontent.com/docker/scout-cli/main/install.sh | sh -s --
                # Docker Scout CLI에 필요한 Docker Hub 로그인 (Login to Docker Hub required for Docker Scout CLI)
                echo $(DOCKER_HUB_PAT) | docker login -u $(DOCKER_HUB_USER) --password-stdin
                # 빌드된 이미지에 대한 CVE 보고서를 얻고 critical/high CVE가 감지되면 파이프라인 실패
                docker scout cves $(image):$(tag) --exit-code --only-severity critical,high

이것은 앞서 언급한 흐름을 만들어요. 체크아웃된 Dockerfile로 이미지를 빌드·태그하고, Docker Scout CLI를 다운로드한 다음 새 태그에 대해 cves 명령을 실행해 CVE 보고서를 생성해요. critical 또는 high 심각도 취약점만 보여 줘요.