-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CI_SERVICE_alias environment variables to make referencing the FQDN of services fun! #27
Conversation
`config.sh` prints JSON to STDOUT following the expected form defined in https://docs.gitlab.com/runner/executors/custom.html#config This change also moves `base.sh` warnings to STDERR.
Much ado about little here. Some restructuring was needed in order to populate a CI_SERVICE_<alias> variables as services are started, then inject them into a temporary manifest. On the way I found that the old TMPVARFILE was not working correctly. I 🪿 love 🪿 bash🪿!!!
Pipeline proof of life for folks who want "evidence" - https://gitlab.com/pauldoomgov/hyperloop-traffic-jam/-/pipelines/1399063314 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remember exactly which thing it is that voids approvals… but hopefully none of these comments will.
cat "${currentDir}/worker-manifest.yml" > "$TMPMANIFEST" | ||
|
||
# Align additional environment variables with YAML at end of source manifest | ||
local padding=" " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought (non-blocking): 😨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, right? 🧌
echo "WARNING: DEFAULT_JOB_IMAGE not set! Falling back to ${DEFAULT_JOB_IMAGE}" 1>&2 | ||
fi | ||
|
||
# Complain if no Docker Hub credentials so we aren't bad neighbors | ||
if [ -z "$DOCKER_HUB_USER" ] || [ -z "$DOCKER_HUB_TOKEN" ]; then | ||
echo "WARNING: Docker Hub credentials not set! Falling back to public access which could result in rate limiting." | ||
echo "WARNING: Docker Hub credentials not set! Falling back to public access which could result in rate limiting." 1>&2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: good thinking
# Add any CI_SERVICE_x variables populated by start_service() | ||
for v in "${!CI_SERVICE_@}"; do | ||
echo "${padding}${v}: \"${!v}\"" >> "$TMPMANIFEST" | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: the indirection is pretty nifty, I haven't used that before
This addresses #7
This change injects an environment variable named
CI_SERVICE_<alias>
for each service and sets the value to the fully qualified domain name of the service. Here is an example snippet of.gitlab-ci.yml
showing its use:The old method to get to the same outcome required cobbling the variable together from 5 other variables.
Instead of attempting to hack the GitLab generated command list, we just calculate and inject the CI_SERVICE_alias variables in
prepare.sh
using a modified CloudFoundry manifest. It might be hideous, but since the need to calculate a service name dynamically is not present in Docker, Kubernetes, and other executors with ephemeral local network namespaces, it seems right.