|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SOURCE_DIR="$(cd "$(dirname "$0")" && pwd)" |
|
source $SOURCE_DIR/config.properties |
|
|
|
export PDSH_RCMD_TYPE=ssh |
|
|
|
HOSTFILE="${HOSTFILE:-$SOURCE_DIR/hostfile}"; |
|
BASE_PDSH_CMD="pdsh -w ^$HOSTFILE \ |
|
export DOCKER_BUILDKIT=1; \ |
|
export $( cat $SOURCE_DIR/config.properties | grep -v "^#" | xargs ); " |
|
DOCKER_COMPOSE_PATH="$DOCKER_DIR/docker-compose.yml" |
|
BASE_DOCKER_CMD="$BASE_PDSH_CMD docker compose -f $DOCKER_COMPOSE_PATH" |
|
|
|
show_help() |
|
{ |
|
cat <<EOF |
|
Usage: ./control_containers.sh [-b] [-u] [-d] [-r] [-h] |
|
-b ...... Build image based on local Dockerfile |
|
-u ...... Bring Containers Up |
|
-d ...... Bring Containers Down |
|
-r ...... Restart Containers |
|
-h ...... Optional; show help |
|
This script runs docker compose commands to handle mutli-node configurations. |
|
|
|
Requirements: |
|
- pdsh |
|
- docker compose |
|
- Dockerfile to build |
|
EOF |
|
} |
|
|
|
build_image() |
|
{ |
|
echo "Building Docker Images" |
|
$BASE_DOCKER_CMD build |
|
} |
|
|
|
up_containers() |
|
{ |
|
echo "Brining Docker Containers Up" |
|
$BASE_DOCKER_CMD up -d |
|
} |
|
|
|
down_containers() |
|
{ |
|
echo "Brining Docker Containers down" |
|
$BASE_DOCKER_CMD down |
|
} |
|
|
|
|
|
restart_containers() |
|
{ |
|
echo "Restarting Docker Containers" |
|
$BASE_DOCKER_CMD restart |
|
} |
|
|
|
eval "$(ssh-agent -s)" > /dev/null |
|
ssh-add "$SOURCE_DIR/ssh/mint_rsa" > /dev/null |
|
|
|
while getopts budrh flag |
|
do |
|
case "${flag}" in |
|
b) build_image ;; |
|
u) up_containers ;; |
|
d) down_containers ;; |
|
r) restart_containers ;; |
|
h) show_help >&2; exit 0 ;; |
|
*) show_help >&2; exit 0 ;; |
|
esac |
|
done |
|
|
|
|