完善ci-webhook

This commit is contained in:
KennyLee 2017-04-21 17:58:06 +08:00
parent 8c7bd9b143
commit a9f3b9e3ab
4 changed files with 47 additions and 29 deletions

View File

@ -1,14 +1,18 @@
FROM registry.cn-hangzhou.aliyuncs.com/kennylee/sshd-tomcat:tomcat8-jre7-nodejs7 FROM registry.cn-hangzhou.aliyuncs.com/kennylee/sshd-tomcat:tomcat8-jdk7-nodejs7
ENV REPO_URL=http://sys:11111111@192.168.3.231:10080/zgbj/gkxt.git
ENV PROJECT_NAME=gkxt
ENV PROJECT_BRANCH=feature_testci
RUN sed -i "s@\/usr\/lib\/jvm\/java-7-oracle@${JAVA_HOME}@" /etc/init.d/tomcat
RUN sed -i "s@-server -Xms128m -Xmx1024m -XX\:PermSize=64M -XX\:MaxPermSize=192M@${JAVA_OPTS}@" /etc/init.d/tomcat
RUN cd /root && git clone https://git.oschina.net/kennylee/ci-webhook.git ci-webhook RUN cd /root && git clone https://git.oschina.net/kennylee/ci-webhook.git ci-webhook
RUN cd ci-webhook && cnpm install
RUN cd /tmp/ && git clone $REPO_URL $PROJECT_NAME && cd $PROJECT_NAME && git checkout $PROJECT_BRANCH
RUN cd /tmp/$PROJECT_NAME && ./gradlew --no-daemon clean dist -x test
RUN rm -rf ${CATALINA_HOME}/webapps/* && unzip /tmp/$PROJECT_NAME/build/dist/*.zip -d ${CATALINA_HOME}/webapps/
RUN cd ci-webhook && cnpm install COPY deploy.sh /deploy.sh
RUN chmod +x /deploy.sh
# Install Java.
RUN \
apt-get update && \
apt-get install -y python-pip && \
pip install supervisor-stdout && \
rm -rf /var/lib/apt/lists/*

View File

@ -0,0 +1,25 @@
#!/bin/bash
PROJECT_NAME=gkxt
REPO_BRANCH=feature_testci
CUSTOM_JAVA_OPTS=
if [ -n "${JAVA_OPTS}" ]; then
CUSTOM_JAVA_OPTS="$JAVA_OPTS"
fi
source /root/.bashrc
TOMCAT_WEBAPPS_PATH=$CATALINA_HOME'/webapps/'
if [ -n "${CUSTOM_JAVA_OPTS}" ]; then
export JAVA_OPTS=$CUSTOM_JAVA_OPTS
fi
${CATALINA_HOME}/bin/catalina.sh stop
sleep 3s
cd /tmp/$PROJECT_NAME
git fetch origin $REPO_BRANCH
git reset --hard origin/$REPO_BRANCH
./gradlew --no-daemon clean dist -x test
/bin/bash -c "rm -rf ${TOMCAT_WEBAPPS_PATH}* && unzip /tmp/$PROJECT_NAME/build/dist/*.zip -d $TOMCAT_WEBAPPS_PATH && ${CATALINA_HOME}/bin/catalina.sh run"

View File

@ -1,27 +1,14 @@
var http = require("http"), var http = require("http"),
exec = require('child_process').exec; exec = require('child_process').exec;
const PORT = 7788, projectName = 'gkxt'; const PORT = 7788;
const repo = {
url: 'http://sys:11111111@192.168.3.231:10080/zgbj/gkxt.git', // git repository
branch: 'feature_testci',
localPath: '/tmp/',
buildCommand: './gradlew clean dist -x test',
distPath: '/root/tomcat/webapps/'
};
http.createServer(function (request, response) { http.createServer(function (request, response) {
if (request.url.search(/deploy\/?$/i) > 0) { if (request.url.search(/deploy\/?$/i) > 0) {
var commands = [ var commands = [
'rm -rf ' + repo.localPath + projectName, 'supervisorctl stop tomcat',
'cd ' + repo.localPath, 'sleep 3s',
'git clone ' + repo.url + ' ' + projectName, 'supervisorctl start tomcat'
'cd ' + projectName,
'git checkout ' + repo.branch,
repo.buildCommand,
'rm -rf ' + repo.distPath + "*",
'unzip ./build/dist/*.zip -d ' + repo.distPath,
'service tomcat restart'
].join(' && '); ].join(' && ');
var buildProcess = exec(commands, function (err, out, code) { var buildProcess = exec(commands, function (err, out, code) {
if (err instanceof Error) { if (err instanceof Error) {

View File

@ -5,9 +5,11 @@ nodaemon=true
command=/usr/sbin/sshd -D command=/usr/sbin/sshd -D
[program:tomcat] [program:tomcat]
command=/supervisord_wrapper.sh command=/bin/bash /deploy.sh
stdout_events_enabled = true stdout_events_enabled = true
stderr_events_enabled = true stderr_events_enabled = true
startretries=3
environment=JAVA_OPTS='-server -Xms256m -Xmx1536m -XX:PermSize=64M -XX:MaxPermSize=192M'
[program:ci] [program:ci]
command=/usr/bin/node /root/ci-webhook/server.js command=/usr/bin/node /root/ci-webhook/server.js
@ -16,7 +18,7 @@ stderr_events_enabled = true
[eventlistener:stdout] [eventlistener:stdout]
command = supervisor_stdout command = supervisor_stdout
buffer_size = 100 #buffer_size = 10
events = PROCESS_LOG events = PROCESS_LOG
result_handler = supervisor_stdout:event_handler result_handler = supervisor_stdout:event_handler