File size: 2,142 Bytes
45361be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash

# Copyright (c) 2023 Habana Labs, Ltd. an Intel Company.Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

#     http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

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