ADO パイプライン ドキュメントといくつかの SO の質問/回答に基づいて、1 つのステップでイメージを構築し、別のステップで ACR にプッシュすることができるはずです。
ビルドステップで ACR URI プレフィックスを取得するイメージ名である「***/」プレフィックスの問題に遭遇しています。このSO 回答 (およびその他) のリンクです。
これを処理する必要がありますが、プッシュ ジョブが画像を見つけられないというエラーが引き続き発生します。
以下のパイプラインの短いバージョン (補足: イメージをアーティファクトとして公開し、後の複数の段階でダウンロードする必要があります。何度もビルドしたくありません)。
- ビルドステップが機能します
- イメージの保存ステップでは、'myacrregistry.azurecr.io' というプレフィックスが付いているイメージが検出されます。
- アーティファクトの公開ステップが機能する
- 次のステージの Load image ステップは機能します
- イメージのプッシュ ステップは失敗し、次の出力が表示されます。
/usr/bin/docker images
/usr/bin/docker push ***/myclient:latest
REPOSITORY TAG IMAGE ID CREATED SIZE
***/myclient latest cb770a5b04ec 50 seconds ago 130MB
ubuntu 20.04 d13c942271d6 13 ... // removed lines
The push refers to repository [***/myclient]
An image does not exist locally with the tag: ***/myclient
##[error]An image does not exist locally with the tag: ***/myclient
##[error]The process '/usr/bin/docker' failed with exit code 1
私はこれを試しました
- Docker@2 ビルド タスク (以下)
- docker build を実行するスクリプトを使用した Bash@3 タスク ... イメージの前に ACR_URL を付けない
- docker build を実行するスクリプトを含む Bash@3 タスク ... およびイメージの前に ACR_URL を付ける
- イメージ プレフィックスを手動で指定する Docker@1 ビルド タスク
- myacrregistry.azurecr.io 文字列をプレフィックスとして使用する
- サービス接続リソース ID をプレフィックスとして使用する (多くの SO 投稿の 1 つで見た)
- サービス接続名をプレフィックスとして使用する
すべて同じ結果です。画像を保存しても画像を見つけるのに問題はありません。画像の読み込みは正常に行われます。プッシュ (試行) の直前に画像リストに画像が表示されていても、プッシュは失敗します。
プッシュ タスクの場合、イメージ名にプレフィックスを指定していないことに注意してください (試してみましたが、機能しません)。そのため、Docker@2 プッシュ タスクは、プレフィックスが何らかの文字列であると想定する必要があります。おそらく、その文字列は、イメージを構築するときに提供する ACR_URI ではないでしょうか? 残念ながら、プッシュステップで「***」の背後にあるものを確認する方法がわかりません。
何か案は?
編集: 以下のパイプラインは、ビルド ステップとプッシュ ステップが同じステージにある場合に機能します。(もちろん、保存、公開、読み込みは冗長です)
パイプライン YAML:
stages:
- stage: BuildAndTest
jobs:
- job: BuildImageAndRunTestsJob
steps:
- task: Docker@2
inputs:
command: build
repository: $(imageRepository)
containerRegistry: $(dockerRegistryServiceConnectionTest)
dockerfile: '$(Build.SourcesDirectory)/PROJECT_FOLDER/Dockerfile'
buildContext: '$(Build.SourcesDirectory)'
tags: $(dockerImageTag)
arguments: '--progress=plain' # Print output of dockerfile commands to pipeline shell
- task: Docker@0
displayName: Save docker image
inputs:
containerRegistryType: 'Azure Container Registry'
action: 'Run a Docker command'
customCommand: 'image save myacrregistry.azurecr.io/$(imageRepository):$(dockerImageTag) -o $(Build.ArtifactStagingDirectory)/client-image.tar'
# Publish the docker image artifact as output of this stage
- publish: $(Build.ArtifactStagingDirectory)
artifact: docker-images
- stage: BuildAndPushImageToACR_Develop
dependsOn: BuildAndTest
condition: and(succeeded('BuildAndTest'), in(variables['Build.SourceBranchName'], 'develop'))
jobs:
- job: LoadImageAndPushJob
steps:
# Download the docker image artifact to use in this stage
- download: current
artifact: docker-images
# Load the docker image from file
- task: Docker@0
displayName: Load docker image
inputs:
containerRegistryType: 'Azure Container Registry'
action: 'Run a Docker command'
customCommand: 'load --input $(Pipeline.Workspace)/docker-images/client-image.tar'
# Push the image to ACR
- task: Docker@2
displayName: Docker push image
inputs:
containerRegistry: $(dockerRegistryServiceConnectionTest)
repository: $(imageRepository)
command: push
tags: $(dockerImageTag)