forked from 527515025/springBoot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,711 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/bin/sh | ||
|
||
######################### | ||
# based on docker bin | ||
|
||
packageName=$1 | ||
imageVersion=$2 | ||
dockerDestFolder=$3 | ||
env=$4 | ||
packageTZ=Asia/Shanghai | ||
|
||
if [ "${packageName}" = "" ]; then | ||
echo [ERROR] "Please provide image name as first param" | ||
exit 1 | ||
fi | ||
|
||
if [ "${imageVersion}" = "" ]; then | ||
echo [ERROR] "Please provide image version as second param" | ||
exit 1 | ||
fi | ||
|
||
if [ "${dockerDestFolder}" = "" ]; then | ||
echo [ERROR] "Please provide docker dest folder" | ||
exit 1 | ||
fi | ||
|
||
if [ "${env}" = "" ]; then | ||
echo [ERROR] "Please provide env folder" | ||
exit 1 | ||
fi | ||
|
||
|
||
COUNT=`docker -v 2>&1 | grep 'version' | grep -v grep | wc -l` | ||
if [ ${COUNT} != 1 ]; then | ||
echo [ERROR] "Cannot find docker command" | ||
exit 1 | ||
fi | ||
|
||
echo [INFO] "Remove old image from docker repository..." | ||
count=`docker images | grep "${packageName}" | grep "${imageVersion}" | wc -l` | ||
if [ ${count} != 1 ]; then | ||
echo [WARN] "image ${packageName} with version ${imageVersion} does not exist in docker repo" | ||
else | ||
docker rmi -f ${packageName}:${imageVersion} | ||
fi | ||
|
||
#generate Dockerfile dynamically | ||
echo [INFO] "generating Dockerfile..." | ||
warName=${packageName}-${imageVersion}.war | ||
dateVersion=`date +%Y%m%d-%H%M%S` | ||
|
||
#cat out to Dockerfile with content begin/end with EOF | ||
cat > target/Dockerfile <<EOF | ||
FROM debian:jessie | ||
MAINTAINER Cliff Ma | ||
COPY target/${warName} ${dockerDestFolder}/${dateVersion}/ | ||
ENV LANG C.UTF-8 | ||
ENV TZ=Asia/Shanghai | ||
RUN ln -snf /usr/share/zoneinfo/${packageTZ} /etc/localtime && echo ${packageTZ} > /etc/timezone | ||
RUN cd ${dockerDestFolder} \ | ||
&& ln -svnf ${dateVersion} current \ | ||
&& cd current \ | ||
&& touch docker-entrypoint.sh \ | ||
&& chmod +x docker-entrypoint.sh \ | ||
&& echo "/opt/apps/java/bin/java -jar ${dockerDestFolder}/current/*.war --spring.config.location=${dockerDestFolder}/current/env/application.properties >/dev/null 2>&1" > docker-entrypoint.sh | ||
CMD .${dockerDestFolder}/current/docker-entrypoint.sh | ||
EOF | ||
|
||
# echo $TZ > /etc/timezone TO someString to one file. | ||
# To set the right time. | ||
# ENV TZ=Asia/Shanghai | ||
# RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime && echo ${TZ} > /etc/timezone | ||
# COPY conf/${env}/*.cer ${dockerDestFolder}/${dateVersion}/ | ||
|
||
|
||
#read Dockerfile | ||
echo [INFO] "Building image..." | ||
docker build -t ${packageName}:${imageVersion} -f target/Dockerfile . || exit 1 | ||
|
||
|
||
echo [INFO] "Exporting image to target folder..." | ||
docker save ${packageName}:${imageVersion} > target/${packageName}-${imageVersion}.image | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# EMBEDDED SERVER CONFIGURATION (ServerProperties) | ||
server.port=8099 | ||
|
||
|
||
ms.db.driverClassName=com.mysql.jdbc.Driver | ||
ms.db.url=jdbc:mysql://localhost:3306/msm?useSSL=false&useUnicode=true&characterEncoding=UTF-8 | ||
ms.db.username=root | ||
ms.db.password=admin | ||
ms.db.maxActive=500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#dev | ||
|
||
################ | ||
##this property file is used to export shell session-scoped variables by command 'source *.properties' | ||
################ | ||
|
||
#app root | ||
prop_appRoot=/opt/apps | ||
|
||
|
||
#run postinstall or not.(It is not used any more.) | ||
prop_runPreinstall=false | ||
prop_runPostinstall=false | ||
|
||
#the package name | ||
prop_package=springboot-mybatis | ||
#the package version | ||
prop_packageVersion=v1 | ||
|
||
|
||
#Your Java Home | ||
prop_javaHome=/opt/apps/jdk/current | ||
|
||
#owner and group for package | ||
prop_ownerGroup=root:root | ||
|
||
|
||
#folders which need to be created manually, the folder path will be relative to the app home folder | ||
#seperate multi folders with space, don't forget the double " | ||
prop_manualFolders="var/logs" | ||
#manual folders mode | ||
prop_manualFolderMode=777 | ||
|
||
|
||
################### | ||
#Cluster config | ||
################### | ||
#used by install.sh to decide the install mode: cluster or single node(default false) | ||
prop_isCluster=false | ||
|
||
#single | ||
prop_singleNode=springboot-mybatis-dev | ||
|
||
#cluster | ||
#all the nodes for the cluster, only is is accepted now | ||
#seperated by , sign (EX di,d2,192.168.100.2)(If you want to use d1 d2,you must config the url in etc/local) | ||
prop_clusterNodes=d1 | ||
|
||
|
||
################### | ||
#springboot config | ||
################### | ||
prop_springbootWarName=${prop_package} | ||
prop_springbootWarVersion=${prop_packageVersion} | ||
prop_springbootProcessKeyWord=${prop_springbootWarName}-${prop_springbootWarVersion}.war | ||
|
||
|
||
############## | ||
#docker config | ||
############## | ||
prop_dockerDestFolder=${prop_appRoot}/${prop_package} | ||
#docker daemon.(Docker is online or not.) | ||
prop_dockerProcessKeyWord='docker' | ||
#docker image name, e.g. cliff/nginx or nginx | ||
prop_dockerImageName=${prop_package} | ||
#docker image version, e.g. v1/v2 or latest | ||
prop_dockerImageVersion=${prop_packageVersion} | ||
#docker container count in each host server(1 in most situation.) | ||
prop_dockerContainerCount=1 | ||
|
||
#docker config file mapping, multiple file mappings is supported so you can specify multiple -v xx:xx | ||
prop_dockerConfigFileMapping="env:${prop_dockerDestFolder}/current/env" | ||
prop_dockerLogFolderMapping="var/logs/nodexxx:${prop_dockerDestFolder}/var/logs" | ||
prop_dockerUploadFolderMapping="uploadFiles:${prop_dockerDestFolder}/uploadFiles" | ||
# It is not used any more. Add command `--net=host` | ||
prop_dockerPortMappings=80:8081 | ||
|
||
########################################## | ||
#seconds config before start and stop | ||
########################################## | ||
|
||
#the sleep time to wail for each node starting up after another, the unit is second | ||
prop_startAllSleep=2 | ||
|
||
#the sleep time to wail for one node starting up. | ||
#sometimes we start up server by backend job so we need wait some time | ||
prop_startOneSleep=8 | ||
|
||
#stop node timeout, if timeout we will kill -9, the unit is second | ||
prop_stopNodeTimeout=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Output pattern : date [thread] priority category - message | ||
log4j.rootLogger=INFO, Console, R | ||
|
||
#Console | ||
log4j.appender.Console=org.apache.log4j.ConsoleAppender | ||
log4j.appender.Console.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n | ||
|
||
|
||
log4j.appender.R=org.apache.log4j.RollingFileAppender | ||
log4j.appender.R.File=logs/cmbms.log | ||
log4j.appender.R.MaxFileSize=50kB | ||
log4j.appender.R.MaxBackupIndex=5 | ||
log4j.appender.R.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.R.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n | ||
|
||
|
||
log4j.appender.ServerDailyRollingFile=org.apache.log4j.DailyRollingFileAppender | ||
log4j.appender.ServerDailyRollingFile.DatePattern='.'yyyy-MM-dd | ||
log4j.appender.ServerDailyRollingFile.layout=org.apache.log4j.PatternLayout | ||
#log4j.appender.ServerDailyRollingFile.Append=true | ||
|
||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender | ||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p [%c] %m%n | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#!/bin/bash | ||
|
||
##################### | ||
# bash only | ||
# usage ./package.sh | ||
##################### | ||
|
||
#declare -a: define an array | ||
#declare -i: define an integer | ||
declare -i index=1 | ||
declare -a envMap | ||
declare -a formatMap=(["1"]="docker" ["2"]="springboot") | ||
|
||
#GET THE URL OF CURRENT PATH | ||
CURRENT_DIR=`dirname $0` | ||
cd $CURRENT_DIR | ||
|
||
######################### | ||
# confirm the env | ||
######################### | ||
index=1 | ||
#scan the envs from conf/* | ||
for i in env/* ; do | ||
if [ -d ${i} ]; then | ||
envMap["${index}"]="`basename ${i}`" | ||
index=index+1 | ||
fi | ||
done | ||
|
||
#Print the choice | ||
env=1 | ||
echo "Please choose the environment by typing the number [default ${env}]" | ||
for i in ${!envMap[@]} ;do | ||
echo [${i}]:${envMap[${i}]} | ||
done | ||
|
||
#Read the envTmp . Set The finalEnv. Pay Attention 'read' NOT 'Read' | ||
read envTmp | ||
# echo "${envTmp}" | ||
if [ "${envTmp}" != "" ]; then | ||
env=${envTmp} | ||
fi | ||
# echo "${env}" | ||
finalEnv=${envMap[${env}]} | ||
echo "${finalEnv}" | ||
echo "[INFO] You are choosing environment: ${finalEnv}" | ||
echo "[INFO] Set the env properties by env/${finalEnv}/env.properties" | ||
|
||
#Load the env/${finalEnv}/env.properties | ||
. env/${finalEnv}/env.properties | ||
echo "" | ||
echo "" | ||
|
||
######################### | ||
# confirm the format | ||
######################### | ||
format=1 | ||
for i in ${!formatMap[@]};do | ||
echo [${i}]: ${formatMap[${i}]} | ||
done | ||
read formatTmp | ||
if [ "${formatTmp}" != "" ]; then | ||
format=${formatTmp} | ||
fi | ||
finalFormat=${formatMap[${format}]} | ||
######################### | ||
# confirm the package | ||
######################### | ||
finalPackage=${prop_package} | ||
echo "[INFO] You are choosing package version: ${finalPackage}" | ||
echo "" | ||
echo "" | ||
|
||
######################### | ||
# confirm the version | ||
######################### | ||
finalPackageVersion=${prop_packageVersion} | ||
echo "[INFO] You are choosing package version: ${finalPackageVersion}" | ||
echo "" | ||
echo "" | ||
|
||
###################### | ||
# begin packing | ||
###################### | ||
if [ -n "${finalFormat}" ] && [ "${finalFormat}" = "springboot" ]; then | ||
############################## | ||
# generate executable war file | ||
############################## | ||
|
||
#noneed.properties The .properties is outside the war . So it is no need any more. | ||
theCommand="./war-it.sh ${finalPackage} ${finalPackageVersion} ${finalEnv} 'noneed.properties'" | ||
echo [INFO] ${theCommand} | ||
eval ${theCommand} || exit 1 | ||
else | ||
############################## | ||
# generate executable war file | ||
############################## | ||
theCommand="./war-it.sh ${finalPackage} ${finalPackageVersion} ${finalEnv} 'noneed.properties'" | ||
echo [INFO] ${theCommand} | ||
eval ${theCommand} || exit 1 | ||
|
||
|
||
|
||
##################################### | ||
# generate docker image and export it | ||
##################################### | ||
theCommand="./docker-it.sh ${finalPackage} ${finalPackageVersion} ${prop_dockerDestFolder} ${finalEnv}" | ||
echo [INFO] ${theCommand} | ||
eval ${theCommand} || exit 1 | ||
fi | ||
|
||
theCommand="./tar-it.sh ${finalEnv} ${finalPackage} ${finalPackageVersion} ${finalFormat}" | ||
echo [INFO] ${theCommand} | ||
eval ${theCommand} || exit 1 | ||
|
||
echo "[INFO] package is done successfully" | ||
|
Oops, something went wrong.