feat(docs): salt install documentation
[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 # The 5 letters name you want to give your cluster
15 CLUSTER="arva2"
16 DOMAIN="arv.local"
17
18 # Which release of Arvados repo you want to use
19 RELEASE="production"
20 # Which version of Arvados you want to install. Defaults to 'latest'
21 # in the desired repo
22 # VERSION="2.0.4"
23
24 # This is a arvados-formula setting. 
25 # If branch is set, the script will switch to it before running salt
26 # Usually not needed, only used for testing
27 # BRANCH="master"
28
29 ##########################################################
30 # Usually there's no need to modify things below this line
31
32 # Salt's dir
33 ## states
34 S_DIR="/srv/salt"
35 ## formulas
36 F_DIR="/srv/formulas"
37 ##pillars
38 P_DIR="/srv/pillars"
39 # In vagrant, we can use the shared dir
40 # P_DIR="/vagrant/salt_pillars"
41
42 sudo apt-get update
43 sudo apt-get install -y curl git
44
45 dpkg -l |grep salt-minion
46 if [ ${?} -eq 0 ]; then
47   echo "Salt already installed"
48 else
49   curl -L https://bootstrap.saltstack.com -o /tmp/bootstrap_salt.sh
50   sudo sh /tmp/bootstrap_salt.sh -XUdfP -x python3
51   sudo /bin/systemctl disable salt-minion.service
52 fi
53
54 # Set salt to masterless mode
55 cat > /etc/salt/minion << EOFSM
56 file_client: local
57 file_roots:
58   base:
59     - ${S_DIR}
60     - ${F_DIR}/*
61     - ${F_DIR}/*/test/salt/states
62
63 pillar_roots:
64   base:
65     - ${P_DIR}
66 EOFSM
67
68 mkdir -p ${S_DIR}
69 mkdir -p ${F_DIR}
70 mkdir -p ${P_DIR}
71
72 # States
73 cat > ${S_DIR}/top.sls << EOFTSLS
74 base:
75   '*':
76     - example_add_snakeoil_certs
77     - locale
78     - nginx.passenger
79     - postgres
80     - docker
81     - arvados
82 EOFTSLS
83
84 # Pillars
85 cat > ${P_DIR}/top.sls << EOFPSLS
86 base:
87   '*':
88     - arvados
89     - locale
90     - nginx_api_configuration
91     - nginx_controller_configuration
92     - nginx_keepproxy_configuration
93     - nginx_keepweb_configuration
94     - nginx_passenger
95     - nginx_websocket_configuration
96     - nginx_webshell_configuration
97     - nginx_workbench2_configuration
98     - nginx_workbench_configuration
99     - postgresql
100 EOFPSLS
101
102
103 # Get the formula and dependencies
104 cd ${F_DIR} || exit 1
105 for f in postgres arvados nginx docker locale; do
106   git clone https://github.com/saltstack-formulas/${f}-formula.git
107 done
108
109 if [ "x${BRANCH}" != "x" ]; then
110   cd ${F_DIR}/arvados-formula
111   git checkout -t origin/${BRANCH}
112   cd -
113 fi
114
115 sed "s/example.net/${DOMAIN}/g; s/fixme/${CLUSTER}/g; s/release: development/release: ${RELEASE}/g; s/# version: '2.0.4'/version: '${VERSION}'/g" \
116   ${F_DIR}/arvados-formula/test/salt/pillar/arvados_dev.sls > ${P_DIR}/arvados.sls
117
118 # Replace cluster and domain name in the example pillars
119 for f in ${F_DIR}/arvados-formula/test/salt/pillar/examples/*; do
120   sed "s/example.net/${DOMAIN}/g; s/fixme/${CLUSTER}/g" \
121   ${f} > ${P_DIR}/$(basename ${f})
122 done
123
124 # Let's write a /etc/hosts file that points all the hosts to localhost
125
126 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
127
128 # Now run the install
129 salt-call --local state.apply -l debug