简体   繁体   English

在 Dockerfile 中使用 Github 机密不适用于 Github 操作

[英]Use Github secrets in Dockerfile does not work with Github Actions

I have a Github Action to build image from a Dockerfile located in the same repo with the Github Action.我有一个 Github Action,可以从与 Github Action 位于同一仓库中的 Dockerfile 构建映像。

In the Dockerfile I use sensitive data so I chose to use Github Secrets.在 Dockerfile 中我使用敏感数据,所以我选择使用 Github Secrets。

Here is my Dockerfile:这是我的 Dockerfile:

From python:3.9.5

ARG NEXUS_USER
ARG NEXUS_PASS

RUN pip install --upgrade pip

RUN pip config set global.extra-index-url https://${NEXUS_USER}:${NEXUS_PASS}@<my nexus endpoint>
RUN pip config set global.trusted-host <my nexus endpoint>

COPY ./src/python /python-scripts

ENTRYPOINT [ "python", "/python-scripts/pipe.py" ]

Actions builds an image using this Dockerfile: Actions 使用此 Dockerfile 构建映像:

jobs:
  docker:
      runs-on: self-hosted
        .
        .
        .
        .
        .
        - name: build
          run: |
            docker build -t ${GITHUB_REPO} .

Action fails when calling the Github secrets from Dockerfile.从 Dockerfile 调用 Github 机密时操作失败。 What is the proper way to do that?这样做的正确方法是什么? As you can see I tried to add ARG in Dockerfile but that didn't work as well.如您所见,我尝试在 Dockerfile 中添加 ARG,但效果不佳。

Is not clear where you are calling secrets from the Dockerfile, BTW you could pass the credentials to the build command using the build-arg flag, like:不清楚您从 Dockerfile 调用机密的位置,顺便说一句,您可以使用 build-arg 标志将凭据传递给构建命令,例如:

 docker build \
   --build-arg "NEXUS_USER=${{ secrets.NEXUS_USER }}" \
   --build-arg "NEXUS_PASS=${{ secrets.NEXUS_PASS }}" \
   -t ${GITHUB_REPO} .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 GitHub Actions 上访问 React 应用程序的 github 机密 - Accesing github secrets on GitHub Actions for a React App Github 组织使用机密、操作和 PAT - Github organization using secrets, actions and PAT's 来自 GitHub 的秘密 docker 容器中的操作不可用 - Secrets from GitHub Actions unavailable in the docker container 如何在 GitHub Actions 中内置的 Dockerfile 中使用 github 令牌并尝试克隆私有存储库? - How to use github token in Dockerfile that is built in GitHub Actions and trying to clone private repository? 如何在 Github 操作中设置 Dockerfile ARG - How to set a Dockerfile ARG in Github actions 无法在 Github 操作中为 .NetCore 构建 Dockerfile - Unable to Build Dockerfile for .NetCore in Github Actions 在 GitHub 操作中使用本地 Dockerfile? - Use local Dockerfile in a GitHub action? 在 GitHub 操作中使用 docker 文件 - Use of docker files in GitHub Actions 我可以参考 Dockerfile 而不是 GitHub 操作工作流程中的图像吗? - Can I reference a Dockerfile instead of an image in a GitHub Actions workflow? 如何使用 GitHub 动作为我的 python 项目测试我的 Dockerfile? - How to test my Dockerfile for my python project using GitHub actions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM