forked from gocd/docker-gocd-agent-alpine-3.9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-agent.sh
executable file
·78 lines (60 loc) · 2.9 KB
/
prepare-agent.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
73
74
75
76
77
78
#!/bin/bash
# Copyright 2018 ThoughtWorks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
yell() { echo "$0: $*" >&2; }
die() { yell "$*"; exit 111; }
try() { echo "$ $@" 1>&2; "$@" || die "cannot $*"; }
[ -z "${VOLUME_DIR}" ] && VOLUME_DIR="/godata"
AGENT_WORK_DIR="/go"
# if running go agent as root, then initialize directory structure and call ourselves as `go` user
if [ "$(id -u)" = '0' ]; then
server_dirs=(config logs pipelines)
yell "Creating directories and symlinks to hold GoCD configuration, data, and logs"
# ensure working dir exist
if [ ! -e "${AGENT_WORK_DIR}" ]; then
try mkdir "${AGENT_WORK_DIR}"
try chown go:go "${AGENT_WORK_DIR}"
fi
# ensure proper directory structure in the volume directory
if [ ! -e "${VOLUME_DIR}" ]; then
try mkdir "${VOLUME_DIR}"
try chown go:go "${AGENT_WORK_DIR}"
fi
for each_dir in "${server_dirs[@]}"; do
if [ ! -e "${VOLUME_DIR}/${each_dir}" ]; then
try mkdir -v "${VOLUME_DIR}/${each_dir}"
try chown go:go "${VOLUME_DIR}/${each_dir}"
fi
if [ ! -e "${AGENT_WORK_DIR}/${each_dir}" ]; then
try ln -sv "${VOLUME_DIR}/${each_dir}" "${AGENT_WORK_DIR}/${each_dir}"
try chown go:go "${AGENT_WORK_DIR}/${each_dir}"
fi
done
if [ ! -e "${AGENT_WORK_DIR}/config/agent-bootstrapper-logback-include.xml" ]; then
try cp -rfv "/go-agent/config/agent-bootstrapper-logback-include.xml" "${AGENT_WORK_DIR}/config/agent-bootstrapper-logback-include.xml"
try chown go:go "${VOLUME_DIR}/config/agent-bootstrapper-logback-include.xml"
fi
if [ ! -e "${AGENT_WORK_DIR}/config/agent-launcher-logback-include.xml" ]; then
try cp -rfv "/go-agent/config/agent-launcher-logback-include.xml" "${AGENT_WORK_DIR}/config/agent-launcher-logback-include.xml"
try chown go:go "${VOLUME_DIR}/config/agent-launcher-logback-include.xml"
fi
if [ ! -e "${AGENT_WORK_DIR}/config/agent-logback-include.xml" ]; then
try cp -rfv "/go-agent/config/agent-logback-include.xml" "${AGENT_WORK_DIR}/config/agent-logback-include.xml"
try chown go:go "${VOLUME_DIR}/config/agent-logback-include.xml"
fi
fi
# these 3 vars are used by `/go-agent/agent.sh`, so we export
export AGENT_WORK_DIR
export GO_AGENT_SYSTEM_PROPERTIES="${GO_AGENT_SYSTEM_PROPERTIES}${GO_AGENT_SYSTEM_PROPERTIES:+ }-Dgo.console.stdout=true"
export AGENT_BOOTSTRAPPER_JVM_ARGS="${AGENT_BOOTSTRAPPER_JVM_ARGS}${AGENT_BOOTSTRAPPER_JVM_ARGS:+ }-Dgo.console.stdout=true"