赵冬冬 преди 3 години
родител
ревизия
55a7330d4e

+ 76 - 1
pom.xml

@@ -10,7 +10,7 @@
     </parent>
     <groupId>com.xin</groupId>
     <artifactId>shardingsphere-jdbc-study</artifactId>
-    <version>0.0.1-SNAPSHOT</version>
+    <version>0.0.1</version>
     <name>shardingsphere-jdbc-study</name>
     <description>Demo project for Spring Boot</description>
 
@@ -25,6 +25,33 @@
         <apache.poi.version>3.15</apache.poi.version>
         <poi.ooxml.version>3.15</poi.ooxml.version>
     </properties>
+    <profiles>
+
+        <profile>
+            <id>test</id>
+            <!--默认激活当前配置-->
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+            <properties>
+                <profiles.active>test</profiles.active>
+                <!-- Docker 配置 -->
+                <docker.dockerHost>http://192.168.29.131:2375</docker.dockerHost>
+                <!--                        <docker.serviceId>DockerHub</docker.serviceId>-->
+                <docker.image.version>1.0.0</docker.image.version>
+            </properties>
+        </profile>
+<!--        <profile>-->
+<!--            <id>dev</id>-->
+<!--            <properties>-->
+<!--                <profiles.active>dev</profiles.active>-->
+<!--                &lt;!&ndash; Docker 配置 &ndash;&gt;-->
+<!--                <docker.dockerHost>https://49.235.127.212:2375</docker.dockerHost>-->
+<!--                &lt;!&ndash;                <docker.serviceId>DockerHub</docker.serviceId>&ndash;&gt;-->
+<!--                <docker.image.version>1.0.0</docker.image.version>-->
+<!--            </properties>-->
+<!--        </profile>-->
+    </profiles>
 
     <dependencies>
         <dependency>
@@ -126,7 +153,55 @@
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>2.18.1</version>
+                <configuration>
+                    <skipTests>true</skipTests>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>com.spotify</groupId>
+                <artifactId>docker-maven-plugin</artifactId>
+                <version>1.2.2</version>
+                <configuration>
+                    <!-- 镜像名称  guoweixin/exam-->
+                    <imageName>${project.artifactId}</imageName>
+                    <!--指定标签-->
+                    <imageTags>
+                        <imageTag>${docker.image.version}</imageTag>
+                    </imageTags>
+                    <!-- 基础镜像jdk 1.8-->
+                    <baseImage>java</baseImage>
+                    <!-- 制作者提供本人信息 -->
+                    <maintainer>2292011451@qq.com</maintainer>
+                    <!--切换到/ROOT目录 -->
+                    <workdir>/ROOT</workdir>
+                    <cmd>["java", "-version"]</cmd>
+                    <entryPoint>["java", "-jar", "${project.build.finalName}.jar"]</entryPoint>
+                    <!-- 指定 Dockerfile 路径
+                      <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
+                   -->
+                    <!--指定远程 docker api地址-->
+                    <dockerHost>${docker.dockerHost}</dockerHost>
+                    <!--证书路劲-->
+<!--                    <dockerCertPath>D:\software\docker</dockerCertPath>-->
+                    <!-- 这里是复制 jar 包到 docker 容器指定目录配置 -->
+                    <resources>
+                        <resource>
+                            <targetPath>/ROOT</targetPath>
+                            <!--用于指定需要复制的根目录,${project.build.directory}表示target目录-->
+                            <directory>${project.build.directory}</directory>
+                            <!--用于指定需要复制的文件。${project.build.finalName}.jar指的是打包后的jar包文件。-->
+                            <include>${project.build.finalName}.jar</include>
+                        </resource>
+                    </resources>
+                </configuration>
+            </plugin>
+
         </plugins>
+
     </build>
 
 </project>

+ 31 - 0
src/main/java/com/xin/shardingspherejdbcdemo/controller/ShellController.java

@@ -0,0 +1,31 @@
+package com.xin.shardingspherejdbcdemo.controller;
+
+import com.xin.shardingspherejdbcdemo.entity.vo.AjaxVo;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/shell")
+@Slf4j
+public class ShellController {
+
+    @Value("${shell.path}")
+    private String shellPath;
+
+    @GetMapping("/{name}")
+    public AjaxVo info(@PathVariable("name") String name) {
+        String cmd = shellPath + "/" + name;
+        System.out.println(cmd);
+        try {
+            Runtime.getRuntime().exec(cmd);
+        } catch (Exception e) {
+            log.error("发送了错误{}", e);
+            return AjaxVo.error("error");
+        }
+        return AjaxVo.success("success");
+    }
+}

