-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·51 lines (43 loc) · 989 Bytes
/
build.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
#!/bin/bash
# ------------------------
# 构建镜像
# bin/build.sh [-c OFF]
# -c 是否启用缓存构建: OFF/ON(默认)
# ------------------------
CACHE="ON"
set -- `getopt c: "$@"`
while [ -n "$1" ]
do
case "$1" in
-c) CACHE="$2"
shift ;;
esac
shift
done
function del_image {
image_name=$1
image_id=`docker images -q --filter reference=${image_name}`
if [ ! -z "${image_id}" ]; then
echo "delete [${image_name}] ..."
docker image rm -f ${image_id}
echo "done ."
fi
}
function build_image {
image_name=$1
dockerfile=$2
del_image ${image_name}
if [ "x${CACHE}" = "xOFF" ]; then
docker build --no-cache -t ${image_name} -f ${dockerfile} .
else
docker build -t ${image_name} -f ${dockerfile} .
fi
}
echo "clean logs ..."
rm -rf ./log
echo "build image ..."
image_name=`echo ${PWD##*/}`
build_image ${image_name} "Dockerfile"
docker-compose build
docker image ls | grep "${image_name}"
echo "finish ."