summaryrefslogtreecommitdiff
path: root/distbuild.configure
blob: bf145b14cde0d96e0aecaea9de154917f32a49d3 (plain)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/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.
#
# 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 ARTIFACT_CACHE_SERVER isn't set, default to $TROVE_ID.
if [ "x$ARTIFACT_CACHE_SERVER" = x ]
then
    ARTIFACT_CACHE_SERVER="$TROVE_ID"
fi

set -u


# Create the mount point for extra disk space.
install -d -o 0 -g 0 -m 0755 "$1/srv/distbuild"


# Configuration shared by all instances of Morph. For reasons of
# convenience, this sets the controller-initiator-address, so
# that when users invoke "morph", they don't need to manually
# specify it, or to manually add another configuration file to
# use. However, the setting may only be set for the distbuild
# initiator (which is what the user invokes), so in ALL other
# configuration files we unset it.
#
# We disable the disk space requirement checks on non-worker nodes.
# They don't make sense unless you're building locally.

cat <<EOF > "$1/etc/morph.conf"
[config]
log = /var/log/morph.log
log-max = 100M
cachedir = /srv/distbuild
tempdir = /srv/distbuild/tmp
trove-host = $TROVE_ID
trove-id = $TROVE_ID
controller-initiator-address = $CONTROLLERHOST
tempdir-min-space = 0
cachedir-min-space = 0
build-ref-prefix = $TROVE_ID
artifact-cache-server = http://${ARTIFACT_CACHE_SERVER}:8080/
git-resolve-cache-server = http://${TROVE_ID}:8080/
EOF


# Configuration for a distbuild controller. This configuration
# file gets used by the systemd unit that runs the controller.
# The existence of this configuration file triggers the systemd
# unit, so we only create it on nodes that are meant to act as
# the controller.

if [ "$DISTBUILD_CONTROLLER" = True ]
then
    cat <<EOF > "$1/etc/morph-controller.conf"
[config]
log = /var/log/morph-controller.log
log-max = 100M
writeable-cache-server = http://${ARTIFACT_CACHE_SERVER}:8081/
worker = $WORKERS
controller-helper-address = 127.0.0.1
EOF
    
    # Configuration for the controller's helper process. This
    # gets used by the systemd unit that starts the helper.

cat <<EOF > "$1/etc/morph-controller-helper.conf"
[config]
log = /var/log/morph-controller-helper.log
log-max = 100M
parent-port = 5656
parent-address = 127.0.0.1
EOF

fi

# Configuration for a distbuild worker. This gets reference
# by the systemd unit that starts the worker. Again, the
# existence of morph-worker.conf triggers the systemd unit
# to starts the worker, so we only create it on systems
# that are meant to be a worker.

if [ "$DISTBUILD_WORKER" = True ]
then
    cat <<EOF > "$1/etc/morph-worker.conf"
[config]
log = /var/log/morph-worker.log
log-max = 100M
controller-initiator-address =
EOF

    # This will be used for a systemd generator which 
    # nfs mounts the ccache from the trove
    echo "$TROVE_ID" > "$1/etc/trove-host"

    # Configuration for the controller's helper process. This
    # gets used by the systemd unit that starts the helper.

cat <<EOF > "$1/etc/morph-worker-helper.conf"
[config]
log = /var/log/morph-worker-helper.log
log-max = 100M
parent-address = 127.0.0.1
EOF


    # Configuration for the Morph cache server daemon. We
    # only run the cache server on workers.

cat <<EOF > "$1/etc/morph-cache-server.conf"
[config]
port = 8080
artifact-dir = /srv/distbuild/artifacts
direct-mode = True
fcgi-server = False
EOF

echo "Copy distbuild worker SSH key to system"
mkdir -p "$1/root/.ssh"
install -m 0600 "$WORKER_SSH_KEY" "$1/root/.ssh/id_rsa"
install -m 0644 "${WORKER_SSH_KEY}.pub" "$1/root/.ssh/id_rsa.pub"

# Add trove's host key
ssh-keyscan -t dsa,ecdsa,rsa "$TROVE_ID" >> "$1/root/.ssh/known_hosts"
fi