windows gitlab-ci:如何指定作业运行的镜像?

b1payxdu  于 2023-11-21  发布在  Windows
关注(0)|答案(2)|浏览(180)

我正在尝试理解文档:

  • https://docs.gitlab.com/ee/ci/yaml/#image

特别是:

  • https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#access-an-image-from-a-private-container-registry

所以我写了下面的.gitlab-ci.yml

  1. # https://docs.gitlab.com/ee/ci/yaml/script.html#set-a-default-before_script-or-after_script-for-all-jobs
  2. default:
  3. before_script:
  4. - docker login -u ${CI_REGISTRY_USER} -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
  5. build windows:
  6. tags:
  7. - powershell
  8. - windows2022
  9. stage: build
  10. script:
  11. - docker build
  12. --tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA}
  13. --build-arg WSCI_VERSION=ltsc2022
  14. -f demo/Dockerfile .
  15. - docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA}
  16. test windows:
  17. tags:
  18. - powershell
  19. - windows2022
  20. variables:
  21. GIT_STRATEGY: none
  22. stage: test
  23. script:
  24. - docker pull ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA}
  25. - docker image inspect ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA}
  26. Upload Windows packages:
  27. tags:
  28. - docker
  29. - windows2022
  30. variables:
  31. GIT_STRATEGY: none
  32. stage: deploy
  33. image: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
  34. script:
  35. - dir

字符串
before_script从未被调用,因此无法访问在image:行上指定的映像。
当我从一个私有仓库中指定了一个显式的image:时,我该如何登录?它看起来不像是在我的私有gitlab设置中设置的DOCKER_AUTH_CONFIG
以下是错误消息以供参考:

  1. Using Docker executor with image gitcloud.acme.com/repo/project:cd370af73fb5058cdb251262c1805fd7246c99ee ...
  2. Authenticating with credentials from C:\Windows\system32\config\systemprofile\.docker\config.json
  3. Pulling docker image gitcloud.acme.com/repo/project:cd370af73fb5058cdb251262c1805fd7246c99ee ...
  4. WARNING: Failed to pull image with policy "always": Error response from daemon: Head "https://gitcloud.acme.com/v2/repo/project/manifests/cd370af73fb5058cdb251262c1805fd7246c99ee": unauthorized: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of a password. See https://gitcloud.acme.com/help/user/profile/account/two_factor_authentication#troubleshooting (manager.go:237:0s)


如果我理解正确,从私有存储库访问映像的正确方法记录在:

  • https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#determine-your-docker_auth_config-data

然而,这个文档似乎暗示我知道密码。这不是我的情况,作为一个简单的用户,我只是用途:

  1. ${CI_REGISTRY_USER} / ${CI_JOB_TOKEN}

91zkwejq

91zkwejq1#

正如您在文档中发现的那样,您必须为您的项目或运行程序设置DOCKER_AUTH_CONFIG(或这里描述的方法之一)。
然而,这个文档似乎暗示我知道密码。这不是我的情况,作为一个简单的用户,我只是使用[作业令牌]
为此,您需要为您的私有注册表生成凭据。在GitLab容器注册表的情况下,这被描述为in the authentication documentation,这意味着以下之一:

然后,您将使用其中一个令牌在项目中创建DOCKER_AUTH_CONFIG变量,如您链接的文档中所述。

js4nwp54

js4nwp542#

多亏了sytech,我重新阅读了文档,并创建了一个部署令牌,似乎在我的情况下工作。
以下是我今天做的事情,供以后参考:
创建部署令牌(无用户名):


的数据
更新测试阶段以转储以下额外值:

  1. test windows:
  2. tags:
  3. - powershell
  4. - windows2022
  5. variables:
  6. GIT_STRATEGY: none
  7. DUMP_ENV: 'env:'
  8. stage: test
  9. before_script:
  10. - dir ${DUMP_ENV} # verify that both CI_DEPLOY_USER and CI_DEPLOY_PASSWORD are present
  11. - docker login -u ${CI_DEPLOY_USER} -p ${CI_DEPLOY_PASSWORD} ${CI_REGISTRY} # use the deploy token
  12. - cat C:/Windows/system32/config/systemprofile/.docker/config.json # dump
  13. script:
  14. - docker pull ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA}
  15. - docker image inspect ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA}

字符串
现在我们有了完整的json,创建预期的变量DOCKER_AUTH_CONFIG如下:



如果部署阶段失败,只需重新启动值DOCKER_AUTH_CONFIG就可以正确读取了。

展开查看全部

相关问题