构建带有构建参数的停靠机映像并将其从DevOps推送到ACR

构建带有构建参数的停靠机映像并将其从DevOps推送到ACR

本文介绍了构建带有构建参数的停靠机映像并将其从DevOps推送到ACR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Azure DevOps管道中构建停靠器映像,然后希望将其推送到Azure容器注册表。注册表已创建,我已将DevOps配置为使用它,buildAndPush Docker task也可以工作。

但是,由于Docker构建可以参数化,我希望将参数传递给它并使用buildAndPushDocker任务。所以我决定分两步来做,一步是建,另一步是推。这边:

# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger: none

resources:
- repo: self

variables:
  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: 'aaaa-aaaa-aaaa-aaaa-aaaaa'
  imageRepository: 'ubuntu-qt'
  containerRegistry: 'myregistry.azurecr.io'
  dockerfilePath: '$(Build.SourcesDirectory)/docker-qt-build/Dockerfile'

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

stages:
- stage: BuildPush
  displayName: Build and push
  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: Docker@2
      displayName: Build ubuntu with qt 5.12.4 installed
      inputs:
        command: build
        repository: $(imageRepository)
        dockerfile: $(dockerfilePath)
        tags: 5.12.4
        arguments: '--build-arg ubuntu_version=18.04 --build-arg qt_version_major=5.12 --build-arg qt_version_full=5.12.4'
    - task: Docker@2
      displayName: Push ubuntu with qt 5.12.4 installed
      inputs:
        command: push
        repository: $(imageRepository)
        containerRegistry: $(dockerRegistryServiceConnection)
        tags: myregistry.azurecr.io/ubuntu-qt:5.12.4

即使构建任务运行良好,似乎也找不到要推送到注册表的镜像:

Starting: Push ubuntu with qt 5.12.4 installed
==============================================================================
Task         : Docker
Description  : Build or push Docker images, login or logout, or run a Docker command
Version      : 2.170.2
Author       : Microsoft Corporation
Help         : https://aka.ms/azpipes-docker-tsg
==============================================================================
/usr/bin/docker images
/usr/bin/docker push ***/ubuntu-qt:***/ubuntu-qt:5.12.4
invalid reference format
##[error]invalid reference format
##[error]The process '/usr/bin/docker' failed with exit code 1
REPOSITORY                                           TAG                 IMAGE ID            CREATED             SIZE
ubuntu-qt                                            5.12.4              e5aeb1027823        2 seconds ago       6.64GB
ubuntu                                               18.04               2eb2d388e1a2        12 days ago         64.2MB
node                                                 10                  5010eb9431a5        2 weeks ago         911MB
node                                                 12                  dfbb88cfffc8        2 weeks ago         918MB
buildpack-deps                                       stretch             42d486287f16        2 weeks ago         835MB
debian                                               9                   5df937d2ac6c        2 weeks ago         101MB
debian                                               8                   72f79d3cb645        2 weeks ago         129MB
node                                                 10-alpine           8e473595b853        2 weeks ago         83.5MB
node                                                 12-alpine           057fa4cc38c2        5 weeks ago         89.3MB
jekyll/builder                                       latest              12489946feab        7 weeks ago         674MB
alpine                                               3.9                 78a2ce922f86        3 months ago        5.55MB
alpine                                               3.10                be4e4bea2c2e        3 months ago        5.58MB
alpine                                               3.8                 c8bccc0af957        6 months ago        4.41MB
ubuntu                                               14.04               6e4f1fe62ff1        7 months ago        197MB
alpine                                               3.7                 6d1ef012b567        17 months ago       4.21MB
mcr.microsoft.com/azure-pipelines/node8-typescript   latest              9a948d360778        22 months ago       595MB

    Finishing: Push ubuntu with qt 5.12.4 installed

推荐答案

在构建步骤中也指定containerRegistry,并在推送步骤中使用5.12.4FORtags(而不是myregistry.azurecr.io/ubuntu-qt:5.12.4)。

这样:

steps:
- task: Docker@2
  displayName: Build ubuntu with qt 5.12.4 installed
  inputs:
    command: build
    repository: $(imageRepository)
    containerRegistry: $(dockerRegistryServiceConnection)
    dockerfile: $(dockerfilePath)
    tags: 5.12.4
    arguments: '--build-arg ubuntu_version=18.04 --build-arg qt_version_major=5.12 --build-arg qt_version_full=5.12.4'
- task: Docker@2
  displayName: Push ubuntu with qt 5.12.4 installed
  inputs:
    command: push
    repository: $(imageRepository)
    containerRegistry: $(dockerRegistryServiceConnection)
    tags: 5.12.4

这篇关于构建带有构建参数的停靠机映像并将其从DevOps推送到ACR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 00:16