mirror of
https://gitee.com/dromara/dbswitch.git
synced 2025-08-29 08:54:00 +00:00
add docker image
This commit is contained in:
32
build-docker/build_and_push_image.sh
Normal file
32
build-docker/build_and_push_image.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
DBSWITCH_VERSION=1.6.4
|
||||
BUILD_DOCKER_DIR="$( cd "$( dirname "$0" )" && pwd )"
|
||||
PROJECT_ROOT_DIR=$( dirname "$BUILD_DOCKER_DIR")
|
||||
DOCKER_DBSWITCH_DIR=$BUILD_DOCKER_DIR/dbswitch
|
||||
|
||||
# build project
|
||||
cd $PROJECT_ROOT_DIR && sh docker-maven-build.sh && cd -
|
||||
|
||||
# copy files
|
||||
cd $BUILD_DOCKER_DIR \
|
||||
&& tar zxvf $PROJECT_ROOT_DIR/target/dbswitch-release-${DBSWITCH_VERSION}.tar.gz -C /tmp \
|
||||
&& cp /tmp/dbswitch-release-${DBSWITCH_VERSION}/lib/* ${BUILD_DOCKER_DIR}/dbswitch/dbswitch-release/lib/ \
|
||||
&& rm -rf /tmp/dbswitch-release-*
|
||||
|
||||
# build image
|
||||
cd ${DOCKER_DBSWITCH_DIR} \
|
||||
&& tar zcvf dbswitch-release.tar.gz dbswitch-release/ \
|
||||
&& docker build -t inrgihc/dbswitch:${DBSWITCH_VERSION} . \
|
||||
&& rm -f dbswitch-release.tar.gz \
|
||||
&& rm -f dbswitch-release/lib/*.jar
|
||||
|
||||
# clean project
|
||||
cd $PROJECT_ROOT_DIR && sh docker-maven-clean.sh && cd -
|
||||
|
||||
# login and push docker image
|
||||
docker login -u inrgihc
|
||||
docker push inrgihc/dbswitch:${DBSWITCH_VERSION}
|
||||
|
12
build-docker/dbswitch/Dockerfile
Normal file
12
build-docker/dbswitch/Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
||||
FROM inrgihc/maven-aliyun:3.6.3-jdk-8
|
||||
|
||||
ADD dbswitch-release.tar.gz /
|
||||
|
||||
EXPOSE 9088
|
||||
|
||||
USER root
|
||||
|
||||
WORKDIR /dbswitch-release
|
||||
|
||||
CMD [ "/dbswitch-release/bin/startup.sh"]
|
||||
|
48
build-docker/dbswitch/dbswitch-release/bin/startup.sh
Executable file
48
build-docker/dbswitch/dbswitch-release/bin/startup.sh
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Author : tang
|
||||
# Date :2021-07-31
|
||||
#
|
||||
#############################################
|
||||
# !!!!!! Modify here please
|
||||
|
||||
APP_MAIN="com.gitee.dbswitch.admin.AdminApplication"
|
||||
|
||||
#############################################
|
||||
|
||||
APP_HOME="${BASH_SOURCE-$0}"
|
||||
APP_HOME="$(dirname "${APP_HOME}")"
|
||||
APP_HOME="$(cd "${APP_HOME}"; pwd)"
|
||||
APP_HOME="$(cd "$(dirname ${APP_HOME})"; pwd)"
|
||||
#echo "Base Directory:${APP_HOME}"
|
||||
|
||||
APP_BIN_PATH=$APP_HOME/bin
|
||||
APP_LIB_PATH=$APP_HOME/lib
|
||||
APP_CONF_PATH=$APP_HOME/conf
|
||||
|
||||
APP_PID_FILE="${APP_HOME}/run/${APP_MAIN}.pid"
|
||||
APP_RUN_LOG="${APP_HOME}/run/run_${APP_MAIN}.log"
|
||||
|
||||
[ -d "${APP_HOME}/run" ] || mkdir -p "${APP_HOME}/run"
|
||||
cd ${APP_HOME}
|
||||
|
||||
echo -n `date +'%Y-%m-%d %H:%M:%S'` >>${APP_RUN_LOG}
|
||||
echo "---- Start service [${APP_MAIN}] process. ">>${APP_RUN_LOG}
|
||||
|
||||
# JVMFLAGS JVM参数可以在这里设置
|
||||
JVMFLAGS="-Dfile.encoding=UTF-8 -XX:+DisableExplicitGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:./gc.log"
|
||||
|
||||
if [ "$JAVA_HOME" != "" ]; then
|
||||
JAVA="$JAVA_HOME/bin/java"
|
||||
else
|
||||
JAVA=java
|
||||
fi
|
||||
|
||||
#把lib下的所有jar都加入到classpath中
|
||||
CLASSPATH=$APP_CONF_PATH
|
||||
for i in $APP_LIB_PATH/*.jar
|
||||
do
|
||||
CLASSPATH="$i:$CLASSPATH"
|
||||
done
|
||||
|
||||
$JAVA -cp $CLASSPATH $JVMFLAGS $APP_MAIN $APP_CONF_PATH
|
35
build-docker/dbswitch/dbswitch-release/conf/application.yml
Normal file
35
build-docker/dbswitch/dbswitch-release/conf/application.yml
Normal file
@@ -0,0 +1,35 @@
|
||||
server:
|
||||
port: 9088
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: dbswitch-admin
|
||||
tomcat:
|
||||
uri-encoding: UTF-8
|
||||
max-http-header-size: 8096
|
||||
mvc:
|
||||
throw-exception-if-no-handler-found: true
|
||||
static-path-pattern: /statics/**
|
||||
datasource:
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://${MYSQLDB_HOST:dbswitch_mysqldb}:${MYSQLDB_PORT:3306}/dbswitch?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF8&autoReconnect=true&useSSL=false&allowMultiQueries=true&failOverReadOnly=false&connectTimeout=30000
|
||||
username: ${MYSQLDB_USERNAME:tangyibo}
|
||||
password: ${MYSQLDB_PASSWORD:123456}
|
||||
validation-query: SELECT 1
|
||||
test-on-borrow: true
|
||||
flyway:
|
||||
locations: classpath:db/migration
|
||||
baseline-on-migrate: true
|
||||
table: DBSWITCH_SCHEMA_HISTORY
|
||||
enabled: true
|
||||
|
||||
mybatis:
|
||||
configuration:
|
||||
lazy-loading-enabled: true
|
||||
aggressive-lazy-loading: false
|
||||
map-underscore-to-camel-case: true
|
||||
#log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
mapper:
|
||||
wrap-keyword: "`{0}`"
|
||||
enable-method-annotation: true
|
63
build-docker/dbswitch/dbswitch-release/conf/logback.xml
Normal file
63
build-docker/dbswitch/dbswitch-release/conf/logback.xml
Normal file
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod=" 5 seconds">
|
||||
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
|
||||
<property name="LOG_HOME" value="./logs" />
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<!-- 按照每天生成日志文件 -->
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<File>${LOG_HOME}/dbswitch_server.log</File>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>ERROR</level> <!--过滤掉error的级别-->
|
||||
<onMatch>DENY</onMatch>
|
||||
<onMismatch>ACCEPT</onMismatch>
|
||||
</filter>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!--日志文件输出的文件名-->
|
||||
<FileNamePattern>${LOG_HOME}/dbswitch_server_%d{yyyy-MM-dd}.log.%i.gz</FileNamePattern>
|
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<!-- or whenever the file size reaches 100MB -->
|
||||
<maxFileSize>512MB</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
<!--日志文件保留天数-->
|
||||
<MaxHistory>30</MaxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<!--打印错误日志-->
|
||||
<appender name="ERRORFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<File>${LOG_HOME}/error_server.log</File>
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>ERROR</level> <!--//打印error-->
|
||||
</filter>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!--日志文件输出的文件名-->
|
||||
<FileNamePattern>${LOG_HOME}/dbswitch_error_%d{yyyy-MM-dd}.log.%i.gz</FileNamePattern>
|
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<!-- or whenever the file size reaches 100MB -->
|
||||
<maxFileSize>512MB</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
<!--日志文件保留天数-->
|
||||
<MaxHistory>180</MaxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 日志输出级别 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="FILE" />
|
||||
<appender-ref ref="ERRORFILE" />
|
||||
</root>
|
||||
</configuration>
|
0
build-docker/dbswitch/dbswitch-release/lib/.gitkeep
Normal file
0
build-docker/dbswitch/dbswitch-release/lib/.gitkeep
Normal file
55
build-docker/install/README.md
Normal file
55
build-docker/install/README.md
Normal file
@@ -0,0 +1,55 @@
|
||||
# DBSWITCH基于docker-compose的一键部署脚本
|
||||
|
||||
**要求**: 准备一个能够安装docker的linux操作系统
|
||||
|
||||
## 一、安装docker及docker-compose
|
||||
|
||||
```
|
||||
[root@localhost install]# ls -l
|
||||
总用量 12
|
||||
-rw-r--r-- 1 root root 625 2月 11 22:24 docker-compose.yml
|
||||
-rw-r--r-- 1 root root 787 2月 11 20:54 docker_install.sh
|
||||
-rw-r--r-- 1 root root 378 2月 11 22:38 README.md
|
||||
|
||||
[root@localhost install]# sh docker_install.sh
|
||||
```
|
||||
|
||||
## 二、一键部署dbswitch
|
||||
|
||||
```
|
||||
[root@localhost install]# ls -l
|
||||
总用量 12
|
||||
-rw-r--r-- 1 root root 625 2月 11 22:24 docker-compose.yml
|
||||
-rw-r--r-- 1 root root 787 2月 11 20:54 docker_install.sh
|
||||
-rw-r--r-- 1 root root 378 2月 11 22:38 README.md
|
||||
|
||||
[root@localhost install]# docker-compose up -d
|
||||
```
|
||||
|
||||
## 三、常用操作命令
|
||||
|
||||
- 1. 一键创建并启动容器服务:
|
||||
```
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
- 2. 销毁容器服务:
|
||||
```
|
||||
docker-compose down
|
||||
```
|
||||
|
||||
- 3. 停止容器:
|
||||
```
|
||||
docker-compose stop
|
||||
```
|
||||
|
||||
- 4. 重启容器:
|
||||
```
|
||||
docker-compose restart
|
||||
```
|
||||
|
||||
- 5. 启动容器:
|
||||
```
|
||||
docker-compose start
|
||||
```
|
||||
|
28
build-docker/install/docker-compose.yml
Normal file
28
build-docker/install/docker-compose.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
version: '3.3'
|
||||
services:
|
||||
mysqldb:
|
||||
container_name: dbswitch_mysqldb
|
||||
image: mysql:5.7
|
||||
volumes:
|
||||
- "/data/mysql:/var/lib/mysql"
|
||||
environment:
|
||||
MYSQL_DATABASE: dbswitch
|
||||
MYSQL_USER: tangyibo
|
||||
MYSQL_PASSWORD: 123456
|
||||
MYSQL_ROOT_PASSWORD: 123456
|
||||
MYSQL_ROOT_HOST: '%'
|
||||
ports:
|
||||
- 13306:3306
|
||||
dbswitch:
|
||||
container_name: dbswitch_webui
|
||||
image: inrgihc/dbswitch:1.6.4
|
||||
environment:
|
||||
MYSQLDB_HOST: dbswitch_mysqldb
|
||||
MYSQLDB_PORT: 3306
|
||||
MYSQLDB_USERNAME: tangyibo
|
||||
MYSQLDB_PASSWORD: 123456
|
||||
ports:
|
||||
- 9088:9088
|
||||
depends_on:
|
||||
- mysqldb
|
||||
|
30
build-docker/install/docker_install.sh
Normal file
30
build-docker/install/docker_install.sh
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
curl -sSL https://get.daocloud.io/docker | sh
|
||||
docker --version
|
||||
mkdir -p /etc/docker/
|
||||
cat > /etc/docker/daemon.json <<EOF
|
||||
{
|
||||
"registry-mirrors":[
|
||||
"https://docker.mirrors.ustc.edu.cn",
|
||||
"http://hub-mirror.c.163.com",
|
||||
"https://dhyjbe13.mirror.aliyuncs.com"
|
||||
],
|
||||
"insecure-registries": ["127.0.0.1/8"],
|
||||
"max-concurrent-downloads":10,
|
||||
"log-driver":"json-file",
|
||||
"log-level":"warn",
|
||||
"log-opts":{
|
||||
"max-size":"10m",
|
||||
"max-file":"3"
|
||||
},
|
||||
"data-root":"/var/lib/docker"
|
||||
}
|
||||
EOF
|
||||
service docker restart
|
||||
|
||||
curl -L https://get.daocloud.io/docker/compose/releases/download/v2.2.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
|
||||
docker-compose --version
|
||||
|
Reference in New Issue
Block a user