+ 42 - 0
src/main/resources/application-dev.yml

@@ -0,0 +1,42 @@
+server:
+  port: 8087
+shell:
+  path: /data
+pagehelper:
+  helper-dialect: mysql
+mybatis:
+  type-aliases-package: com.xin.shardingspherejdbcdemo.entity
+  mapper-locations: classpath:mapper/*Mapper.xml
+  configuration:
+    map-underscore-to-camel-case: true
+    default-fetch-size: 500
+    default-statement-timeout: 80
+dbinfo:
+  username: root
+  password: 123456
+spring:
+  main:
+    allow-bean-definition-overriding: true
+  shardingsphere:
+    datasource:
+      #数据库别名
+      names: sharding-user
+      sharding-user:
+        type: com.alibaba.druid.pool.DruidDataSource
+        driver-class-name: com.mysql.cj.jdbc.Driver
+        url: jdbc:mysql://192.168.29.131:3306/sharding_user?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
+        username: ${dbinfo.username}
+        password: ${dbinfo.password}
+    sharding:
+      tables:
+        #逻辑表名
+        user:
+          actual-data-nodes: sharding-user.t_user$->{0..2}
+          table-strategy:
+            inline:
+              sharding-column: id
+              algorithm-expression: t_user$->{id%3}
+    #打印sql
+    props:
+      sql:
+        show: true

+ 42 - 0
src/main/resources/application-test.yml

@@ -0,0 +1,42 @@
+server:
+  port: 8087
+shell:
+  path: /data
+pagehelper:
+  helper-dialect: mysql
+mybatis:
+  type-aliases-package: com.xin.shardingspherejdbcdemo.entity
+  mapper-locations: classpath:mapper/*Mapper.xml
+  configuration:
+    map-underscore-to-camel-case: true
+    default-fetch-size: 500
+    default-statement-timeout: 80
+dbinfo:
+  username: root
+  password: 123456
+spring:
+  main:
+    allow-bean-definition-overriding: true
+  shardingsphere:
+    datasource:
+      #数据库别名
+      names: sharding-user
+      sharding-user:
+        type: com.alibaba.druid.pool.DruidDataSource
+        driver-class-name: com.mysql.cj.jdbc.Driver
+        url: jdbc:mysql://192.168.29.131:3306/sharding_user?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
+        username: ${dbinfo.username}
+        password: ${dbinfo.password}
+    sharding:
+      tables:
+        #逻辑表名
+        user:
+          actual-data-nodes: sharding-user.t_user$->{0..2}
+          table-strategy:
+            inline:
+              sharding-column: id
+              algorithm-expression: t_user$->{id%3}
+    #打印sql
+    props:
+      sql:
+        show: true

+ 3 - 41
src/main/resources/application.yml

@@ -1,42 +1,4 @@
-server:
-  port: 8087
-pagehelper:
-  helper-dialect: mysql
-mybatis:
-  type-aliases-package: com.xin.shardingspherejdbcdemo.entity
-  mapper-locations: classpath:mapper/*Mapper.xml
-  configuration:
-    map-underscore-to-camel-case: true
-    default-fetch-size: 500
-    default-statement-timeout: 80
-dbinfo:
-  dbname: study
-  url: jdbc:mysql://192.168.29.131:3306/${dbinfo.dbname}
-  username: root
-  password: 123456
 spring:
-  main:
-    allow-bean-definition-overriding: true
-  shardingsphere:
-    datasource:
-      #数据库别名
-      names: sharding-user
-      sharding-user:
-        type: com.alibaba.druid.pool.DruidDataSource
-        driver-class-name: com.mysql.cj.jdbc.Driver
-        url: jdbc:mysql://192.168.29.131:3306/sharding_user?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
-        username: ${dbinfo.username}
-        password: ${dbinfo.password}
-    sharding:
-      tables:
-        #逻辑表名
-        user:
-          actual-data-nodes: sharding-user.t_user$->{0..2}
-          table-strategy:
-            inline:
-              sharding-column: id
-              algorithm-expression: t_user$->{id%3}
-    #打印sql
-    props:
-      sql:
-        show: true
+  # 环境 dev:开发环境|test:测试环境|prod:生产环境
+  profiles:
+    active: test #激活的配置文件