From 75d23c602a1c8ccd1e73e853ecb6b80bdd16cfd9 Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen.haas@lakedrops.com> Date: Wed, 22 May 2024 08:32:03 +0200 Subject: [PATCH] Set access token through inventory specific variable and remove the global env and default values from new runners --- templates/register.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/register.sh b/templates/register.sh index 42e4010..bd631b7 100755 --- a/templates/register.sh +++ b/templates/register.sh @@ -6,18 +6,18 @@ if [[ "$1" == "" ]]; then echo "Project ID required as first argument." exit 1 elif [[ "$1" == "auto" ]]; then - ID=$(curl -s -H "PRIVATE-TOKEN: {{ lookup('env','GITLAB_ACCESS_TOKEN') }}" "https://gitlab.lakedrops.com/api/v4/projects/?topic=needs_runner_{{ inventory_hostname }}" | jq -r '.[0].id') + ID=$(curl -s -H "PRIVATE-TOKEN: {{ gitlab_register_runner_access_token }}" "https://gitlab.lakedrops.com/api/v4/projects/?topic=needs_runner_{{ inventory_hostname }}" | jq -r '.[0].id') if [[ "$ID" == "null" ]]; then echo "Nothing to do" exit 0 fi echo "Adding runner for project ID $ID" - curl -X PUT -s -H "PRIVATE-TOKEN: {{ lookup('env','GITLAB_ACCESS_TOKEN') }}" "https://gitlab.lakedrops.com/api/v4/projects/${ID}" -d "topics=runner_{{ inventory_hostname }}" + curl -X PUT -s -H "PRIVATE-TOKEN: {{ gitlab_register_runner_access_token }}" "https://gitlab.lakedrops.com/api/v4/projects/${ID}" -d "topics=runner_{{ inventory_hostname }}" else ID=$1 fi -TOKEN=$(curl -s -X POST -H "PRIVATE-TOKEN: {{ lookup('env','GITLAB_ACCESS_TOKEN') }}" --data "runner_type=project_type" --data "project_id=${ID}" --data "tag_list=deploylocal" "https://gitlab.lakedrops.com/api/v4/user/runners" | jq -r .token) -NAME=$(curl -s -H "PRIVATE-TOKEN: {{ lookup('env','GITLAB_ACCESS_TOKEN') }}" "https://gitlab.lakedrops.com/api/v4/projects/${ID}" | jq -r .path_with_namespace) +TOKEN=$(curl -s -X POST -H "PRIVATE-TOKEN: {{ gitlab_register_runner_access_token }}" --data "runner_type=project_type" --data "project_id=${ID}" --data "tag_list=deploylocal" "https://gitlab.lakedrops.com/api/v4/user/runners" | jq -r .token) +NAME=$(curl -s -H "PRIVATE-TOKEN: {{ gitlab_register_runner_access_token }}" "https://gitlab.lakedrops.com/api/v4/projects/${ID}" | jq -r .path_with_namespace) -gitlab-runner register --non-interactive --token "${TOKEN}" --name "Local deployment {{ inventory_hostname }}, ${NAME}" --url https://gitlab.lakedrops.com/ --executor docker --docker-image registry.lakedrops.com/docker/gitlab-drupal-ci/php-7.4 --docker-disable-cache --docker-volumes "/var/run/docker.sock:/var/run/docker.sock" --docker-volumes "/drupal/${ID}:/data" --env "DOCKER_AUTH_CONFIG={\"auths\":{\"registry.lakedrops.com\":{\"auth\":\"{{ gitlab_docker_registry_token }}\"}}}" --docker-pull-policy "always" +gitlab-runner register --non-interactive --token "${TOKEN}" --name "Local deployment {{ inventory_hostname }}, ${NAME}" --url https://gitlab.lakedrops.com/ --executor docker --docker-image registry.lakedrops.com/docker/gitlab-drupal-ci/php-7.4 --docker-disable-cache --docker-volumes "/var/run/docker.sock:/var/run/docker.sock" --docker-volumes "/drupal/${ID}:/data" -- GitLab