From 76afaa5af4a63f6cdf7824aa378b1a03e9b75e1b Mon Sep 17 00:00:00 2001
From: zhangdd <86431843@qq.com>
Date: Tue, 28 Sep 2021 11:22:28 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BAshell=E6=96=87=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: zhangdd <86431843@qq.com>
---
pom.xml | 5 ++++
sh/hello.sh | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+)
create mode 100644 sh/hello.sh
diff --git a/pom.xml b/pom.xml
index 8cb8e74..5d8eb2d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,6 +30,11 @@
org.springframework.boot
spring-boot-starter-web
+
+
+ org.projectlombok
+ lombok
+
diff --git a/sh/hello.sh b/sh/hello.sh
new file mode 100644
index 0000000..40ae8f5
--- /dev/null
+++ b/sh/hello.sh
@@ -0,0 +1,76 @@
+#!/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
\ No newline at end of file
--
GitLab