【发布时间】:2021-08-09 14:06:02
【问题描述】:
这个问题有点像这个问题。 How to pass GitLab CI file variable to Dockerfile and docker container?
我使用了投票最多的答案,但是我失败了。
下面是我想做的。
我使用 file 类型设置了名为 PIP_CONFIG 的 gitlab ci 变量。 价值就像
[global]
timeout = 60
在.gitlab-ci.yml
...
- docker build -t $IMAGe
--build-arg PIP_CONFIG=$PIP_CONFIG
src/.
...
在Dockerfile
FROM python:3
ARG PIP_CONFIG
RUN mkdir ~/.pip
RUN echo $PIP_CONFIG > ~/.pip/pip.conf
...
...
RUN pip install -r requirements.txt
然后我得到一个错误
Configuration file could not be loaded.
File contains no section headers.
file: '/root/.pip/pip.conf', line: 1
'/builds/xxx/xxx/project_name.tmp/PIPCONFIG\n' <<<< this line
...
好像只写了临时文件的路径而不是文件的内容。
我也尝试使用COPY $PIP_CONFIG ~/.pip/pip.conf,但它说/builds/xxx/xxx/project_name.tmp/PIPCONFIG中不存在路径。
有人能告诉我我应该怎么做吗?谢谢。
PS:我之所以不直接在存储库中编写配置,而是使用来自 repo 的COPY,是因为 pip config 中有一些敏感令牌。
【问题讨论】:
标签: docker pip gitlab gitlab-ci