Skip to content

Commit

Permalink
chore(deployment): spruce up scripts with some Node and ShellCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Nov 30, 2021
1 parent 1791164 commit aa551d6
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 89 deletions.
70 changes: 70 additions & 0 deletions packages/deployment/scripts/docker-deployment.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#! /usr/bin/env node
/* global process */
// Get a deployment.json for a 2-node docker setup.

const DEFAULT_NUM_VALIDATORS = 2;
const DEFAULT_NETWORK_NAME = 'localtest';

const NUM_VALIDATORS = process.argv[2] || DEFAULT_NUM_VALIDATORS;

const NETWORK_NAME = process.env.NETWORK_NAME || DEFAULT_NETWORK_NAME;

// Add in DOCKER_VOLUMES=host_path:container_path,host_path2:container_path2,...
const ADD_VOLUMES = (process.env.DOCKER_VOLUMES || '')
.split(',')
.flatMap(volumeSpec => {
const splitVolumeSpec = volumeSpec.split(':');
if (splitVolumeSpec.length < 2) {
// No specification found.
return [];
}

const [hostPath, ...rest] = splitVolumeSpec;
return [
{
host_path: hostPath,
container_path: rest.join(':'),
},
];
});

const deployment = {
PLACEMENTS: [
[
'docker1',
{
default: 2,
},
],
],
PLACEMENT_PROVIDER: {
docker1: 'docker',
},
SSH_PRIVATE_KEY_FILE: 'id_ecdsa',
DETAILS: {
VOLUMES: {
docker1: [
{
host_path: '/sys/fs/cgroup',
container_path: '/sys/fs/cgroup',
},
...ADD_VOLUMES,
],
},
},
OFFSETS: {
docker1: 0,
},
ROLES: {
docker1: 'validator',
},
DATACENTERS: {
docker1: new Array(NUM_VALIDATORS).fill('default'),
},
PROVIDER_NEXT_INDEX: {
docker: 1,
},
NETWORK_NAME,
};

process.stdout.write(`${JSON.stringify(deployment, null, 2)}\n`);
59 changes: 0 additions & 59 deletions packages/deployment/scripts/docker-deployment.sh

This file was deleted.

48 changes: 28 additions & 20 deletions packages/deployment/scripts/install-deps.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
#! /bin/bash
set -e
set -ueo pipefail

# Install Terraform.
TERRAFORM_VERSION=0.11.14

UNAME_S=$(uname -s | tr A-Z a-z)
uname_s=$(uname -s | tr '[:upper:]' '[:lower:]')

case $UNAME_S in
*) TERRAFORM_OS=$UNAME_S ;;
case $uname_s in
*) TERRAFORM_OS=$uname_s ;;
esac

UNAME_M=$(uname -m)
case $UNAME_M in
uname_m=$(uname -m)
case $uname_m in
x86_64) TERRAFORM_ARCH=amd64 ;;
*) TERRAFORM_ARCH=$UNAME_M ;;
*) TERRAFORM_ARCH=$uname_m ;;
esac

TERRAFORM_RELEASE=terraform_${TERRAFORM_VERSION}_${TERRAFORM_OS}_${TERRAFORM_ARCH}
curl https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/${TERRAFORM_RELEASE}.zip > terraform.zip && \
unzip -od /usr/local/bin/ terraform.zip && rm -f terraform.zip
TERRAFORM_URL=https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/${TERRAFORM_RELEASE}.zip

# Extract, then delete temporary file.
(
terraform_zip=$(mktemp -t terraform)
trap "rm -f \"\$terraform_zip\"" EXIT
echo "$terraform_zip"
exit 1
curl "$TERRAFORM_URL" > "$terraform_zip"
unzip -od /usr/local/bin/ "$terraform_zip"
)

# Install Ansible.
if test -d /etc/apt; then
# Install Ansible.
echo 'deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main' >> /etc/apt/sources.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 && \
apt-get update --allow-releaseinfo-change -y && \
apt-get install -y ansible rsync curl sudo gnupg2 jq && \
apt-get clean -y
elif test "$UNAME_S" == darwin; then
# Install Ansible.
brew update && \
brew install ansible rsync curl gnupg2 jq && \
brew cleanup
echo 'deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main' >> /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
apt-get update --allow-releaseinfo-change -y
apt-get install -y ansible rsync curl sudo gnupg2 jq
apt-get clean -y
elif test "$uname_s" == darwin; then
brew update
brew install ansible rsync curl gnupg2 jq
brew cleanup
else
echo "Don't know how to install Ansible, so I'm skipping..."
exit 1
Expand Down
11 changes: 8 additions & 3 deletions packages/deployment/scripts/integration-test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /bin/bash
set -e
set -ueo pipefail

real0=$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")
thisdir=$(cd "$(dirname -- "$real0")" > /dev/null && pwd -P)
Expand All @@ -11,5 +11,10 @@ cd "$NETWORK_NAME/setup"

# Speed up the docker deployment by pre-mounting /usr/src/agoric-sdk.
DOCKER_VOLUMES="$(cd "$thisdir/../../.." > /dev/null && pwd -P):/usr/src/agoric-sdk" \
"$thisdir/docker-deployment.sh" > deployment.json
exec "$thisdir/setup.sh" --force-init bootstrap ${1+"$@"}
"$thisdir/docker-deployment.cjs" > deployment.json

# Set up the network from our above deployment.json.
"$thisdir/setup.sh" init --noninteractive

# Go ahead and bootstrap.
exec "$thisdir/setup.sh" bootstrap ${1+"$@"}
9 changes: 2 additions & 7 deletions packages/deployment/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! /bin/bash
set -e
# setup.sh - Run the local ag-setup-cosmos with arguments
set -ueo pipefail

real0=$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")
thisdir=$(cd "$(dirname -- "$real0")" > /dev/null && pwd -P)
Expand All @@ -13,11 +14,5 @@ export AG_SETUP_COSMOS_HOME="$PWD"
# Put our bindir into the PATH so that children can find ag-setup-cosmos.
export PATH="$thisdir/../bin:$PATH"

if test "$1" == --force-init; then
shift
# Set up the network.
ag-setup-cosmos init --noninteractive
fi

# Run our setup command.
exec ag-setup-cosmos ${1+"$@"}

0 comments on commit aa551d6

Please sign in to comment.