-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathdockerfile.sh
executable file
·69 lines (60 loc) · 1.42 KB
/
dockerfile.sh
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
#!/bin/bash
set -eu
source scripts/.variables.sh
#生成dockerfile
gen(){
#程序名称
pname="$1_$2"
#模板
filename=./deployments/bin/"$pname"
swagger=./deployments/config/swagger/$1/$2/proto
#判断bin是否存在
if [ ! -d deployments/bin/"$pname" ];then
mkdir -p deployments/bin/"$pname"/proto
fi
#判断swagger存在复制到这个目录下面
if [ -d $swagger ];then
cp -r $swagger/ $filename
fi
#添加本地时区
#RUN set -xe && apk add --no-cache tzdata && cp -r -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cat>$filename/Dockerfile<<EOF
FROM alpine:3.5
RUN echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/main' > /etc/apk/repositories \
&& echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/community' >>/etc/apk/repositories \
&& apk update && apk add tzdata \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
ADD $pname /$pname
ADD proto/ /swagger
ADD sqlupdate/ /sqlupdate
RUN chmod +x /$pname
ENTRYPOINT [ "/$pname" ]
EOF
echo "生成dockerfile $pname"
}
#全部生成dockerfile
allgen() {
gen api backend
gen api frontend
gen srv user
gen srv socket
gen srv account
}
#判断如何build
case $1 in
alldf) echo "全部生成dockerfile"
allgen
;;
df) echo "生成dockerfile:"$2,$3
if [ -z $2 -o -z $3 ];then
echo "参数错误"
exit 2
fi
gen $2 $3
;;
*)
echo "生成dockerfile error"
exit 2
;;
esac