fix(provision): pin formulas' versions
[arvados.git] / tools / salt-install / provision.sh
1 #!/bin/bash
2
3 # Copyright (C) The Arvados Authors. All rights reserved.
4 #
5 # SPDX-License-Identifier: CC-BY-SA-3.0
6
7 # If you want to test arvados in a single host, you can run this script, which
8 # will install it using salt masterless
9 # This script is run by the Vagrant file when you run it with
10 #
11 # vagrant up
12
13 ##########################################################
14 # This section are the basic parameters to configure the installation
15
16 # The 5 letters name you want to give your cluster
17 CLUSTER="arva2"
18 DOMAIN="arv.local"
19
20 INITIAL_USER="admin"
21
22 # If not specified, the initial user email will be composed as
23 # INITIAL_USER@CLUSTER.DOMAIN
24 INITIAL_USER_EMAIL="${INITIAL_USER}@${CLUSTER}.${DOMAIN}"
25 INITIAL_USER_PASSWORD="password"
26
27 # The example config you want to use. Currently, only "single_host" is
28 # available
29 CONFIG_DIR="single_host"
30
31 # Which release of Arvados repo you want to use
32 RELEASE="production"
33 # Which version of Arvados you want to install. Defaults to 'latest'
34 # in the desired repo
35 VERSION="latest"
36
37 # Host SSL port where you want to point your browser to access Arvados
38 # Defaults to 443 for regular runs, and to 8443 when called in Vagrant.
39 # You can point it to another port if desired
40 # In Vagrant, make sure it matches what you set in the Vagrantfile
41 # HOST_SSL_PORT=443
42
43 # This is a arvados-formula setting.
44 # If branch is set, the script will switch to it before running salt
45 # Usually not needed, only used for testing
46 # BRANCH="master"
47
48 ##########################################################
49 # Usually there's no need to modify things below this line
50
51 # Formulas versions
52 POSTGRES_TAG="v0.41.3"
53 NGINX_TAG="v2.4.0"
54 DOCKER_TAG="v1.0.0"
55 LOCALE_TAG="v0.3.4"
56
57 set -o pipefail
58
59 # capture the directory that the script is running from
60 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
61
62 usage() {
63   echo >&2
64   echo >&2 "Usage: ${0} [-h] [-h]"
65   echo >&2
66   echo >&2 "${0} options:"
67   echo >&2 "  -d, --debug             Run salt installation in debug mode"
68   echo >&2 "  -p <N>, --ssl-port <N>  SSL port to use for the web applications"
69   echo >&2 "  -t, --test              Test installation running a CWL workflow"
70   echo >&2 "  -h, --help              Display this help and exit"
71   echo >&2 "  -v, --vagrant           Run in vagrant and use the /vagrant shared dir"
72   echo >&2
73 }
74
75 arguments() {
76   # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
77   TEMP=$(getopt -o dhp:tv \
78     --long debug,help,ssl-port:,test,vagrant \
79     -n "${0}" -- "${@}")
80
81   if [ ${?} != 0 ] ; then echo "GNU getopt missing? Use -h for help"; exit 1 ; fi
82   # Note the quotes around `$TEMP': they are essential!
83   eval set -- "$TEMP"
84
85   while [ ${#} -ge 1 ]; do
86     case ${1} in
87       -d | --debug)
88         LOG_LEVEL="debug"
89         shift
90         ;;
91       -t | --test)
92         TEST="yes"
93         shift
94         ;;
95       -v | --vagrant)
96         VAGRANT="yes"
97         shift
98         ;;
99       -p | --ssl-port)
100         HOST_SSL_PORT=${2}
101         shift 2
102         ;;
103       --)
104         shift
105         break
106         ;;
107       *)
108         usage
109         exit 1
110         ;;
111     esac
112   done
113 }
114
115 LOG_LEVEL="info"
116 HOST_SSL_PORT=443
117 TESTS_DIR="tests"
118
119 arguments ${@}
120
121 # Salt's dir
122 ## states
123 S_DIR="/srv/salt"
124 ## formulas
125 F_DIR="/srv/formulas"
126 ##pillars
127 P_DIR="/srv/pillars"
128
129 apt-get update
130 apt-get install -y curl git jq
131
132 dpkg -l |grep salt-minion
133 if [ ${?} -eq 0 ]; then
134   echo "Salt already installed"
135 else
136   curl -L https://bootstrap.saltstack.com -o /tmp/bootstrap_salt.sh
137   sh /tmp/bootstrap_salt.sh -XUdfP -x python3
138   /bin/systemctl disable salt-minion.service
139 fi
140
141 # Set salt to masterless mode
142 cat > /etc/salt/minion << EOFSM
143 file_client: local
144 file_roots:
145   base:
146     - ${S_DIR}
147     - ${F_DIR}/*
148     - ${F_DIR}/*/test/salt/states/examples
149
150 pillar_roots:
151   base:
152     - ${P_DIR}
153 EOFSM
154
155 mkdir -p ${S_DIR}
156 mkdir -p ${F_DIR}
157 mkdir -p ${P_DIR}
158
159 # States
160 cat > ${S_DIR}/top.sls << EOFTSLS
161 base:
162   '*':
163     - single_host.host_entries
164     - single_host.snakeoil_certs
165     - locale
166     - nginx.passenger
167     - postgres
168     - docker
169     - arvados
170 EOFTSLS
171
172 # Pillars
173 cat > ${P_DIR}/top.sls << EOFPSLS
174 base:
175   '*':
176     - arvados
177     - docker
178     - locale
179     - nginx_api_configuration
180     - nginx_controller_configuration
181     - nginx_keepproxy_configuration
182     - nginx_keepweb_configuration
183     - nginx_passenger
184     - nginx_websocket_configuration
185     - nginx_webshell_configuration
186     - nginx_workbench2_configuration
187     - nginx_workbench_configuration
188     - postgresql
189 EOFPSLS
190
191 # Get the formula and dependencies
192 cd ${F_DIR} || exit 1
193 git clone https://github.com/saltstack-formulas/arvados-formula.git
194 git clone --branch "${DOCKER_TAG}" https://github.com/saltstack-formulas/docker-formula.git
195 git clone --branch "${LOCALE_TAG}" https://github.com/saltstack-formulas/locale-formula.git
196 git clone --branch "${NGINX_TAG}" https://github.com/saltstack-formulas/nginx-formula.git
197 git clone --branch "${POSTGRES_TAG}" https://github.com/saltstack-formulas/postgres-formula.git
198
199 if [ "x${BRANCH}" != "x" ]; then
200   cd ${F_DIR}/arvados-formula || exit 1
201   git checkout -t origin/"${BRANCH}"
202   cd -
203 fi
204
205 if [ "x${VAGRANT}" = "xyes" ]; then
206   SOURCE_PILLARS_DIR="/vagrant/${CONFIG_DIR}"
207   TESTS_DIR="/vagrant/${TESTS_DIR}"
208 else
209   SOURCE_PILLARS_DIR="${SCRIPT_DIR}/${CONFIG_DIR}"
210   TESTS_DIR="${SCRIPT_DIR}/${TESTS_DIR}"
211 fi
212
213 # Replace cluster and domain name in the example pillars and test files
214 for f in "${SOURCE_PILLARS_DIR}"/*; do
215   sed "s/__CLUSTER__/${CLUSTER}/g;
216        s/__DOMAIN__/${DOMAIN}/g;
217        s/__RELEASE__/${RELEASE}/g;
218        s/__HOST_SSL_PORT__/${HOST_SSL_PORT}/g;
219        s/__GUEST_SSL_PORT__/${GUEST_SSL_PORT}/g;
220        s/__INITIAL_USER__/${INITIAL_USER}/g;
221        s/__INITIAL_USER_EMAIL__/${INITIAL_USER_EMAIL}/g;
222        s/__INITIAL_USER_PASSWORD__/${INITIAL_USER_PASSWORD}/g;
223        s/__VERSION__/${VERSION}/g" \
224   "${f}" > "${P_DIR}"/$(basename "${f}")
225 done
226
227 mkdir -p /tmp/cluster_tests
228 # Replace cluster and domain name in the example pillars and test files
229 for f in "${TESTS_DIR}"/*; do
230   sed "s/__CLUSTER__/${CLUSTER}/g;
231        s/__DOMAIN__/${DOMAIN}/g;
232        s/__HOST_SSL_PORT__/${HOST_SSL_PORT}/g;
233        s/__INITIAL_USER__/${INITIAL_USER}/g;
234        s/__INITIAL_USER_EMAIL__/${INITIAL_USER_EMAIL}/g;
235        s/__INITIAL_USER_PASSWORD__/${INITIAL_USER_PASSWORD}/g" \
236   ${f} > /tmp/cluster_tests/$(basename ${f})
237 done
238 chmod 755 /tmp/cluster_tests/run-test.sh
239
240 # FIXME! #16992 Temporary fix for psql call in arvados-api-server
241 if [ -e /root/.psqlrc ]; then
242   if ! ( grep 'pset pager off' /root/.psqlrc ); then
243     RESTORE_PSQL="yes"
244     cp /root/.psqlrc /root/.psqlrc.provision.backup
245   fi
246 else
247   DELETE_PSQL="yes"
248 fi
249
250 echo '\pset pager off' >> /root/.psqlrc
251 # END FIXME! #16992 Temporary fix for psql call in arvados-api-server
252
253 # Now run the install
254 salt-call --local state.apply -l ${LOG_LEVEL}
255
256 # FIXME! #16992 Temporary fix for psql call in arvados-api-server
257 if [ "x${DELETE_PSQL}" = "xyes" ]; then
258   echo "Removing .psql file"
259   rm /root/.psqlrc
260 fi
261
262 if [ "x${RESTORE_PSQL}" = "xyes" ]; then
263   echo "Restoring .psql file"
264   mv -v /root/.psqlrc.provision.backup /root/.psqlrc
265 fi
266 # END FIXME! #16992 Temporary fix for psql call in arvados-api-server
267
268 # Leave a copy of the Arvados CA so the user can copy it where it's required
269 echo "Copying the Arvados CA certificate to the installer dir, so you can import it"
270 # If running in a vagrant VM, also add default user to docker group
271 if [ "x${VAGRANT}" = "xyes" ]; then
272   cp /etc/ssl/certs/arvados-snakeoil-ca.pem /vagrant
273
274   echo "Adding the vagrant user to the docker group"
275   usermod -a -G docker vagrant
276 else
277   cp /etc/ssl/certs/arvados-snakeoil-ca.pem ${SCRIPT_DIR}
278 fi
279
280 # Test that the installation finished correctly
281 if [ "x${TEST}" = "xyes" ]; then
282   cd /tmp/cluster_tests
283   ./run-test.sh
284 fi