-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstartup.sh
executable file
·59 lines (46 loc) · 1.55 KB
/
startup.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
#!/bin/bash
echo "==============="
echo ""
echo "DOCKER INFO"
docker info
echo ""
echo "DOCKER COMPOSE VERSION"
docker-compose --version
echo ""
echo "==============="
if [ "$GITLAB_URL" == "" ] || [ "$REGISTRATION_TOKEN" == "" ] || [ "$NAME" == "" ]; then
echo "ERROR: You have to specify GITLAB_URL, REGISTRATION_TOKEN and NAME environment variables for this container to run"
exit 1
elif [ ! -f /registered ]; then
echo "Registering this runner on $GITLAB_URL with token $REGISTRATION_TOKEN and description $NAME.."
gitlab-runner --debug register -n \
--url $GITLAB_URL \
--registration-token $REGISTRATION_TOKEN \
--executor docker \
--name "$NAME" \
--tag-list "$TAG_LIST" \
--docker-image "flaviostutz/docker-compose:19.03" \
--docker-volumes /var/run/docker.sock:/var/run/docker.sock
EXIT_CODE=$?
if [ $EXIT_CODE == 0 ]; then
touch /registered
else
echo "Failed to register this Runner. Exiting."
exit $EXIT_CODE
fi
fi
pid=0 #init var
# SIGTERM-handler to unregister de gitlab-runner
shutdown_handler() {
echo "GOOD BYE"
gitlab-runner unregister -n "$NAME"
}
# catch the sigterm and unregister the runner
trap 'shutdown_handler' SIGTERM
# starts the gitlab runner as a "secondary" proccess because it should be down when we unregister it in the SIGTERM handler
echo "Starting Gitlab Runner..."
/usr/bin/dumb-init /entrypoint run --user=gitlab-runner --working-directory=/home/gitlab-runner &
while true
do
tail -f /dev/null & wait "$!"
done