summaryrefslogtreecommitdiffstats
path: root/ci/build_docker_image.sh
blob: 5d94507adb5967da7b7b7139f8d25589f883d33d (plain)
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
#!/bin/bash

for i in "$@"
do
case $i in
    -n=*|--name=*)
    NAME="${i#*=}"
    shift
    ;;
    -v=*|--version=*)
    VERSION="${i#*=}"
    shift
    ;;
    -d=*|--dir=*)
    DIR="${i#*=}"
    shift
    ;;
esac
done

if [[ ${NAME} && ${VERSION} && ${DIR} ]]; then
	echo "assign the x to all files and dirs under current dir.."
	chmod +x -R .
	echo "begin to build image ${NAME}.."
        build_args=""
        if [ $http_proxy ]; then
            build_args+=" --build-arg http_proxy=$http_proxy"
        fi
        if [ $https_proxy ]; then
            build_args+=" --build-arg https_proxy=$https_proxy"
        fi
	docker build --no-cache -t ${NAME}:${VERSION} $build_args . >/dev/null || { echo -e "\nBuild docker image failed!";exit 1; }
	docker rmi $(docker images | grep "^<none>" | awk '{print $3}') &>/dev/null
	# docker save -o ${NAME}.tar ${NAME}:${VERSION} >/dev/null || { rm -f ${NAME}.tar &>/dev/null;echo -e "\nSave docker image failed!";exit 1; }
	if [ ! -d ${DIR} ]; then
		mkdir -p ${DIR}
	fi
	mv ${NAME}.tar ${DIR}/${NAME}.tar &>/dev/null
	echo "build completes!"
else
	echo "not all -n and -v and -d are provided!"
	exit 1
fi