-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.sh
139 lines (125 loc) · 3.41 KB
/
common.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
docker_service_ip=172.17.0.1
enableNodeDockerfileInclude=1
setDockerMachineEnv() {
name=$1
if [ "x" != "x`command -v docker-machine`" ]; then
eval $(docker-machine env $name)
ip=`docker-machine ip $name`
return
fi
ip="172.17.0.1"
}
getDefaultVolume() {
volume="-v /www:/www"
}
docker_my_init() {
imageName=`echo $imageName | tr '[:upper:]' '[:lower:]'`
}
build() {
docker_my_init
if [ "x1" == "x$enableNodeDockerfileInclude" ]; then
dockerfile-include -i $dockerfile -o Dockerfile
fi
ARCH_NAME="x64"
if [ ! -z $ARCH ] && [ $ARCH == "arm64" ];then
ARCH_NAME="arm64"
fi
if [ "x$isPodman" == "xtrue" ]; then
podman build -t $imageName --build-arg ARCH_NAME=$ARCH_NAME .
else
docker build -t $imageName --build-arg ARCH_NAME=$ARCH_NAME .
fi
}
# build for multiple arch
buildx() {
if [ -z $ARCH ]; then
echo "Need arch: -a amd64 arm64"
exit 1
fi
platform="linux/x64"
ARCH_NAME="x64"
if [ $ARCH == "amd64" ];then
ARCH_NAME="x64"
platform="linux/amd64"
elif [ $ARCH == "arm64" ];then
ARCH_NAME="arm64"
platform="linux/arm64"
elif [ $ARCH == "arm64/v8" ];then
ARCH_NAME="arm64"
platform="linux/arm64/v8"
elif [ $ARCH == "arm64/v7" ];then
ARCH_NAME="arm64"
platform="linux/arm/v7"
fi
rm -rf include_tmp
docker_my_init
if [ "x1" == "x$enableNodeDockerfileInclude" ]; then
dockerfile-include -i $dockerfile -o Dockerfile
fi
if [ "x$isPodman" == "xtrue" ]; then
podman build -t $imageName --platform $platform --build-arg ARCH_NAME=$ARCH_NAME .
else
docker buildx build $noCache $PUSH --build-arg ARCH_NAME=$ARCH_NAME --platform $platform -t $imageName:latest-$ARCH .
docker tag $imageName:latest-$ARCH $imageName:latest
fi
}
rebuild() {
docker_my_init
if [ "x1" == "x$enableNodeDockerfileInclude" ]; then
dockerfile-include -i $dockerfile -o Dockerfile
fi
if [ "x$isPodman" == "xtrue" ]; then
podman build --no-cache -t $imageName .
else
docker build --no-cache -t $imageName .
fi
}
stop() {
docker_my_init
docker stop $containerName || true
docker rm -f $containerName || true
}
startDef() {
docker_my_init
stop
docker run -dti --rm $port $volume --name $containerName $imageName /bin/bash
#docker exec -d $containerName bash -c "sh /root/start.sh"
}
start() {
host=""
if [ "X" != "X$hostname" ]; then
host=" -h $hostname "
fi
docker_my_init
stop
docker run -ti $port $volume $host --name $containerName $imageName
}
startIfNotFound() {
docker_my_init
r=`docker ps --filter="name=$containerName" 2>&1 | wc -l`
if [[ $r == *"1"* ]]; then
echo -e "The container $containerName is not existed.\n"
start
else
echo -e "The container $containerName is existed.\n"
fi
}
myStart() {
host=""
if [ "X" != "X$hostname" ]; then
host=" -h $hostname "
fi
docker_my_init
stop
docker run -d -t $port $volume $host --name $containerName $imageName /bin/bash
docker exec -d $containerName bash -c "sh /root/start.sh"
}
root() {
docker_my_init
stop
docker run -t -i $port --name $containerName $volume $imageName /bin/bash
}
login () {
docker_my_init
docker exec -ti $containerName /bin/bash
}