fix(salt): choose repo
[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 # This could have been done with the Salt vagrant provisioner, but this script
14 # can be used in environments other than vagrant.
15
16 # If branch is set, the script will switch to it before running salt
17 BRANCH="refactor-config-add-service"
18 RELEASE="testing"
19
20 CLUSTER="arva2"
21 DOMAIN="arv.local"
22
23 # Salt's dir
24 ## states
25 S_DIR="/srv/salt"
26 ## formulas
27 F_DIR="/srv/formulas"
28 ##pillars
29 P_DIR="/srv/pillars"
30 # In vagrant, we can use the shared dir
31 # P_DIR="/vagrant/salt_pillars"
32
33 sudo apt-get update
34 sudo apt-get install -y curl git
35
36 dpkg -l |grep salt-minion
37 if [ ${?} -eq 0 ]; then
38   echo "Salt already installed"
39 else
40   curl -L https://bootstrap.saltstack.com -o /tmp/bootstrap_salt.sh
41   sudo sh /tmp/bootstrap_salt.sh -XUdfP -x python3
42   sudo /bin/systemctl disable salt-minion.service
43 fi
44
45 # Set salt to masterless mode
46 cat > /etc/salt/minion << EOFSM
47 file_client: local
48 file_roots:
49   base:
50     - ${S_DIR}
51     - ${F_DIR}/*
52     - ${F_DIR}/*/test/salt/states
53
54 pillar_roots:
55   base:
56     - ${P_DIR}
57 EOFSM
58
59 mkdir -p ${S_DIR}
60 mkdir -p ${F_DIR}
61 mkdir -p ${P_DIR}
62
63 cat > ${S_DIR}/top.sls << EOFTSLS
64 base:
65   '*':
66     - example_add_snakeoil_certs
67     - locale
68     - nginx.passenger
69     - postgres
70     - docker
71     - arvados
72 EOFTSLS
73
74 cat > ${P_DIR}/top.sls << EOFPSLS
75 base:
76   '*':
77     - arvados
78     - locale
79     - nginx_api_configuration
80     - nginx_controller_configuration
81     - nginx_keepproxy_configuration
82     - nginx_keepweb_configuration
83     - nginx_passenger
84     - nginx_websocket_configuration
85     - nginx_webshell_configuration
86     - nginx_workbench2_configuration
87     - nginx_workbench_configuration
88     - postgresql
89 EOFPSLS
90
91
92 # Get the formula and dependencies
93 cd ${F_DIR} || exit 1
94 for f in postgres arvados nginx docker locale; do
95   git clone https://github.com/netmanagers/${f}-formula.git
96 done
97
98 if [ "x${BRANCH}" != "x" ]; then
99   cd ${F_DIR}/arvados-formula
100   git checkout -t origin/${BRANCH}
101   cd -
102 fi
103
104 sed "s/example.net/${DOMAIN}/g; s/fixme/${CLUSTER}/g; s/release: development/release: ${RELEASE}/g" \
105   ${F_DIR}/arvados-formula/test/salt/pillar/arvados_dev.sls > ${P_DIR}/arvados.sls
106
107 # Replace cluster and domain name in the example pillars
108 for f in ${F_DIR}/arvados-formula/test/salt/pillar/examples/*; do
109   sed "s/example.net/${DOMAIN}/g; s/fixme/${CLUSTER}/g" \
110   ${f} > ${P_DIR}/$(basename ${f})
111 done
112
113 # # Copy arvados' pillar.example file to the pillars dir, so it's used
114 # sed "s/example.net/${DOMAIN}/g" ${F_DIR}/arvados-formula/pillar.example > ${P_DIR}/arvados.sls
115 #
116 # # Replace domain name in the example pillars
117 # for f in ${F_DIR}/arvados-formula/test/salt/pillar/examples/*; do
118 #   sed "s/example.net/${DOMAIN}/g" ${f} > ${P_DIR}/$(basename ${f})
119 # done
120 #
121 # Let's write a /etc/hosts file that points all the hosts to localhost
122
123 echo "127.0.0.2 api keep keep0 collections download ws workbench workbench2 ${CLUSTER}.${DOMAIN} api.${CLUSTER}.${DOMAIN} keep.${CLUSTER}.${DOMAIN} keep0.${CLUSTER}.${DOMAIN} collections.${CLUSTER}.${DOMAIN} download.${CLUSTER}.${DOMAIN} ws.${CLUSTER}.${DOMAIN} workbench.${CLUSTER}.${DOMAIN} workbench2.${CLUSTER}.${DOMAIN}" >> /etc/hosts
124
125 # FIXME! Test to see if arvados-api-server progresses without issues
126 cat > /root/.psqlrc << EOF
127 \pset pager off
128 EOF
129
130 # Now run the install
131 salt-call --local state.apply -l debug