[英]Is it possible to use GitHub Action inputs inside the Dockerfile?
I created a GitHub action and am passing input arguments to the action.我创建了一个 GitHub 操作并将输入参数传递给该操作。 I am using these arguments in a bash script, which is being called by the
Dockerfile
.我在 bash 脚本中使用这些参数,该脚本由
Dockerfile
。 However, it is possible to use any of these inputs in the Dockerfile
?但是,可以在
Dockerfile
使用这些输入中的Dockerfile
吗?
Specifically I am trying to make the python version a variable input.具体来说,我试图使 python 版本成为变量输入。 The
Dockerfile
is: Dockerfile
是:
FROM python:3
RUN pip install flake8
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
Where I want the first line to be我希望第一行在哪里
FROM python:<github_action_input_arg>
First, I suggest you to use docker/build-push-action@v2
.首先,我建议你使用
docker/build-push-action@v2
。 Then in pipeline, you could use next to pass argument from github actions to Dockerfile:然后在管道中,您可以使用 next 将参数从 github 操作传递到 Dockerfile:
-
name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: $your_account/$your_repo
build-args: |
github_action_input_arg=xxx
Of course, for Dockerfile
, you should change to next:当然,对于
Dockerfile
,您应该更改为下一个:
ARG github_action_input_arg
FROM python:${github_action_input_arg}
You could refers to understand-how-arg-and-from-interact & build-push-action .您可以参考理解-如何-arg-and-from-interact & build-push-action 。 If you mean you are the owner of your own action, you could also refers to
build-push-action
to know how it handle this.如果您的意思是您是自己操作的所有者,则还可以参考
build-push-action
以了解它如何处理此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.