-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·69 lines (60 loc) · 2.52 KB
/
docker-entrypoint.sh
File metadata and controls
executable file
·69 lines (60 loc) · 2.52 KB
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
#!/bin/bash
###################################################################################################
# Copyright (c) 2018, Nils Knieling. All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
###################################################################################################
###################################################################################################
# HELPERS
###################################################################################################
# exit_with_failure() outputs a message before exiting the script
function exit_with_failure() {
echo "FAILURE: $1"
exit 9
}
# command_exists() tells if a given command exists.
function command_exists() {
command -v "$1" >/dev/null 2>&1
}
###################################################################################################
# MAIN
###################################################################################################
echo "[Entrypoint] GitLab Runner Docker Image optimized for Cloud Foundry"
if ! command_exists curl; then
exit_with_failure "'curl' is needed. Please install 'curl'."
fi
if [ -z "$CI_SERVER_URL" ]; then
exit_with_failure 'CI_SERVER_URL is missing'
fi
if [ -z "$RUNNER_NAME" ]; then
exit_with_failure 'RUNNER_NAME is missing'
fi
if [ -z "$REGISTRATION_TOKEN" ]; then
exit_with_failure 'REGISTRATION_TOKEN is missing'
fi
if [ -z "$RUNNER_EXECUTOR" ]; then
export RUNNER_EXECUTOR="shell"
fi
echo "Register GitLab Runner with Name $RUNNER_NAME"
if curl -s --header "Private-Token: $API_PRIVATE_TOKEN" "$API_RUNNER_URL" | grep "description\":\"$RUNNER_NAME\""; then
exit_with_failure "GitLab Runner with name $RUNNER_NAME already registered"
else
if gitlab-runner register --non-interactive; then
echo "GitLab Runner successfully registered"
else
exit_with_failure "GitLab Runner not registered"
fi
fi
echo "Start GitLab Runner"
gitlab-runner "$@"