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. Then I use that image to make deployment on 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
This is what my gitlab-ci.yml file looks like
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:
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.
My end goal is to use Kubernetes Deployment.yaml for username and password and passed as arguments to Dockerfile.
ARGS
are build-time variables so no way to pass values to ARGS at runtime.
By the way, you can override entrypoint
as following in Kubernetes deployment and consume environment variables. ( entrypoint
in Dockerfile is command
in Kubernetes container spec).
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 ${}
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.