如何在 GitLab CI 中的任何其他内容之前在我的 PATH 中设置 docker-credential-ecr-login

Ama*_*ari 5 gitlab docker aws-ecr

我正在使用 AWS ECR 来托管私有 Dockerfile 映像,我想在 GitLab CI 中使用它。

根据文档,我需要设置 docker-credential-ecr-login 以获取私有图像,但我不知道如何在其他任何事情之前做到这一点。那是我的 .gitlab-ci 文件:

image: 0222822883.dkr.ecr.us-east-1.amazonaws.com/api-build:latest

tests:
  stage: test
  before_script:
    - echo "before_script"
    - apt install amazon-ecr-credential-helper
    - apk add --no-cache curl jq python py-pip
    - pip install awscli
  script:
    - echo "script"
    - bundle install
    - bundle exec rspec
  allow_failure: true # for now as we do not have tests
Run Code Online (Sandbox Code Playgroud)

谢谢你。

pal*_*taa 0

来自 GitLab 文档。为了与您的 AWS 账户进行交互,GitLab CI/CD 管道需要在设置 > CI/CD > 变量下的 GitLab 设置中定义 AWS_ACCESS_KEY_ID 和 AWS_SECRET_ACCESS_KEY。然后添加到您的之前脚本中:

image: 0222822883.dkr.ecr.us-east-1.amazonaws.com/api-build:latest

tests:
  stage: test
  before_script:
    - echo "before_script"
    - apt install amazon-ecr-credential-helper
    - apk add --no-cache curl jq python py-pip
    - pip install awscli
    - $( aws ecr get-login --no-include-email )
  script:
    - echo "script"
    - bundle install
    - bundle exec rspec
  allow_failure: true # for now as we do not have tests
Run Code Online (Sandbox Code Playgroud)

另外,您有一个拼写错误是awscli,而不是awsclir。然后添加构建、测试并相应地推送。