forked from FlakM/gitlab-runner-auto-register
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·73 lines (53 loc) · 1.82 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
if [ -z "$CI_SERVER_URL" ]; then
CI_SERVER_URL="https://gitlab.com/"
fi
if [ -z "$DOCKER_IMAGE" ]; then
export DOCKER_IMAGE=docker:20.10.10
fi
if [ -z "$REGISTRATION_TOKEN" ]; then
echo "ERROR: Env REGISTRATION_TOKEN not set!"
exit 1
fi
if [ "$ADMIN_TOKEN" != "" ]; then
REGISTER_OTHER_PROJECTS="true"
PROJECTS_STRING=`echo "$PROJECTS_TO_REGISTER" | tr ";" ","`
fi
MY_NAME="${CUSTOM_RUNNER_NAME:-$HOSTNAME}"
export RUNNER_NAME="$MY_NAME"
# gitlab-ci-multi-runner data directory
DATA_DIR="/etc/gitlab-runner"
CONFIG_FILE=${CONFIG_FILE:-$DATA_DIR/config.toml}
# custom certificate authority path
CA_CERTIFICATES_PATH=${CA_CERTIFICATES_PATH:-$DATA_DIR/certs/ca.crt}
LOCAL_CA_PATH="/usr/local/share/ca-certificates/ca.crt"
update_ca() {
echo "Updating CA certificates..."
cp "${CA_CERTIFICATES_PATH}" "${LOCAL_CA_PATH}"
update-ca-certificates --fresh >/dev/null
}
if [ -f "${CA_CERTIFICATES_PATH}" ]; then
# update the ca if the custom ca is different than the current
cmp --silent "${CA_CERTIFICATES_PATH}" "${LOCAL_CA_PATH}" || update_ca
fi
echo "===> Start Docker..."
service docker start
echo "===> Trap SIGTERM to terminate Gitlab Runner..."
trap "gitlab-runner stop" SIGTERM
echo "===> Running gitlab-runner register..."
export REGISTER_NON_INTERACTIVE=true
gitlab-runner register --executor=docker $REGISTER_EXTRA_ARGS
if [ $? -gt 0 ]; then
echo "===> ERROR: Registration failed!"
exit 1
fi
if [ "$REGISTER_OTHER_PROJECTS" == "true" ]; then
export GITLAB_TOKEN="$ADMIN_TOKEN"
./gitlab-runner-cleaner.sh register "$RUNNER_NAME" --byId=false --projects "$PROJECTS_STRING"
fi
echo "===> Current version of gitlab-runner:"
gitlab-runner --version
echo "===> Running gitlab-runner run..."
gitlab-runner run
echo "===> Stopping and unregistering..."
gitlab-runner unregister --name "$RUNNER_NAME"