From 120c0fa4c8e163854ddf515b869a01ced5f03834 Mon Sep 17 00:00:00 2001 From: BigXin0109 <1064730540@qq.com> Date: Wed, 28 Sep 2022 15:27:21 +0800 Subject: [PATCH] docker support mysql and h2 (#746) --- docs/docs/user_docs/ops/server-docker.md | 17 ++++++++- hippo4j-server/Dockerfile | 31 ++++++----------- hippo4j-server/conf/hippo4j-logback.xml | 1 + hippo4j-server/docker-startup.sh | 44 ++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 21 deletions(-) create mode 100644 hippo4j-server/docker-startup.sh diff --git a/docs/docs/user_docs/ops/server-docker.md b/docs/docs/user_docs/ops/server-docker.md index 8ff51566..010ccae2 100644 --- a/docs/docs/user_docs/ops/server-docker.md +++ b/docs/docs/user_docs/ops/server-docker.md @@ -12,7 +12,22 @@ Docker 镜像默认使用内置 H2 数据库,数据持久化到 Docker 容器 docker run -d -p 6691:6691 --name hippo4j-server hippo4j/hippo4j-server ``` -访问 Server 控制台,路径 `http://localhost:6691/index.html`,默认用户名密码:admin / 123456 +使用mysql +```shell +/** +* 暂时只暴露以下参数 +* DATASOURCE_HOST、DATASOURCE_PORT、DATASOURCE_DB、DATASOURCE_USERNAME、DATASOURCE_PASSWORD +*/ +docker run -d -p 6691:6691 --name hippo4j-server \ +-e DATASOURCE_HOST=127.0.0.1 \ +-e DATASOURCE_PORT=3306 \ +-e DATASOURCE_DB=hippo4j_manager \ +-e DATASOURCE_USERNAME=root \ +-e DATASOURCE_PASSWORD=root \ +hippo4j/hippo4j-server +``` + +访问 Server 控制台,路径 `http://localhost:6691/index.html` ,默认用户名密码:admin / 123456 ## 镜像构建 diff --git a/hippo4j-server/Dockerfile b/hippo4j-server/Dockerfile index 23678131..0bfee974 100644 --- a/hippo4j-server/Dockerfile +++ b/hippo4j-server/Dockerfile @@ -17,33 +17,24 @@ FROM openjdk:8-jre-slim MAINTAINER lijianxin -ENV MYSQL_HOST="127.0.0.1" \ - MYSQL_PORT="3306" \ - MYSQL_DB="hippo4j_manager" \ - MYSQL_USERNAME="root" \ - MYSQL_PASSWORD="root" \ +ENV DATASOURCE_MODE="h2" \ + DATASOURCE_HOST="127.0.0.1" \ + DATASOURCE_PORT="3306" \ + DATASOURCE_DB="hippo4j_manager" \ + DATASOURCE_USERNAME="root" \ + DATASOURCE_PASSWORD="root" \ BASE_DIR="/opt/hippo4j" ENV TZ=PRC RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -ADD conf/hippo4j-logback.xml ${BASE_DIR}/logback.xml +ADD conf/hippo4j-logback.xml ${BASE_DIR}/conf/hippo4j-logback.xml +ADD conf/application.properties ${BASE_DIR}/conf/application.properties ADD target/hippo4j-server.jar ${BASE_DIR}/hippo4j-server.jar +ADD docker-startup.sh ${BASE_DIR}/docker-startup.sh WORKDIR ${BASE_DIR} +RUN chmod +x docker-startup.sh -ENTRYPOINT ["sh","-c","java -jar \ - -Xloggc:${BASE_DIR}/hippo4j_gc.log -verbose:gc -XX:+PrintGCDetails \ - -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation \ - -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M \ - -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BASE_DIR}/java_heapdump.hprof \ - -Xms1024m -Xmx1024m -Xmn512m \ - -Dhippo4j.standalone=true -Dhippo4j.home=${BASE_DIR} \ - hippo4j-server.jar \ - --server.max-http-header-size=524288 \ - --server.tomcat.basedir=${BASE_DIR}/tomcat \ - --logging.config=${BASE_DIR}/logback.xml \ - --spring.profiles.active=h2 \ - --spring.datasource.url=jdbc:h2:file:${BASE_DIR}/h2_hippo4j;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL \ - "] +ENTRYPOINT ["./docker-startup.sh"] \ No newline at end of file diff --git a/hippo4j-server/conf/hippo4j-logback.xml b/hippo4j-server/conf/hippo4j-logback.xml index 80b844bf..3f8442d9 100644 --- a/hippo4j-server/conf/hippo4j-logback.xml +++ b/hippo4j-server/conf/hippo4j-logback.xml @@ -47,6 +47,7 @@ + diff --git a/hippo4j-server/docker-startup.sh b/hippo4j-server/docker-startup.sh new file mode 100644 index 00000000..3a562b13 --- /dev/null +++ b/hippo4j-server/docker-startup.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +export JAVA_HOME +export JAVA="$JAVA_HOME/bin/java" + +export SERVER="hippo4j-server" + +JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext" +JAVA_OPT="${JAVA_OPT} -Xloggc:${BASE_DIR}/logs/hippo4j_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M" + +JAVA_OPT="${JAVA_OPT} -Xms1024m -Xmx1024m -Xmn512m" +JAVA_OPT="${JAVA_OPT} -Dhippo4j.standalone=true" +JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BASE_DIR}/logs/java_heapdump.hprof" +JAVA_OPT="${JAVA_OPT} -Dhippo4j.home=${BASE_DIR}" + +JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}" +JAVA_OPT="${JAVA_OPT} --logging.config=${BASE_DIR}/conf/hippo4j-logback.xml" +JAVA_OPT="${JAVA_OPT} --server.max-http-header-size=524288" +JAVA_OPT="${JAVA_OPT} --server.tomcat.basedir=${BASE_DIR}/bin" + +if [[ "${DATASOURCE_MODE}" == "mysql" ]]; then + JAVA_OPT="${JAVA_OPT} --spring.datasource.url=\"jdbc:mysql://${DATASOURCE_HOST}:${DATASOURCE_PORT}/${DATASOURCE_DB}?characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8\" " + JAVA_OPT="${JAVA_OPT} ---spring.datasource.username=${DATASOURCE_USERNAME} --spring.datasource.password=${DATASOURCE_PASSWORD} " +elif [[ "${DATASOURCE_MODE}" == "h2" ]]; then + JAVA_OPT="${JAVA_OPT} --spring.profiles.active=h2 --spring.datasource.url=jdbc:h2:file:${BASE_DIR}/h2_hippo4j;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL" +else + echo "hippo4j DATASOURCE_MODE is error, value ${DATASOURCE_MODE}, use default h2" +fi + +if [ ! -d "${BASE_DIR}/logs" ]; then + mkdir ${BASE_DIR}/logs +fi + +echo "$JAVA ${JAVA_OPT}" + +echo "hippo4j is starting with standalone" + +if [ ! -f "${BASE_DIR}/logs/start.out" ]; then + touch "${BASE_DIR}/logs/start.out" +fi + +echo "$JAVA ${JAVA_OPT}" > ${BASE_DIR}/logs/start.out 2>&1 & +java -jar hippo4j-server.jar ${JAVA_OPT} +echo "hippo4j is starting,you can check the ${BASE_DIR}/logs/"