Set all existing variables into the build container
What does this MR do?
Before this MR, when executing a job with the k8s executor, only the public or internal variables were directly set as env variables for the container. This defacto blocks any image with a custom entrypoint to make use of them. On the docker executor side, the behaviour is different as such distinction is not made.
With this MR, we make the k8s executor behaves as the docker one by setting all existing variables as container env variables
Why was this MR needed?
To allow custom entrypoint to make use of all variables at the start of the container
What's the best way to test this MR?
- Create a group (or use an existing one) and create the variable
MY_GROUP_LEVEL_ENV
with the valueThis is my group level environment variable
(nor masked, nor protected) - Create a project within this group and create the variable
MY_PROJECT_LEVEL_ENV
with the valueThis is my project level env variable
(nor masked, nor protected) - Use the following gitlab-ci.yml
gitlab-ci
stages:
- test
variables:
FF_KUBERNETES_HONOR_ENTRYPOINT: "true"
format:
stage: test
image: aaro301/alpine:custom-entrypoint
script:
- sleep 30
The image used has been created using the following dockerfile
dockerfile
FROM alpine:latest@sha256:1304f174557314a7ed9eddb4eab12fed12cb0cd9809e4c28f29af86979a3c870
COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
entrypoint.sh
#!/bin/sh
echo "=================================="
echo "This is the custom entrypoint"
echo "$MY_GROUP_LEVEL_ENV";
echo "$MY_PROJECT_LEVEL_ENV";
echo "=================================="
exec "$@"
- Use the following config.toml
config.toml
concurrent = 1
check_interval = 1
log_level = "debug"
[session_server]
session_timeout = 1800
[[runners]]
url = "https://gitlab.com/"
token = "__TOKEN__"
executor = "kubernetes"
[runners.kubernetes]
terminationGracePeriodSeconds = 0
[runners.kubernetes.affinity]
[runners.kubernetes.volumes]
[runners.kubernetes.dns_config]
- Run the job and display the build container logs using the command
kubectl logs -f <POD_NAME> build -n <NAMESPACE>
- The log will show the print of the Group Level and Project Level variables
==================================
This is the custom entrypoint
This is my group level environment variable
This is my project level env variable
==================================
$ sleep 30
What are the relevant issue numbers?
close https://gitlab.com/gitlab-com/ops-sub-department/section-ops-request-for-help/-/issues/27
Edited by Romuald Atchadé