-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcodeWatch
executable file
·29 lines (29 loc) · 1.21 KB
/
codeWatch
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
#/bin/sh
#监控如果新增目录,自动设置docker容器
set -e
cd /codeEnv
while true; do
for line in `cd ./code ; find * -maxdepth 0 -type d`; do
username=`echo $line | awk -F '.' '{print $1}'`
dir=`echo $line | awk -F '.' '{print $2}'`
#如果dir对应一个team下的镜像
if ([ ! -z $dir ] && [ -d "./team/$dir" ] ); then
#echo "$username-$dir"
#判断fig中是否存在
if [ -z $(cat fig.yml | grep $username$dir:) ]; then
#如果不存在容器
#读取镜像的fig.yml
container_name=$username$dir;
workdir="\/codeEnv\/code\/$username.$dir"
domain=`cat ./domain`
#替换变量
fig_content=`cat ./team/www/fig.yml | sed "s/{CONTAINER_NAME}/$container_name/g" | sed "s/{WORKDIR}/$workdir/g" | sed "s/{USERNAME}/$username/g" | sed "s/{DOMAIN}/$domain/g" | sed "s/{DIR}/$dir/g"`
#追加到fig.yml
sh -c "echo '$fig_content' >> ./fig.yml"
#运行容器
FIG_PROJECT_NAME=code fig run -d $container_name
fi
fi
done
sleep 2
done