【问题标题】:AWS Codeartifact and docker build cacheAWS Codeartifact 和 docker 构建缓存
【发布时间】:2021-09-24 04:18:41
【问题描述】:

我正在尝试使用 AWS Codeartifact 作为我的 pip 存储库。 每次构建 docker 映像时,我都需要登录或生成令牌, 我试过这个:How to use AWS CodeArtifact *within* A Dockerfile in AWSCodeBuild

但在每个构建中,pip.conf 文件都不同(新令牌),这会破坏 docker 缓存。

现在我想避免预安装所有软件包的基础映像。

谁有这个问题的解决方案?

谢谢!

【问题讨论】:

    标签: docker pip docker-build aws-codeartifact


    【解决方案1】:

    看起来 docker buildkit 就是答案。

    生成文件:

    docker_build:
        @$(eval CODEARTIFACT_AUTH_TOKEN := $(shell aws codeartifact get-authorization-token --domain your-domain --domain-owner your-id --region your-region --query authorizationToken --output text --duration-seconds 900))
        @pip config set global.index-url "https://aws:${CODEARTIFACT_AUTH_TOKEN}@<your-domain>-<your-id>.d.codeartifact.<your-region>.amazonaws.com/pypi/your-repo/simple/"
        cp ~/.config/pip/pip.conf /tmp/pip.conf
        DOCKER_BUILDKIT=1 docker build --progress=plain --secret id=pip.conf,src=/tmp/pip.conf -t tmp_docker_image .
    

    Dockerfile:

    FROM python:3.8.8-slim-buster
    WORKDIR /code
    ADD requirements.txt /code/requirements.txt
    RUN --mount=type=secret,id=pip.conf,dst=/root/.pip/pip.conf \
    pip install -r ./requirements.txt
    

    我已经测试了几次,每次运行都更改了令牌,看起来不错。

    这个帮助了:https://dev.to/hugoprudente/managing-secrets-during-docker-build-3682

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-23
      • 2023-01-08
      • 2018-02-06
      • 2018-06-27
      • 1970-01-01
      • 2021-07-27
      • 2021-08-04
      • 2020-04-16
      相关资源
      最近更新 更多