[英]Override Dockerfile arguments by Kubernetes Deployment.yml
I'm running a pipeline on gitlab which uses .gitlab-ci.yml and Dockerfile to build a image and push it to GCP container repository.我在 gitlab 上运行一个管道,它使用 .gitlab-ci.yml 和 Dockerfile 来构建映像并将其推送到 GCP 容器存储库。 Then I use that image to make deployment on Kubernetes.
然后我使用该映像在 Kubernetes 上进行部署。
I'm using CI/CD private variables to inject username(service_now_qa_username) and password(service_now_qa_password) and passing it as arguments to docker build command which are then used in Dockerfile我正在使用 CI/CD 私有变量来注入用户名(service_now_qa_username)和密码(service_now_qa_password) ,并将其作为参数传递给 docker build 命令,然后在Dockerfile中使用
This is what my gitlab-ci.yml file looks like这就是我的 gitlab-ci.yml 文件的样子
variables:
BUILD_ARGS: "--build-arg USERNAME=$service_now_qa_username --build-arg PASSWORD=$service_now_qa_password"
script:
- docker build -t "$IMAGE_NAME:$CI_COMMIT_REF_NAME" -t "$IMAGE_NAME:latest" $BUILD_ARGS .
This is what my Dockerfile looks like:这是我的 Dockerfile 的样子:
ARG USERNAME
ARG PASSWORD
ENV USER=$USERNAME
ENV PASS=$PASSWORD
ENTRYPOINT java -jar servicenowapi.jar -conf config.json -username ${USER} -password ${PASS}
Now I want to override these arguments of username and password using Kubernetes Deployment.yml and use Deployment.yaml file to override these arguments.现在我想使用 Kubernetes Deployment.yml覆盖用户名和密码的这些参数,并使用 Deployment.yaml 文件覆盖这些参数。
My end goal is to use Kubernetes Deployment.yaml for username and password and passed as arguments to Dockerfile.我的最终目标是使用 Kubernetes Deployment.yaml 作为用户名和密码,并作为参数传递给 Dockerfile。
ARGS
are build-time variables so no way to pass values to ARGS at runtime. ARGS
是构建时变量,因此无法在运行时将值传递给 ARGS。
By the way, you can override entrypoint
as following in Kubernetes deployment and consume environment variables.顺便说一句,您可以在 Kubernetes 部署中按照以下方式覆盖
entrypoint
点并使用环境变量。 ( entrypoint
in Dockerfile is command
in Kubernetes container spec). (Dockerfile 中的
entrypoint
点是 Kubernetes 容器规范中的command
)。
containers:
- name: xxxx
env:
- name: USER
value: "Input your user"
- name: PASS
value: "Input your pass"
command: ["java", "-jar servicenowapi.jar -conf config.json -username $(USER) -password $(PASS)"]
The main thing here is to define env vars and to use $()
instead of ${}
.这里的主要内容是定义环境变量并使用
$()
而不是${}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.