did/docker/build.sh

56 lines
1.5 KiB
Bash
Raw Normal View History

2021-01-21 03:27:13 +00:00
#!/bin/sh
set -e
echo "############## start ##############"
2021-01-22 07:40:02 +00:00
BUILD_DATE=$(date +%Y-%m-%d:%H:%M:%S)
2021-01-21 03:27:13 +00:00
2021-01-21 04:07:20 +00:00
#CURR_DIR=`basename $PWD`
#if [[ ${CURR_DIR} != "docker" ]]; then
# echo "############## must exec in docker dir ##############"
# exit 2;
#fi
#
#cd ../
2021-01-21 03:27:13 +00:00
#SERVER_NAME=`awk '/<name>[^<]+<\/name>/{gsub(/<name>|<\/name>/,"",$1);print $1;exit;}' pom.xml`
#SERVER_NAME=$(basename `pwd`)
SERVER_NAME=${MODULE_PARMS}
SERVER_JAR=$PWD/${MODULE_PARMS}/target/${SERVER_NAME}*.jar
#if [ ! -n "ls ${SERVER_JAR} >/dev/null 2>&1" ]; then
2021-01-22 07:40:02 +00:00
if [[ "$(echo ${SERVER_JAR})" != "${SERVER_JAR}" ]]; then
echo exist ${SERVER_JAR} skip maven build.
2021-01-21 03:27:13 +00:00
else
2021-01-22 07:40:02 +00:00
mvn clean install -DskipTests
2021-01-21 03:27:13 +00:00
fi
cp ${SERVER_JAR} ./docker
2021-01-21 04:07:20 +00:00
#cd docker
2021-01-21 03:27:13 +00:00
2021-01-22 07:40:02 +00:00
if [[ ${DOCKER_IMAGE_TAG} ]]; then
image_tag=${DOCKER_IMAGE_TAG}
2021-01-21 03:27:13 +00:00
else
2021-01-22 07:40:02 +00:00
echo "############## DOCKER_IMAGE_TAG is null ! ##############"
# image_tag=$(git symbolic-ref --short -q HEAD)
image_tag=$(date "+%Y%m%d_%H%M%S")
2021-01-21 03:27:13 +00:00
fi
echo "############## image_tag is: ${image_tag} ##############"
base_url=docker.ehlxr.me
docker_url=${base_url}/ehlxr/${SERVER_NAME}:${image_tag}
2021-01-21 04:07:20 +00:00
docker build --build-arg SERVER_NAME=${SERVER_NAME} -f ./docker/Dockerfile -t ${docker_url} .
2021-01-21 03:27:13 +00:00
# get user pwd from environment
echo "${DOCKER_REGISTRY_PWD}" | docker login --username ${DOCKER_REGISTRY_USER} --password-stdin ${base_url}
docker push ${docker_url}
2021-01-21 04:07:20 +00:00
rm ./docker/${SERVER_NAME}*.jar
2021-01-21 03:27:13 +00:00
echo "############## build & push finish: ${BUILD_DATE} ##############"
err=$?
if [[ "$err" -ne "0" ]]; then
2021-01-22 07:40:02 +00:00
echo "############## build error ! ##############"
exit 1
fi