[英]How to pass secrets as environment variables into a Docker Github Action?
In my workflow I'm running a custom action using the following step:在我的工作流程中,我使用以下步骤运行自定义操作:
- name: Run action
uses: ./backend
env:
MY_SECRET: ${{ secrets.MY_SECRET }}
And here's action.yml
:这是
action.yml
:
name: "Backend"
on: [pull_request]
runs:
using: 'docker'
image: "Dockerfile"
For some reason, MY_SECRET
is empty in my Dockerfile
.出于某种原因,我的
Dockerfile
MY_SECRET
为空。 I tried accessing it both in a shell script file and the RUN
command:我尝试在 shell 脚本文件和
RUN
命令中访问它:
RUN echo "MY_SECRET: $MY_SECRET"
But it's always empty.但它总是空的。
I tried both repository-level and organization-level secrets, but the environment variable is always empty.我尝试了存储库级别和组织级别的机密,但环境变量始终为空。
Any idea why?知道为什么吗?
You can't use $MY_SECRET
inside the container.您不能在容器内使用
$MY_SECRET
。 Instead, you should pass argument through the --build-arg
flag.相反,您应该通过
--build-arg
标志传递参数。
I think you should do something like:我认为你应该做这样的事情:
steps:
- run: docker build --build-arg MY_SECRET=$MY_SECRET .
And then you'll be able to access MY_SECRET
in the build phase.然后您将能够在构建阶段访问
MY_SECRET
。
If you're building using an action and not manually, you should find out how to pass the build arguments.如果您使用操作而不是手动构建,您应该了解如何传递构建参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.