123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #!/bin/bash
- set -e
- show_usage="args: [--image-name=]"
- #-o或--options选项后面是可接受的短选项,如ab:c::,表示可接受的短选项为-a -b -c,
- #其中-a选项不接参数,-b选项后必须接参数,-c选项的参数为可选的
- #-l或--long选项后面是可接受的长选项,用逗号分开,冒号的意义同短选项。
- #-n选项后接选项解析错误时提示的脚本名字
- ARGS=`getopt -o -h --long help,image-name: -n "$0" -- "$@"`
- if [ $? != 0 ]; then
- exit 1
- fi
- #将规范化后的命令行参数分配至位置参数($1,$2,...)
- eval set -- "${ARGS}"
- while [ -n "$1" ]
- do
- case "$1" in
- -h|--help)
- echo "$show_usage"; exit 1 ;;
- --image-name)
- IMAGE_NAME=$2; shift ;;
- *) shift ;;
- esac
- done
- PROJECT_PATH=$(cd `dirname $0`; pwd)
- APP_NAME="${PROJECT_PATH##*/}"
- VERSION=`cat VERSION`
- make version=$VERSION
- DOCKERFILE=Dockerfile
- if [ -z $IMAGE_NAME ];then
- IMAGE_NAME=$APP_NAME
- fi
- sed -e "s/%APP_NAME%/$APP_NAME/g" ${DOCKERFILE}.in > ${DOCKERFILE}
- docker build . -t $IMAGE_NAME
|