#!/usr/bin/env bash docker ps > /dev/null 2>&1 if [ "$?" -ne 0 ]; then echo "Docker is not running correctly!" exit 1 fi if [ $# -lt 1 ]; then echo "Please specify spring active profile name!" exit 1 fi SPRING_PROFILE="$1" parentGroupId=$(mvn help:evaluate -Dexpression=project.parent.groupId -q -DforceStdout) hasParent=false if [[ "$parentGroupId" == "com.aijiao"* || "$parentGroupId" == "com.schbrain"* ]]; then hasParent=true fi if [ "$hasParent" == true ]; then SERVICE=$(mvn help:evaluate -Dexpression=project.parent.artifactId -q -DforceStdout) else SERVICE=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout) fi if [ "$hasParent" == true ]; then cd .. fi mvn -Dmaven.test.skip clean install if [ $? -ne 0 ]; then echo "Maven install failed!" exit 1 fi if [ "$hasParent" == true ]; then cd - fi VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) CONTAINER_NAME="$SERVICE"_"$SPRING_PROFILE" docker stop "$CONTAINER_NAME" docker rm "$CONTAINER_NAME" existImageId=`docker images |grep "$SERVICE" |grep "$VERSION"_"$SPRING_PROFILE" |awk '{print $3}'` if [ -n "$existImageId" ]; then echo "Removing exist image: $existImageId" docker rmi "$existImageId" fi if [ ! -d "target" ]; then echo "target dir not exits!" exit 1 fi cd target git archive -o dockerfiles.zip --format=zip --remote=git@gitlab.schbrain.com:schbrain-pub/dockerfiles.git 2.0:common unzip -o dockerfiles.zip && rm -f dockerfiles.zip TEST_MEM_OPTS="" ONLINE_MEM_OPTS="" if [[ "$SPRING_PROFILE" =~ "online" || "$SPRING_PROFILE" =~ "pre" ]]; then if [ ! -z "$ONLINE_MEM_OPTS" ]; then sed -i "" "s/MEM_OPTS=.*/MEM_OPTS=\"$ONLINE_MEM_OPTS\"/" run-app.sh fi else if [ ! -z "$TEST_MEM_OPTS" ]; then sed -i "" "s/MEM_OPTS=.*/MEM_OPTS=\"$TEST_MEM_OPTS\"/" run-app.sh fi fi cd .. profile="" if [[ "$SPRING_PROFILE" =~ "online" || "$SPRING_PROFILE" =~ "pre" ]]; then profile="-Ponline" fi mvn $profile -Dspring.profiles.active="$SPRING_PROFILE" dockerfile:build -U