-
Notifications
You must be signed in to change notification settings - Fork 1
/
distbuild.configure
132 lines (107 loc) · 3.93 KB
/
distbuild.configure
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/sh
# Copyright (C) 2013-2014 Codethink Limited
#
# 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; version 2 of the License.
#
# 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# This is a "morph deploy" configure extension to configure a Baserock
# build node, as part of a distributed building cluster. It uses the
# following variables from the environment:
#
# * DISTBUILD_CONTROLLER: if 'yes', machine is set up as the controller.
# * DISTBUILD_WORKER: if 'yes', machine is set up as a worker.
# * TROVE_ID: hostname and Trove prefix of the server to pull source
# from and push built artifacts to.
# * TROVE_HOST: FQDN of the same server as in TROVE_ID
#
# The following variable is optional:
#
# * ARTIFACT_CACHE_SERVER: by default artifacts are pushed to the same
# Trove that served the source, but you can use a different one.
#
# The following variable is required for worker nodes only:
#
# * CONTROLLERHOST: hostname or IP address of distbuild controller machine.
# * WORKER_SSH_KEY: identity used to authenticate with Trove
#
# The following variable is required for the controller node only:
#
# * WORKERS: hostnames or IP address of worker nodes, comma-separated.
set -e
if [ -n "$DISTBUILD_GENERIC" ]; then
echo "Not configuring the distbuild node, it will be generic"
exit 0
fi
# Set default values for these two options if they are unset, so that if the
# user specifies no distbuild config at all the configure extension exits
# without doing anything but does not raise an error.
DISTBUILD_CONTROLLER=${DISTBUILD_CONTROLLER-False}
DISTBUILD_WORKER=${DISTBUILD_WORKER-False}
if [ "$DISTBUILD_CONTROLLER" = False -a "$DISTBUILD_WORKER" = False ]; then
exit 0
fi
set -u
# Check that all the variables needed are present:
error_vars=false
if [ "x$TROVE_HOST" = "x" ]; then
echo "ERROR: TROVE_HOST needs to be defined."
error_vars=true
fi
if [ "x$TROVE_ID" = "x" ]; then
echo "ERROR: TROVE_ID needs to be defined."
error_vars=true
fi
if [ "$DISTBUILD_WORKER" = True ]; then
if ! ssh-keygen -lf "$WORKER_SSH_KEY" > /dev/null 2>&1; then
echo "ERROR: WORKER_SSH_KEY is not a vaild ssh key."
error_vars=true
fi
if [ "x$CONTROLLERHOST" = "x" ]; then
echo "ERROR: CONTROLLERHOST needs to be defined."
error_vars=true
fi
fi
if [ "$DISTBUILD_CONTROLLER" = True ]; then
if [ "x$WORKERS" = "x" ]; then
echo "ERROR: WORKERS needs to be defined."
error_vars=true
fi
fi
if "$error_vars"; then
exit 1
fi
ROOT="$1"
DISTBUILD_DATA="$ROOT/etc/distbuild"
mkdir -p "$DISTBUILD_DATA"
# If it's a worker, install the worker ssh key.
if [ "$DISTBUILD_WORKER" = True ]
then
install -m 0644 "$WORKER_SSH_KEY" "$DISTBUILD_DATA/worker.key"
fi
# Create the configuration file
python <<'EOF' >"$DISTBUILD_DATA/distbuild.conf"
import os, sys, yaml
distbuild_configuration={
'TROVE_ID': os.environ['TROVE_ID'],
'TROVE_HOST': os.environ['TROVE_HOST'],
'DISTBUILD_WORKER': os.environ['DISTBUILD_WORKER'],
'DISTBUILD_CONTROLLER': os.environ['DISTBUILD_CONTROLLER'],
'WORKER_SSH_KEY': '/etc/distbuild/worker.key',
}
optional_keys = ('ARTIFACT_CACHE_SERVER', 'CONTROLLERHOST', 'WORKERS',
'TROVE_BACKUP_KEYS')
for key in optional_keys:
if key in os.environ:
distbuild_configuration[key] = os.environ[key]
yaml.dump(distbuild_configuration, sys.stdout, default_flow_style=False)
EOF