|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +function echo_color { |
| 4 | + echo -e "\033[1m$1\033[0m" |
| 5 | +} |
| 6 | + |
| 7 | +# Require a command-line arg for the formation name |
| 8 | +if [ -z $1 ]; then |
| 9 | + echo usage: $0 [formation] |
| 10 | + exit 1 |
| 11 | +fi |
| 12 | +formation=$1 |
| 13 | + |
| 14 | +# Create a "static" formation, where nodes must be added manually |
| 15 | +deis formations:create $formation --flavor=static |
| 16 | + |
| 17 | +# Update the layer to SSH as "vagrant", and retrieve its SSH public key |
| 18 | +echo_color "Updating the runtime layer to SSH as \"vagrant\"..." |
| 19 | +ssh_key=$(deis layers:update $formation runtime --ssh_username=vagrant | |
| 20 | + grep -Eo '\"ssh_public_key\"\: \"(.*)\"' | cut -d\" -f4) |
| 21 | +authfile=.ssh/authorized_keys |
| 22 | +tmpfile=/tmp/authorized_keys.tmp |
| 23 | + |
| 24 | +# SSH into deis-node-1 and authorize the SSH public key |
| 25 | +echo_color "Adding the layer's public key to deis-node-1..." |
| 26 | +vagrant ssh deis-node-1 -c "echo $ssh_key|cat - $authfile > $tmpfile && mv $tmpfile $authfile" |
| 27 | + |
| 28 | +# Add deis-node-1 to the formation |
| 29 | +echo_color "Adding node deis-node-1 to formation and provisioning..." |
| 30 | +deis nodes:create $formation deis-node-1.local --layer=runtime |
| 31 | + |
| 32 | +# SSH into deis-node-2 and authorize the SSH public key |
| 33 | +echo_color "Adding the layer's public key to deis-node-2..." |
| 34 | +vagrant ssh deis-node-2 -c "echo $ssh_key|cat - $authfile > $tmpfile && mv $tmpfile $authfile" |
| 35 | + |
| 36 | +# Add deis-node-1 to the formation |
| 37 | +echo_color "Adding node deis-node-2 to formation and provisioning..." |
| 38 | +deis nodes:create $formation deis-node-2.local --layer=runtime |
| 39 | + |
| 40 | +echo_color "Done. Now run \"deis create --formation=$formation\" in your app repository." |
0 commit comments