-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmisterio
executable file
·94 lines (74 loc) · 2.17 KB
/
misterio
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
86
87
88
89
90
91
#!/bin/bash
if [ "z$1" == "z" ]; then
cat <<EOF
Simple usage: misterio \{ apply \| up \| start \| down \}
Every docker compose command is supported
apply: make a build and an up
Mistery pick every role listed inside hosts/$HOSTNAME and process it
the role env file format is
<rolename>[@inst].env
where @inst can be used to have multiple instance on the same machine
The technology is based only on docker compose (no docker swarm)
Role specific use:
misterio --list
List all the roles
misterio --rolename \{ apply \| up \| start \| down \}
Apply a specific command to that role
EOF
exit 1
fi
if [ ! -z $MISTERIO_HOST_ALIAS ]; then
MISTERIO_HOST=$MISTERIO_HOST_ALIAS
else
MISTERIO_HOST=$HOSTNAME
fi
processRole(){
local role_env="$1"
shift 1
local role=$(basename $role_env)
local inst_re='(.*)@(.*).env'
if [[ $role =~ $inst_re ]]; then
MISTERIO_INST_NAME=${BASH_REMATCH[2]}
#echo MISTERIO_INST_PREFIX=$MISTERIO_INST_PREFIX
role_dir=roles/${BASH_REMATCH[1]}
else
unset MISTERIO_INST_NAME
role_dir=roles/${role//.env/}
fi
echo -e '\nEnv:' ${role_env//hosts/}
# set -x
cp ${role_env} ${role_dir}/.env || true
{ set +x; } 2>/dev/null
if [ "$#" == "1" -a "$1" == "apply" ] ; then
( cd $role_dir ; docker compose up --build -d || (echo FAILED $role on $HOSTNAME ) )
( cd $role_dir ; docker compose ps ; docker compose logs --tail 3 )
else
( cd $role_dir ; docker compose $* || (echo FAILED $role on $HOSTNAME ))
fi
{ set +x; } 2>/dev/null
# docker build 'https://github.com/elastic/dockerfiles.git#v6.8.10:elasticsearch'
}
case $1 in
--list)
echo Roles for $MISTERIO_HOST
for role_env in hosts/$MISTERIO_HOST/*.env ; do
role=$(basename $role_env)
echo ${role//.env/}
done
;;
--*)
opt="$1"
shift 1
single_role=${opt//--/}
# echo $single_role
processRole hosts/$MISTERIO_HOST/${single_role}.env $*
;;
*)
set -e
# set -v
cd $(dirname $0)
for role_env in hosts/$MISTERIO_HOST/*.env ; do
processRole $role_env $*
done
;;
esac