如何使用 AWS CodeArtifact *within* AWSCodeBuild 中的 Dockerfile [英] How to use AWS CodeArtifact *within* A Dockerfile in AWSCodeBuild

查看:18
本文介绍了如何使用 AWS CodeArtifact *within* AWSCodeBuild 中的 Dockerfile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 aws codebuild 中的 dockerbuild 中的 codeartifact 执行 pip 安装.

I am trying to do a pip install from codeartifact from within a dockerbuild in aws codebuild.

这篇文章并没有完全解决我的问题:https://docs.aws.amazon.com/codeartifact/latest/ug/using-python-packages-in-codebuild.html

This article does not quite solve my problem: https://docs.aws.amazon.com/codeartifact/latest/ug/using-python-packages-in-codebuild.html

AWS CodeArtifct 的登录在预构建中;Docker 上下文之外.

The login to AWS CodeArtifct is in the prebuild; outside of the Docker context.

但我的 pip install 我的 Dockerfile(我们从私有 pypi 注册表中提取).

But my pip install is inside my Dockerfile (we pull from a private pypi registry).

在预构建中运行登录命令后,我如何做到这一点,而不是做一些可怕的事情,比如将环境变量设置为从读取 ~/.config/pip.conf/ 派生的密码?>

How do I do this, without doing something horrible like setting an env variable to the password derived from reading ~/.config/pip.conf/ after running the login command in prebuild?

推荐答案

所以,这是我现在解决这个问题的方法.看起来有点 hacky,但它有效:

So, here is how I solved this for now. Seems kinda hacky, but it works:

  1. 在预构建中,我运行命令并将 ~/.config/pip/pip.conf 复制到当前构建目录:
  1. In the prebuild, I run the command and copy ~/.config/pip/pip.conf to the current build directory:

pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      ...
      - echo Fetching pip.conf for PYPI
      - aws codeartifact --region us-east-1 login --tool pip --repository ....
      - cp ~/.config/pip/pip.conf .
  build:
    commands:
      - docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
      - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG

  1. 然后在Dockerfile中,我COPY那个文件,执行pip install,然后rm it
  1. Then in the Dockerfile, I COPY that file in, do the pip install, then rm it

COPY requirements.txt pkg/
COPY --chown=myuser:myuser pip.conf /home/myuser/.config/pip/pip.conf
RUN pip install -r ./pkg/requirements.txt
RUN pip install ./pkg
RUN rm /home/myuser/.config/pip/pip.conf

这篇关于如何使用 AWS CodeArtifact *within* AWSCodeBuild 中的 Dockerfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