Skip to content

Commit

Permalink
add docker support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tairy committed Dec 22, 2018
1 parent feb83ae commit cec64a9
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 125 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.gitattributes
.gitignore
header.txt
LICENSE.txt
README.md
.idea
.mvn
12 changes: 6 additions & 6 deletions deployment/agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RES="\E[0m";

echo_r () {
# Color red: Error, Failed
[ $# -ne 1 ] && return 1
[[ $# -ne 1 ]] && return 1
printf "[${BLUE_COLOR}jobx${RES}] ${RED_COLOR}$1${RES}\n"
}

Expand All @@ -44,7 +44,7 @@ esac
# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ]; do
while [[ -h "$PRG" ]]; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
Expand Down Expand Up @@ -72,17 +72,17 @@ CONFIG_PATH=${DEPLOY_PATH}/conf/conf.properties
###############################################################################################

#先检查dist下是否有war包
if [ ! -f "${WORKDIR}/${APP_TAR_NAME}" ] ; then
if [[ ! -f "${WORKDIR}/${APP_TAR_NAME}" ]] ; then
#dist下没有tar包则检查agent的target下是否有tar包.
if [ ! -f "${MAVEN_TARGET_TAR}" ] ; then
if [[ ! -f "${MAVEN_TARGET_TAR}" ]] ; then
echo_r "[JobX] please build project first!"
exit 0;
else
cp ${MAVEN_TARGET_TAR} ${WORKDIR};
fi
fi

[ -d "${DEPLOY_PATH}" ] && rm -rf ${DEPLOY_PATH}/* || mkdir -p ${DEPLOY_PATH}
[[ -d "${DEPLOY_PATH}" ]] && rm -rf ${DEPLOY_PATH}/* || mkdir -p ${DEPLOY_PATH}
#untar..
tar -xzvf ${WORKDIR}/${APP_TAR_NAME} && chmod +x ${DEPLOY_PATH}/bin/* >/dev/null 2>&1
EXECUTABLE=${DEPLOY_PATH}/bin/startup.sh
Expand All @@ -94,7 +94,7 @@ if $os400; then
# this will not work if the user belongs in secondary groups
eval
else
if [ ! -x "$EXECUTABLE" ]; then
if [[ ! -x "$EXECUTABLE" ]]; then
echo "Cannot find $EXECUTABLE"
echo "The file is absent or does not have execute permission"
echo "This file is needed to run this program"
Expand Down
64 changes: 32 additions & 32 deletions deployment/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ printf "${GREEN_COLOR} / /_/ / / /_/ / /_/ / __ . \ ${RES}\n"
printf "${GREEN_COLOR} \____/ \____/ /_.___/ __ / \_\__ ${RES}\n"
printf "${GREEN_COLOR} _____ / ${RES}\n\n"

# resolve links - $0 may be a softlink
# resolve links - $0 may be a soft link.
PRG="$0"

while [ -h "$PRG" ]; do
while [[ -h "$PRG" ]]; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
Expand All @@ -66,25 +66,25 @@ JOBX_AGENT_BIN_DIR=${WORK_BASE}/jobx-agent/src/assembly/bin

echo_r () {
# Color red: Error, Failed
[ $# -ne 1 ] && return 1
[[ $# -ne 1 ]] && return 1
printf "[${BLUE_COLOR}jobx${RES}] ${RED_COLOR}$1${RES}\n"
}

echo_g () {
# Color green: Success
[ $# -ne 1 ] && return 1
[[ $# -ne 1 ]] && return 1
printf "[${BLUE_COLOR}jobx${RES}] ${GREEN_COLOR}$1${RES}\n"
}

echo_y () {
# Color yellow: Warning
[ $# -ne 1 ] && return 1
[[ $# -ne 1 ]] && return 1
printf "[${BLUE_COLOR}jobx${RES}] ${YELLOW_COLOR}$1${RES}\n"
}

echo_w () {
# Color yellow: White
[ $# -ne 1 ] && return 1
[[ $# -ne 1 ]] && return 1
printf "[${BLUE_COLOR}jobx${RES}] ${WHITE_COLOR}$1${RES}\n"
}

Expand All @@ -99,53 +99,53 @@ OS400*) os400=true;;
esac

# Make sure prerequisite environment variables are set
if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
if $darwin; then
if [[ -z "$JAVA_HOME" && -z "$JRE_HOME" ]]; then
if ${darwin}; then
# Bugzilla 54390
if [ -x '/usr/libexec/java_home' ] ; then
if [[ -x '/usr/libexec/java_home' ]] ; then
export JAVA_HOME=`/usr/libexec/java_home`
# Bugzilla 37284 (reviewed).
elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then
elif [[ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]]; then
export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home"
fi
else
JAVA_PATH=`which java 2>/dev/null`
if [ "x$JAVA_PATH" != "x" ]; then
if [[ "x$JAVA_PATH" != "x" ]]; then
JAVA_PATH=`dirname $JAVA_PATH 2>/dev/null`
JRE_HOME=`dirname $JAVA_PATH 2>/dev/null`
fi
if [ "x$JRE_HOME" = "x" ]; then
if [[ "x$JRE_HOME" = "x" ]]; then
# XXX: Should we try other locations?
if [ -x /usr/bin/java ]; then
if [[ -x /usr/bin/java ]]; then
JRE_HOME=/usr
fi
fi
fi
if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
if [[ -z "$JAVA_HOME" && -z "$JRE_HOME" ]]; then
echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
echo "At least one of these environment variable is needed to run this program"
exit 1
fi
fi
if [ -z "$JAVA_HOME" -a "$1" = "debug" ]; then
if [[ -z "$JAVA_HOME" && "$1" = "debug" ]]; then
echo "JAVA_HOME should point to a JDK in order to run in debug mode."
exit 1
fi
if [ -z "$JRE_HOME" ]; then
if [[ -z "$JRE_HOME" ]]; then
JRE_HOME="$JAVA_HOME"
fi

# If we're running under jdb, we need a full jdk.
if [ "$1" = "debug" ] ; then
if [ "$os400" = "true" ]; then
if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/javac ]; then
if [[ "$1" = "debug" ]] ; then
if [[ "$os400" = "true" ]]; then
if [[ ! -x "$JAVA_HOME"/bin/java || ! -x "$JAVA_HOME"/bin/javac ]]; then
echo "The JAVA_HOME environment variable is not defined correctly"
echo "This environment variable is needed to run this program"
echo "NB: JAVA_HOME should point to a JDK not a JRE"
exit 1
fi
else
if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/jdb -o ! -x "$JAVA_HOME"/bin/javac ]; then
if [[ ! -x "$JAVA_HOME"/bin/java || ! -x "$JAVA_HOME"/bin/jdb || ! -x "$JAVA_HOME"/bin/javac ]]; then
echo "The JAVA_HOME environment variable is not defined correctly"
echo "This environment variable is needed to run this program"
echo "NB: JAVA_HOME should point to a JDK not a JRE"
Expand All @@ -154,14 +154,14 @@ if [ "$1" = "debug" ] ; then
fi
fi
# Don't override the endorsed dir if the user has set it previously
if [ -z "$JAVA_ENDORSED_DIRS" ]; then
if [[ -z "$JAVA_ENDORSED_DIRS" ]]; then
# Set the default -Djava.endorsed.dirs argument
JAVA_ENDORSED_DIRS="$JOBX_HOME"/endorsed
fi

if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
if [[ -z "$JAVACMD" ]] ; then
if [[ -n "$JAVA_HOME" ]] ; then
if [[ -x "$JAVA_HOME/jre/sh/java" ]] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
Expand All @@ -173,31 +173,31 @@ if [ -z "$JAVACMD" ] ; then
fi
#check java exists.
$JAVACMD >/dev/null 2>&1
if [ $? -ne 1 ];then
if [[ $? -ne 1 ]];then
echo_r "ERROR: java is not install,please install java first!"
exit 1;
fi
#check openjdk
if [ "`$JAVACMD -version 2>&1 | head -1|grep "openjdk"|wc -l`"x == "1"x ]; then
if [[ "`$JAVACMD -version 2>&1 | head -1|grep "openjdk"|wc -l`"x == "1"x ]]; then
echo_r "ERROR: please uninstall OpenJDK and install JDK 1.7+ first"
exit 1;
fi
echo_w "build jobx Starting...";
if [ ! -f "${WORK_BASE}/.mvn/mvnw" ];then
if [[ ! -f "${WORK_BASE}/.mvn/mvnw" ]];then
echo_r "ERROR: ${WORK_BASE}/.mvn/mvnw is not exists,This file is needed to run this program!"
exit 1;
fi

#gcc compile executor.c
exec_retval=0
GCCCMD="`which gcc`" >/dev/null 2>&1
if [ $? -eq 1 ];then
if [[ $? -eq 1 ]];then
exec_retval=-1
else
echo_g "compile executor.c starting..."
${GCCCMD} ${EXEC_LIB} -o executor.so
ret_val=$?
if [ ${ret_val} -eq 0 ] ; then
if [[ ${ret_val} -eq 0 ]] ; then
exec_retval=0
mv executor.so ${JOBX_AGENT_BIN_DIR}
else
Expand All @@ -208,13 +208,13 @@ fi

${WORK_BASE}/.mvn/mvnw -f ${WORK_BASE}/pom.xml clean install -Dmaven.test.skip=true;
ret_val=$?
if [ ${ret_val} -eq 0 ] ; then
if [[ ${ret_val} -eq 0 ]] ; then
cp ${JOBX_AGENT} ${WORK_DIR}
cp ${JOBX_SERVER} ${WORK_DIR}
printf "[${BLUE_COLOR}jobx${RES}] ${WHITE_COLOR}build jobx @Version ${JOBX_VERSION} successfully! please goto${RES} ${GREEN_COLOR}${WORK_DIR}${RES}\n"
if [ ${exec_retval} -eq 1 ]; then
if [[ ${exec_retval} -eq 1 ]]; then
echo_w "WARN: compile executor.c error,please compile executor.c by yourself."
elif [ ${exec_retval} -eq -1 ]; then
elif [[ ${exec_retval} -eq -1 ]]; then
echo_w "WARN: compile executor.c error,not found gcc,please compile executor.c by yourself."
else
rm -rf ${JOBX_AGENT_BIN_DIR}/executor.so >/dev/null 2>&1
Expand Down
26 changes: 13 additions & 13 deletions deployment/server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ if [ $? -ne 1 ];then
fi

#check openjdk
if [ "`${RUNJAVA} -version 2>&1 | head -1|grep "openjdk"|wc -l`"x == "1"x ]; then
echo_r "ERROR: please uninstall OpenJDK and install jdk first"
exit 1;
fi
#if [ "`${RUNJAVA} -version 2>&1 | head -1|grep "openjdk"|wc -l`"x == "1"x ]; then
# echo_r "ERROR: please uninstall OpenJDK and install jdk first"
# exit 1;
#fi

# OS specific support. $var _must_ be set to either true or false.
cygwin=false
Expand Down Expand Up @@ -123,16 +123,16 @@ CONFIG_PATH=${DEPLOY_PATH}/WEB-INF/classes/config.properties
###############################################################################################

#先检查dist下是否有war包
if [ ! -f "${WORKDIR}/${APP_WAR_NAME}" ] ; then
if [[ ! -f "${WORKDIR}/${APP_WAR_NAME}" ]] ; then
#dist下没有war包则检查server的target下是否有war包.
if [ ! -f "${MAVEN_TARGET_WAR}" ] ; then
if [[ ! -f "${MAVEN_TARGET_WAR}" ]] ; then
echo_w "[JobX] please build project first!"
exit 0;
else
cp ${MAVEN_TARGET_WAR} ${WORKDIR};
fi
fi
if [ ! -f "${DEPLOY_PATH}" ] ; then
if [[ ! -f "${DEPLOY_PATH}" ]] ; then
mkdir -p ${DEPLOY_PATH}
# unpackage war to dist
cp ${WORKDIR}/${APP_WAR_NAME} ${DEPLOY_PATH} &&
Expand All @@ -142,7 +142,7 @@ if [ ! -f "${DEPLOY_PATH}" ] ; then
fi

# Add jars to classpath
if [ ! -z "$CLASSPATH" ] ; then
if [[ ! -z "$CLASSPATH" ]] ; then
CLASSPATH="$CLASSPATH":
fi

Expand All @@ -152,20 +152,20 @@ do
done
CLASSPATH="$CLASSPATH":${DEPLOY_PATH}/WEB-INF/classes
#default launcher
[ -z "${JOBX_LAUNCHER}" ] && JOBX_LAUNCHER="tomcat";
[[ -z "${JOBX_LAUNCHER}" ]] && JOBX_LAUNCHER="tomcat";
#server'port
if [ $# -gt 0 ] ;then
if [[ $# -gt 0 ]] ;then
JOBX_PORT=$1
if [ "$JOBX_PORT" -gt 0 ] 2>/dev/null ;then
if [ $JOBX_PORT -lt 0 ] || [ $JOBX_PORT -gt 65535 ];then
if [[ "$JOBX_PORT" -gt 0 ]] 2>/dev/null ;then
if [[ $JOBX_PORT -lt 0 ]] || [[ $JOBX_PORT -gt 65535 ]];then
echo_r "server'port error,muse be between 0 and 65535!"
fi
else
echo_r "server'port bust be number."
exit 1;
fi
fi
[ -z "${JOBX_PORT}" ] && JOBX_PORT="20501";
[[ -z "${JOBX_PORT}" ]] && JOBX_PORT="20501";
#start server....
printf "[${BLUE_COLOR}jobx${RES}] ${WHITE_COLOR} server Starting @ [${GREEN_COLOR}${JOBX_PORT}${RES}].... ${RES}\n"
MAIN="com.jobxhub.server.JobXServer"
Expand Down
30 changes: 30 additions & 0 deletions docker/jobx-agent/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM java:8-jdk

LABEL [email protected]

WORKDIR /working

ADD pom.xml /working/pom.xml
ADD jobx-agent /working/jobx-agent
ADD jobx-api /working/jobx-api
ADD jobx-common /working/jobx-common
ADD jobx-registry /working/jobx-registry
ADD jobx-rpc /working/jobx-rpc
ADD jobx-server /working/jobx-server
ADD jobx-examples /working/jobx-examples
ADD settings.xml /working/settings.xml
ADD checkstyle.xml /checkstyle.xml

RUN cd /working \
&& wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz \
&& tar -zxvf apache-maven-3.5.4-bin.tar.gz \
&& /working/apache-maven-3.5.4/bin/mvn -f pom.xml clean install -Dmaven.test.skip=true --settings /working/settings.xml \
&& tar -zxvf jobx-agent/target/jobx-agent-1.2.0-RELEASE.tar.gz -C jobx-agent/target/ \
&& chmod +x jobx-agent/target/jobx-agent/bin/*.sh

EXPOSE 1577

CMD /working/jobx-agent/target/jobx-agent/bin/startup.sh



30 changes: 30 additions & 0 deletions docker/jobx-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM java:8-jdk

LABEL [email protected]

WORKDIR /working

ADD pom.xml /working/pom.xml
ADD jobx-agent /working/jobx-agent
ADD jobx-api /working/jobx-api
ADD jobx-common /working/jobx-common
ADD jobx-registry /working/jobx-registry
ADD jobx-rpc /working/jobx-rpc
ADD jobx-server /working/jobx-server
ADD jobx-examples /working/jobx-examples
ADD settings.xml /working/settings.xml
ADD checkstyle.xml /checkstyle.xml
ADD deployment /working/deployment

RUN cd /working \
&& wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz \
&& tar -zxvf apache-maven-3.5.4-bin.tar.gz \
&& /working/apache-maven-3.5.4/bin/mvn -f pom.xml clean install -Dmaven.test.skip=true --settings /working/settings.xml \
&& chmod +x /working/deployment/server.sh

EXPOSE 1577

CMD /working/deployment/server.sh



Loading

0 comments on commit cec64a9

Please sign in to comment.