在 Azure DevOps 中,我有我的管道来创建容器并将其部署在 Azure 容器注册表中,并且工作正常。在这个过程中我使用 qetza.replacetokens
来替换 DOCKERFILE 中的一些标记
trigger:
- main
resources:
- repo: self
variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: 'myconnection'
imageRepository: '$(project)'
containerRegistry: $(ACRLoginServer)
dockerfilePath: '$(Build.SourcesDirectory)/DOCKERFILE'
tag: '$(Build.BuildId)'
# Agent VM image name
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Check
condition: eq('${{ variables.imageRepository }}', '')
steps:
- script: |
echo '##[error] The imageRepository must have a value!'
echo '##[error] --------------------------------------'
echo '##[error] For the name of the repository, you can use only numbers and letters in lowercase.\nNo spaces or spacial chararters are allowed.'
exit 1
- job: Build
condition: not(eq('${{ variables.imageRepository }}', ''))
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: qetza.replacetokens.replacetokens-task.replacetokens@3
displayName: 'Replace tokens'
inputs:
targetFiles: '**/DOCKERFILE'
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
arguments: '--build-arg github_pat="$(github_pat)" '
tags: |
latest
在这之前,我已经为 Azure 容器注册表创建了一个 Service Connection
。
所以,我在 Azure Container Registry 中创建了一个新的基础镜像,所有的新项目都基于它。我面临的问题是我不知道如何将连接从 DevOps 传递到 ACR 到 DOCKERFILE,我收到此错误
DOCKERFILE 就是这样
# OS & Base R Set Up
FROM #{dockerRegistryServiceConnection}/cellorbase
RUN apt-get update && apt-get install -y libicu-dev make pandoc pandoc-citeproc && rm -rf /var/lib/apt/lists/*
RUN echo "options(repos = c(CRAN = 'https://cran.rstudio.com/'), download.file.method = 'libcurl')" >> /usr/local/lib/R/etc/Rprofile.site
# Install renv to restore all Shiny app deps
RUN R -e "install.packages('renv'); renv::consent(provided = TRUE)"
# Define Project Number
ARG project=p200403
# create root folder for app in container
RUN mkdir /root/${project}
基本上,我不知道如何告诉 DOCKERFILE 从 Azure 容器注册表中拉取容器。