將 Docker Scout 與 Microsoft Azure DevOps Pipelines 整合
以下範例在連線到 Azure DevOps 的存放庫中執行,其中包含 Docker 映像檔的定義和內容。 由對主要分支的提交觸發,管線會建置映像檔並使用 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: |
# Install the Docker Scout CLI
curl -sSfL https://raw.githubusercontent.com/docker/scout-cli/main/install.sh | sh -s --
# Login to Docker Hub required for Docker Scout CLI
echo $(DOCKER_HUB_PAT) | docker login -u $(DOCKER_HUB_USER) --password-stdin
# Get a CVE report for the built image and fail the pipeline when critical or high CVEs are detected
docker scout cves $(image):$(tag) --exit-code --only-severity critical,high
這會建立前面提到的流程。 它使用簽出的 Dockerfile 建置和標記映像檔,下載 Docker Scout CLI,然後針對新標籤執行 cves
命令以產生 CVE 報告。 它僅顯示嚴重或高嚴重性漏洞。