mirror of
https://github.com/jpetazzo/container.training.git
synced 2026-07-28 09:11:18 +00:00
Each time we call that script, we must set a few env vars beforehand. Let's make these vars optional parameters to the script instead. Also add helper scripts to list the locations (zones or regions) available to each provider.
76 lines
2.0 KiB
Bash
Executable File
76 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
|
set -e
|
|
|
|
TIME=$(which time)
|
|
|
|
if [ -f ~/.config/doctl/config.yaml ]; then
|
|
export DIGITALOCEAN_ACCESS_TOKEN=$(grep ^access-token ~/.config/doctl/config.yaml | cut -d: -f2 | tr -d " ")
|
|
fi
|
|
|
|
if [ -f ~/.config/linode-cli ]; then
|
|
export LINODE_TOKEN=$(grep ^token ~/.config/linode-cli | cut -d= -f2 | tr -d " ")
|
|
fi
|
|
|
|
[ "$1" ] || {
|
|
echo "Syntax:"
|
|
echo ""
|
|
echo "$0 <provider> <region> [how-many-clusters] [min-nodes] [max-nodes]"
|
|
echo ""
|
|
echo "Available providers:"
|
|
ls -1 source/modules
|
|
echo ""
|
|
echo "Leave the region empty to show available regions for this provider."
|
|
echo "You can also specify ALL as a provider to simultaneously provision"
|
|
echo "many clusters on *each* provider for benchmarking purposes."
|
|
echo ""
|
|
exit 1
|
|
}
|
|
|
|
PROVIDER="$1"
|
|
export TF_VAR_location="$2"
|
|
export TF_VAR_how_many_clusters="${3-1}"
|
|
export TF_VAR_min_nodes_per_pool="${4-2}"
|
|
export TF_VAR_max_nodes_per_pool="${5-4}"
|
|
|
|
[ "$TF_VAR_location" ] || {
|
|
"./source/modules/$PROVIDER/list_locations.sh"
|
|
exit 1
|
|
}
|
|
|
|
[ "$TAG" ] || {
|
|
TIMESTAMP=$(date +%Y-%m-%d-%H-%M-%S)
|
|
RANDOMTAG=$(base64 /dev/urandom | tr A-Z a-z | tr -d /+ | head -c5)
|
|
export TAG=tag-$TIMESTAMP-$RANDOMTAG
|
|
}
|
|
|
|
[ "$PROVIDER" = "ALL" ] && {
|
|
for PROVIDER in $(ls -1 source/modules); do
|
|
$TERMINAL -T $TAG-$PROVIDER -e sh -c "
|
|
export TAG=$TAG-$PROVIDER
|
|
$0 $PROVIDER
|
|
cd $TAG-$PROVIDER
|
|
bash
|
|
" &
|
|
done
|
|
exit 0
|
|
}
|
|
|
|
[ -d "source/modules/$PROVIDER" ] || {
|
|
echo "Provider '$PROVIDER' not found."
|
|
echo "Available providers:"
|
|
ls -1 source/modules
|
|
exit 1
|
|
}
|
|
|
|
export LINODE_TOKEN=$(grep ^token ~/.config/linode-cli | cut -d= -f2 | tr -d " ")
|
|
export DIGITALOCEAN_ACCESS_TOKEN=$(grep ^access-token ~/.config/doctl/config.yaml | cut -d: -f2 | tr -d " ")
|
|
|
|
cp -a source $TAG
|
|
cd $TAG
|
|
cp -r modules/$PROVIDER modules/PROVIDER
|
|
$TIME -o time.1.init terraform init
|
|
$TIME -o time.2.stage1 terraform apply -auto-approve
|
|
cd stage2
|
|
$TIME -o ../time.3.init terraform init
|
|
$TIME -o ../time.4.stage2 terraform apply -auto-approve
|