3 # Copyright (C) The Arvados Authors. All rights reserved.
5 # SPDX-License-Identifier: CC-BY-SA-3.0
10 # Helps manage the configuration in a git repository, and then deploy
11 # nodes by pushing a copy of the git repository to each node and
12 # running the provision script to do the actual installation and
19 declare CONFIG_FILE=local.params
21 # The salt template directory
22 declare CONFIG_DIR=local_config_dir
24 # The 5-character Arvados cluster id
25 # This will be populated by loadconfig()
28 # The parent domain (not including the cluster id)
29 # This will be populated by loadconfig()
32 # A bash associative array listing each node and mapping to the roles
33 # that should be provisioned on those nodes.
34 # This will be populated by loadconfig()
37 # The ssh user we'll use
38 # This will be populated by loadconfig()
41 # The git repository that we'll push to on all the nodes
42 # This will be populated by loadconfig()
52 if [[ -n "$MISSING" ]] ; then
53 echo "Some tools are missing, please make sure you have the 'git' and 'iproute2' packages installed"
62 # Synchronizes the configuration by creating a git repository on
63 # each node, pushing our branch, and updating the checkout.
65 if [[ "$NODE" != localhost ]] ; then
66 if ! ssh $DEPLOY_USER@$NODE test -d ${GITTARGET}.git ; then
68 # Initialize the git repository (1st time case). We're
69 # actually going to make two repositories here because git
70 # will complain if you try to push to a repository with a
71 # checkout. So we're going to create a "bare" repository
72 # and then clone a regular repository (with a checkout)
75 ssh $DEPLOY_USER@$NODE git init --bare ${GITTARGET}.git
76 if ! git remote add $NODE $DEPLOY_USER@$NODE:${GITTARGET}.git ; then
77 git remote set-url $NODE $DEPLOY_USER@$NODE:${GITTARGET}.git
79 git push $NODE $BRANCH
80 ssh $DEPLOY_USER@$NODE git clone ${GITTARGET}.git ${GITTARGET}
85 # Push to the bare repository on the remote node, then in the
86 # remote node repository with the checkout, pull the branch
87 # from the bare repository.
89 git push $NODE $BRANCH
90 ssh $DEPLOY_USER@$NODE "git -C ${GITTARGET} checkout ${BRANCH} && git -C ${GITTARGET} pull"
98 # Deploy a node. This runs the provision script on the node, with
99 # the appropriate roles.
101 if [[ -z "$ROLES" ]] ; then
102 echo "No roles specified for $NODE, will deploy all roles"
104 ROLES="--roles ${ROLES}"
107 logfile=deploy-${NODE}-$(date -Iseconds).log
109 if [[ "$NODE" = localhost ]] ; then
111 if [[ $(whoami) != 'root' ]] ; then
114 $SUDO ./provision.sh --config ${CONFIG_FILE} ${ROLES} 2>&1 | tee $logfile
116 ssh $DEPLOY_USER@$NODE "cd ${GITTARGET} && sudo ./provision.sh --config ${CONFIG_FILE} ${ROLES}" 2>&1 | tee $logfile
121 if [[ ! -s $CONFIG_FILE ]] ; then
122 echo "Must be run from initialized setup dir, maybe you need to 'initialize' first?"
124 source ${CONFIG_FILE}
125 GITTARGET=arvados-deploy-config-${CLUSTER}
132 if [[ -n "$subcmd" ]] ; then
137 if [[ ! -f provision.sh ]] ; then
138 echo "Must be run from arvados/tools/salt-install"
152 if [[ -z "$PARAMS" || ! -f local.params.example.$PARAMS ]] ; then
153 echo "Not found: local.params.example.$PARAMS"
154 echo "Expected one of multiple_hosts, single_host_multiple_hostnames, single_host_single_hostname"
158 if [[ -z "$SLS" || ! -d config_examples/$SLS ]] ; then
159 echo "Not found: config_examples/$SLS"
160 echo "Expected one of multi_host/aws, single_host/multiple_hostnames, single_host/single_hostname"
164 if [[ -z "$SETUPDIR" || -z "$PARAMS" || -z "$SLS" ]]; then
165 echo "installer.sh <setup dir to initialize> <params template> <config template>"
169 if [[ -n "$err" ]] ; then
173 echo "Initializing $SETUPDIR"
175 cp -r *.sh tests $SETUPDIR
177 cp local.params.example.$PARAMS $SETUPDIR/${CONFIG_FILE}
178 cp -r config_examples/$SLS $SETUPDIR/${CONFIG_DIR}
180 if [[ -n "$TERRAFORM" ]] ; then
181 mkdir $SETUPDIR/terraform
182 cp -r $TERRAFORM/* $SETUPDIR/terraform/
186 echo '*.log' > .gitignore
188 git add *.sh ${CONFIG_FILE} ${CONFIG_DIR} tests .gitignore
189 git commit -m"initial commit"
192 echo "Setup directory $SETUPDIR initialized."
193 if [[ -n "$TERRAFORM" ]] ; then
194 (cd $SETUPDIR/terraform/vpc && terraform init)
195 (cd $SETUPDIR/terraform/data-storage && terraform init)
196 (cd $SETUPDIR/terraform/services && terraform init)
197 echo "Now go to $SETUPDIR, customize 'terraform/vpc/terraform.tfvars' as needed, then run 'installer.sh terraform'"
199 echo "Now go to $SETUPDIR, customize '${CONFIG_FILE}' and '${CONFIG_DIR}' as needed, then run 'installer.sh deploy'"
204 logfile=terraform-$(date -Iseconds).log
205 (cd terraform/vpc && terraform apply) 2>&1 | tee -a $logfile
206 (cd terraform/data-storage && terraform apply) 2>&1 | tee -a $logfile
207 (cd terraform/services && terraform apply) 2>&1 | tee -a $logfile
211 for i in BLOB_SIGNING_KEY MANAGEMENT_TOKEN SYSTEM_ROOT_TOKEN ANONYMOUS_USER_TOKEN WORKBENCH_SECRET_KEY DATABASE_PASSWORD; do
212 echo ${i}=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 32 ; echo '')
225 if grep -rni 'fixme' ${CONFIG_FILE} ${CONFIG_DIR} ; then
227 echo "Some parameters still need to be updated. Please fix them and then re-run deploy."
231 BRANCH=$(git branch --show-current)
236 if ! git diff --cached --exit-code ; then
237 git commit -m"prepare for deploy"
240 if [[ -z "$NODE" ]]; then
241 for NODE in "${!NODES[@]}"
243 # First, push the git repo to each node. This also
244 # confirms that we have git and can log into each
249 for NODE in "${!NODES[@]}"
251 # Do 'database' role first,
252 if [[ "${NODES[$NODE]}" =~ database ]] ; then
253 deploynode $NODE "${NODES[$NODE]}"
258 for NODE in "${!NODES[@]}"
260 # then 'api' or 'controller' roles
261 if [[ "${NODES[$NODE]}" =~ (api|controller) ]] ; then
262 deploynode $NODE "${NODES[$NODE]}"
267 for NODE in "${!NODES[@]}"
269 # Everything else (we removed the nodes that we
270 # already deployed from the list)
271 deploynode $NODE "${NODES[$NODE]}"
274 # Just deploy the node that was supplied on the command line.
281 echo "Completed deploy, run 'installer.sh diagnostics' to verify the install"
292 if ! which arvados-client ; then
293 echo "arvados-client not found, install 'arvados-client' package with 'apt-get' or 'yum'"
297 if [[ -z "$LOCATION" ]] ; then
298 echo "Need to provide '-internal-client' or '-external-client'"
300 echo "-internal-client You are running this on the same private network as the Arvados cluster (e.g. on one of the Arvados nodes)"
301 echo "-external-client You are running this outside the private network of the Arvados cluster (e.g. your workstation)"
305 export ARVADOS_API_HOST="${CLUSTER}.${DOMAIN}:${CONTROLLER_EXT_SSL_PORT}"
306 export ARVADOS_API_TOKEN="$SYSTEM_ROOT_TOKEN"
308 arvados-client diagnostics $LOCATION
312 echo "Arvados installer"
314 echo "initialize initialize the setup directory for configuration"
315 echo "terraform create cloud resources using terraform"
316 echo "generate-tokens generate random values for tokens"
317 echo "deploy deploy the configuration from the setup directory"
318 echo "diagnostics check your install using diagnostics"