update at 2021-01-21 11:27:13 by ehlxr
This commit is contained in:
parent
e1235f4bb4
commit
bb103f5cf5
7
.dockerignore
Normal file
7
.dockerignore
Normal file
@ -0,0 +1,7 @@
|
||||
**/.DS_Store
|
||||
.idea
|
||||
**/*.iml
|
||||
**/target/
|
||||
**/dependency-reduced-pom.xml
|
||||
logs
|
||||
.vscode
|
51
.drone.yml
Normal file
51
.drone.yml
Normal file
@ -0,0 +1,51 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
workspace:
|
||||
path: /did
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: maven
|
||||
commands:
|
||||
- mvn clean install -DskipTests -e -U
|
||||
- cp ./did-server/target/did-server*.jar ./docker
|
||||
- echo -n "$(date -d @${DRONE_BUILD_CREATED} '+%Y%m%d_%H%M%S')_${DRONE_BUILD_NUMBER}, $(grep "<version>.*</version>" pom.xml | head -1 | awk -F '[>,<]' '{print $3})', latest" > .tags
|
||||
|
||||
- name: docker
|
||||
image: plugins/docker
|
||||
settings:
|
||||
repo: docker.ehlxr.me/ehlxr/did-server
|
||||
dockerfile: ./did-server/docker/build/Dockerfile
|
||||
registry: docker.ehlxr.me
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
build_args:
|
||||
- SERVER_NAME=did-server
|
||||
|
||||
# - name: deploy
|
||||
# image: appleboy/drone-ssh
|
||||
# settings:
|
||||
# host: 158.101.68.196
|
||||
# username: root
|
||||
# password:
|
||||
# from_secret: ssh_password
|
||||
# port: 22
|
||||
# script:
|
||||
# - docker swarm init
|
||||
# - docker service create --replicas 2 -p 4000:4000 --name blog ehlxr/blog:$(date -d @${DRONE_BUILD_CREATED} "+%Y%m%d_%H%M%S")_${DRONE_BUILD_NUMBER}
|
||||
# - docker service update --image ehlxr/blog:$(date -d @${DRONE_BUILD_CREATED} "+%Y%m%d_%H%M%S")_${DRONE_BUILD_NUMBER} blog
|
||||
|
||||
- name: notification
|
||||
image: lddsb/drone-dingtalk-message
|
||||
settings:
|
||||
token:
|
||||
from_secret: dingtalk_token
|
||||
type: markdown
|
||||
when:
|
||||
status:
|
||||
- failure
|
||||
- success
|
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,5 +1,8 @@
|
||||
**/.DS_Store
|
||||
.idea
|
||||
did.iml
|
||||
**/*.iml
|
||||
**/target/
|
||||
**/dependency-reduced-pom.xml
|
||||
did-server/_build.sh
|
||||
logs
|
||||
.vscode
|
||||
**/*.jar
|
76
Jenkinsfile
vendored
Normal file
76
Jenkinsfile
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
DOCKER_REGISTRY_USER = credentials('docker-registry-user')
|
||||
DOCKER_REGISTRY_PWD = credentials('docker-registry-pwd')
|
||||
DINGTALK_TOKEN = credentials('dingtalk-token')
|
||||
DOCKER_IMAGE_TAG = createVersion()
|
||||
}
|
||||
|
||||
parameters {
|
||||
gitParameter(branch: '',
|
||||
branchFilter: '.*',
|
||||
defaultValue: 'origin/master',
|
||||
listSize: '10',
|
||||
name: 'GIT_BRANCH',
|
||||
quickFilterEnabled: true,
|
||||
selectedValue: 'DEFAULT',
|
||||
sortMode: 'DESCENDING_SMART',
|
||||
tagFilter: '*',
|
||||
type: 'PT_BRANCH_TAG',
|
||||
description: 'Select your branch or tag.')
|
||||
choice(name: 'MODULE_PARMS', choices: ['did-server'], description: 'select module of project')
|
||||
string(name: 'DOCKER_IMAGE_TAG', defaultValue: '', description: 'docker 镜像 tag,默认为当前时间戳 + 编译号码,例如:20190909_113757_89')
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
checkout([$class: 'GitSCM',
|
||||
branches: [[name: "${params.GIT_BRANCH}"]],
|
||||
doGenerateSubmoduleConfigurations: false,
|
||||
extensions: [],
|
||||
submoduleCfg: [],
|
||||
userRemoteConfigs: [
|
||||
[
|
||||
credentialsId: 'git_credential',
|
||||
url: 'https://git.ehlxr.me/ehlxr/did.git'
|
||||
]
|
||||
]
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh "mvn clean install -DskipTests -e -U"
|
||||
sh "cp ${MODULE_PARMS}/target/${MODULE_PARMS}*.jar && sh build.sh"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
success {
|
||||
sh sendMsg("Jenkins Pipeline Finished: SUCCESS! \n docker image tag is: ${env.DOCKER_IMAGE_TAG}")
|
||||
}
|
||||
failure {
|
||||
sh sendMsg("Jenkins Pipeline Finished: FAILED!")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
def createVersion() {
|
||||
if("${env.DOCKER_IMAGE_TAG}" == ""){
|
||||
return new Date().format('yyyyMMdd_HHmmss') + "_${env.BUILD_NUMBER}"
|
||||
}
|
||||
|
||||
return "${env.DOCKER_IMAGE_TAG}"
|
||||
}
|
||||
|
||||
def sendMsg(String msg) {
|
||||
return "curl -s https://oapi.dingtalk.com/robot/send?access_token=${env.DINGTALK_TOKEN} \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{\"msgtype\": \"text\",\"text\": {\"content\": \""+ msg +"\"}}'"
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "############## start ##############"
|
||||
BUILD_DATE=`date +%Y-%m-%d:%H:%M:%S`
|
||||
|
||||
SERVER_NAME=`awk '/<name>[^<]+<\/name>/{gsub(/<name>|<\/name>/,"",$1);print $1;exit;}' pom.xml`
|
||||
#SERVER_NAME=$(basename `pwd`)
|
||||
mvn clean install -DskipTests
|
||||
cp target/${SERVER_NAME}*.jar ./docker
|
||||
cd docker
|
||||
|
||||
err=$?
|
||||
echo "############## $err ##############"
|
||||
if [ "$err" -ne "0" ]; then
|
||||
echo "############## build error ! ##############"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker_url=ehlxr/${SERVER_NAME}:latest
|
||||
|
||||
docker build --build-arg SERVER_NAME=${SERVER_NAME} -f ./Dockerfile -t ${docker_url} .
|
||||
|
||||
docker push ${docker_url}
|
||||
|
||||
rm ${SERVER_NAME}*.jar
|
||||
|
||||
echo "build & push finish ..."
|
||||
echo "############## ${BUILD_DATE} ##############"
|
@ -1,19 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#HOSTNAME=`hostname | cut -c1-18`
|
||||
LOGS_DIR="/data/logs"
|
||||
|
||||
if [ ! -d ${LOGS_DIR} ]; then
|
||||
mkdir -p ${LOGS_DIR}
|
||||
fi
|
||||
STDOUT_FILE=${LOGS_DIR}/${SERVER_NAME}.log
|
||||
|
||||
JAVA_OPTS=" -Duser.timezone=\"Asia/Shanghai\" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF8"
|
||||
|
||||
JAVA_MEM_OPTS=" -server -Xmx${XMX:-512m} -Xms${XMS:-128m} -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC \
|
||||
-XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=${LargePageSize:-4m} \
|
||||
-XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "
|
||||
|
||||
echo "Starting the ${SERVER_NAME} ...\c"
|
||||
#java -jar ${JAVA_OPTS} ${JAVA_MEM_OPTS} ./${SERVER_NAME}-*.jar > ${STDOUT_FILE} 2>&1
|
||||
java -jar ${JAVA_OPTS} ${JAVA_MEM_OPTS} ./${SERVER_NAME}-*.jar | tee -a ${STDOUT_FILE} 2>&1
|
@ -7,8 +7,8 @@
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="ID-SERVER-ERR" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>/data/logs/did/did-server-error.log</file>
|
||||
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${LOG_PATH:.}/logs/did/did-server-error.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>/data/logs/did/did-server-error.log.%d{yyyy-MM-dd}</fileNamePattern>
|
||||
<maxHistory>30</maxHistory>
|
||||
@ -24,8 +24,8 @@
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="ID-SERVER" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>/data/logs/did/did-server.log</file>
|
||||
<appender name="NORMAL" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>./logs/did/did-server.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>/data/logs/did/did-server.log.%d{yyyy-MM-dd}</fileNamePattern>
|
||||
<maxHistory>30</maxHistory>
|
||||
@ -36,11 +36,10 @@
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
<appender-ref ref="ID-SERVER"/>
|
||||
<appender-ref ref="ID-SERVER-ERR"/>
|
||||
<appender-ref ref="ERROR"/>
|
||||
<appender-ref ref="NORMAL"/>
|
||||
</root>
|
||||
|
||||
</configuration>
|
@ -11,6 +11,5 @@ COPY ${SERVER_NAME}*.jar /opt/
|
||||
|
||||
RUN chmod -R 755 /opt/
|
||||
|
||||
|
||||
EXPOSE 16830 16831
|
||||
ENTRYPOINT ["/opt/start.sh"]
|
55
docker/build.sh
Executable file
55
docker/build.sh
Executable file
@ -0,0 +1,55 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
echo "############## start ##############"
|
||||
BUILD_DATE=`date +%Y-%m-%d:%H:%M:%S`
|
||||
|
||||
CURR_DIR=`basename $PWD`
|
||||
if [[ ${CURR_DIR} != "docker" ]]; then
|
||||
echo "############## must exec in docker dir ##############"
|
||||
exit 2;
|
||||
fi
|
||||
|
||||
cd ../
|
||||
#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
|
||||
if [[ "`echo ${SERVER_JAR}`" != "${SERVER_JAR}" ]]; then
|
||||
echo exist ${SERVER_JAR} skip maven build.
|
||||
else
|
||||
mvn clean install -DskipTests
|
||||
fi
|
||||
|
||||
cp ${SERVER_JAR} ./docker
|
||||
cd docker
|
||||
|
||||
if [[ ${DOCKER_IMAGE_TAG} ]];then
|
||||
image_tag=${DOCKER_IMAGE_TAG}
|
||||
else
|
||||
echo "############## DOCKER_IMAGE_TAG is null ! ##############"
|
||||
# image_tag=$(git symbolic-ref --short -q HEAD)
|
||||
image_tag=`date "+%Y%m%d_%H%M%S"`
|
||||
fi
|
||||
echo "############## image_tag is: ${image_tag} ##############"
|
||||
|
||||
base_url=docker.ehlxr.me
|
||||
docker_url=${base_url}/ehlxr/${SERVER_NAME}:${image_tag}
|
||||
|
||||
docker build --build-arg SERVER_NAME=${SERVER_NAME} -f ./Dockerfile -t ${docker_url} .
|
||||
# get user pwd from environment
|
||||
echo "${DOCKER_REGISTRY_PWD}" | docker login --username ${DOCKER_REGISTRY_USER} --password-stdin ${base_url}
|
||||
|
||||
docker push ${docker_url}
|
||||
|
||||
rm ${SERVER_NAME}*.jar
|
||||
echo "############## build & push finish: ${BUILD_DATE} ##############"
|
||||
|
||||
err=$?
|
||||
if [[ "$err" -ne "0" ]]; then
|
||||
echo "############## build error ! ##############"
|
||||
exit 1
|
||||
fi
|
33
docker/start.sh
Executable file
33
docker/start.sh
Executable file
@ -0,0 +1,33 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
#HOSTNAME=`hostname | cut -c1-18`
|
||||
LOGS_DIR="/data/logs"
|
||||
GC_LOGS_DIR="/data/gc"
|
||||
|
||||
if [[ ! -d ${LOGS_DIR} ]]; then
|
||||
mkdir -p ${LOGS_DIR}
|
||||
fi
|
||||
if [[ ! -d ${GC_LOGS_DIR} ]]; then
|
||||
mkdir -p ${GC_LOGS_DIR}
|
||||
fi
|
||||
|
||||
STDOUT_FILE=${LOGS_DIR}/${SERVER_NAME}.log
|
||||
CURRENT=`date "+%Y%m%d%H%M%S"`
|
||||
|
||||
#JAVA_OPTS=" -Duser.timezone=\"Asia/Shanghai\" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF8"
|
||||
|
||||
#JAVA_MEM_OPTS=" -server -Xmx${XMX:-512m} -Xms${XMS:-128m} -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC \
|
||||
# -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=${LargePageSize:-4m} \
|
||||
# -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 \
|
||||
# -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:${GC_LOGS_DIR}/${SERVER_NAME}_${CURRENT}_gc.log \
|
||||
# -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${GC_LOGS_DIR}/${SERVER_NAME}_${CURRENT}.hprof"
|
||||
|
||||
JAVA_MEM_OPTS=" -server -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:${GC_LOGS_DIR}/${SERVER_NAME}_${CURRENT}_gc.log \
|
||||
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${GC_LOGS_DIR}/${SERVER_NAME}_${CURRENT}.hprof"
|
||||
|
||||
echo "Starting the ${SERVER_NAME} ...\c"
|
||||
chmod -R 755 ./${SERVER_NAME}*.jar
|
||||
#java -jar ${JAVA_OPTS} ${JAVA_MEM_OPTS} ./${SERVER_NAME}*.jar > ${STDOUT_FILE} 2>&1
|
||||
java -jar ${JAVA_MEM_OPTS} ./${SERVER_NAME}*.jar | tee -a ${STDOUT_FILE} 2>&1
|
Loading…
Reference in New Issue
Block a user