Browse Source

feat(deploy): 环境部署脚本

Go 4 years ago
parent
commit
40412439f7

+ 18 - 0
.gitignore

@@ -0,0 +1,18 @@
+*.class
+
+# Package Files #
+*.jar
+*.war
+*.ear
+!libs/*.jar
+logs
+*.iml
+.idea/
+/target
+.DS_Store
+gradle
+.gradle/
+build/
+out/
+upload/
+dist/

+ 1 - 0
deploy/ssh/business.ini

@@ -0,0 +1 @@
+GROUP=/business

+ 2 - 0
deploy/ssh/qianxing.ini

@@ -1 +1,3 @@
 DEPLOY_PATH=/data
+GROUP=
+ENV=test

+ 70 - 0
deploy/upload.sh

@@ -0,0 +1,70 @@
+#!/bin/bash
+
+TARGET=$1
+# 获取最新版本号
+VERSION=$(git describe --tags `git rev-list --tags --max-count=1`)
+if [[ "${VERSION}" = "" ]]
+then
+    VERSION=0.0.1-SNAPSHOT
+fi
+
+if [[ -z ${TARGET} ]]
+then
+  # 默认平台
+  TARGET=admin
+fi
+rm -rf ${PROJECT_PATH}/dist
+if [[ $TARGET = "admin" ]]
+then
+  cd front;
+  npm run deploy:prod ${TARGET}
+  cd ../;
+  # mv admin/dist ./;
+  export UPLOAD=front/dist
+  export UPLOADED=static-${TARGET}
+elif [[ $TARGET = "www" ]]
+then
+  cd front;
+  npm run deploy:prod ${TARGET};
+  cd ../;
+  # mv web/dist  ./;
+  export UPLOAD=front/dist
+  export UPLOADED=static-${TARGET}
+elif [[ $TARGET = "gateway" ]]
+then
+  rm -rf dist
+  mkdir dist
+  export ENV=$ENV
+  cd server;
+  ./gradlew :gateway-api:bootJar 
+  cd ../
+
+  mv server/gateway-api/build/libs/gateway-api-*-boot.jar dist/gateway-api-boot.jar
+  cat server/pm2-gateway-api.json > dist/pm2.json
+  chmod +x dist/*
+
+  echo ${VERSION} > dist/LAST_VERSION
+
+  export FORCE_UPLOAD=false
+  export UPLOAD=dist
+  export UPLOADED="gateway"
+elif [[ $TARGET = "gateway-all" ]]
+then
+  rm -rf dist
+  mkdir dist
+  export ENV=$ENV
+  cd server;
+  ./gradlew :gateway-api:bootJar 
+  cd ../
+
+  mv server/gateway-api/build/libs/* dist/
+  mv dist/gateway-api-*-boot.jar dist/gateway-api-boot.jar
+  cat server/pm2-gateway-api.json > dist/pm2.json
+  chmod +x dist/*
+
+  echo ${VERSION} > dist/LAST_VERSION
+
+  export FORCE_UPLOAD=true
+  export UPLOAD=dist
+  export UPLOADED="gateway"
+fi

+ 18 - 0
deploy/uploaded.sh

@@ -0,0 +1,18 @@
+#!/bin/bash
+CURRENT_PATH=$(pwd);
+ROOT_PATH=$(cd `dirname $0`/; pwd);
+RUN_PATH=${ROOT_PATH}
+
+echo $1
+TARGET=$1
+
+cd ${RUN_PATH}
+pwd
+
+if [[ $TARGET = "gateway" ]]
+then
+  npx pm2 start --hp ${RUN_PATH} ${RUN_PATH}/pm2.json
+elif [[ $TARGET = "gateway-all" ]]
+then
+  npx pm2 start --hp ${RUN_PATH} ${RUN_PATH}/pm2.json
+fi

+ 1 - 1
front/project/Constant.js

@@ -35,7 +35,7 @@ export const SentenceOption = [{ label: '平行', value: 'parallel' }, { label:
 //   }],
 //   questions: [{
 //     description: '', // type!=inline
-//     answer: [],
+//     answer: [[true,false],[false,true]],
 //     select: [],
 //     direction: '', // type=double
 //   }],

+ 1 - 1
front/project/admin/local.json

@@ -3,7 +3,7 @@
     "scripts": [],
     "proxy": [
       {
-        "target": "http://127.0.0.1:8080",
+        "target": "http://127.0.0.1:8888",
         "from": "/api",
         "to": "/admin"
       }

+ 11 - 5
front/project/www/local.json

@@ -1,18 +1,24 @@
 {
   "development": {
-    "scripts": ["http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"],
+    "scripts": [
+      "http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"
+    ],
     "proxy": [
       {
-        "target": "http://127.0.0.1:8080",
+        "target": "http://127.0.0.1:8888",
         "from": "/api",
         "to": "/api"
       }
     ]
   },
   "test": {
-    "scripts": ["http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"]
+    "scripts": [
+      "http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"
+    ]
   },
   "production": {
-    "scripts": ["http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"]
+    "scripts": [
+      "http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"
+    ]
   }
-}
+}

+ 2 - 2
front/src/containers/App.js

@@ -64,7 +64,7 @@ export default class App extends Component {
           {routes.map(route => {
             return (
               <Route
-                exact={!((route.matchPath || route.path).indexOf(':') >= 0)}
+                exact
                 key={route.key}
                 path={route.matchPath || route.path}
                 render={props => {
@@ -104,11 +104,11 @@ export default class App extends Component {
           return this.renderPage(route, props);
       }
     }
-
     return (
       <UserStoreAsync
         config={route}
         {...props}
+        key={props.location.key}
         moduleList={this.moduleList}
         moduleMap={this.moduleMap}
         project={project}

+ 1 - 1
front/src/containers/Page.js

@@ -140,7 +140,7 @@ export default class extends Component {
   }
 
   refreshQuery(query) {
-    this.inited = false;
+    // this.inited = false;
     replaceLink(`${this.props.location.pathname}?${querystring.stringify(query)}`);
   }
 

+ 0 - 34
front/src/services/History.js

@@ -1,34 +0,0 @@
-import { createBrowserHistory as createHistory } from 'history';
-
-export const History = createHistory({ basename: __BASE_NAME__ });
-
-export const linkTo = link => {
-  /**
-   * 跳转页面
-   */
-  History.push(link);
-};
-export const replaceLink = link => {
-  /**
-   * 刷新当前页
-   */
-  History.replace(link);
-};
-export const goBack = () => {
-  /**
-   * 返回上一页
-   */
-  History.goBack();
-};
-export const toLink = link => {
-  /**
-   * 跳转页面
-   */
-  window.location.href = link;
-};
-export const openLink = link => {
-  /**
-   * 打开新页面
-   */
-  window.open(link);
-};

+ 1 - 0
front/src/stores/base.js

@@ -27,6 +27,7 @@ export default class BaseStore {
 
   setState(state) {
     if (!this.store) throw new Error('store init error');
+    console.log('setState', state);
     this.store.dispatch({
       key: this.key,
       type: STORE_UPDATE,

+ 1 - 1
front/src/stores/other.js

@@ -1,5 +1,5 @@
 import * as querystring from 'querystring';
-import { History, linkTo, goBack, replaceLink } from '../services/History';
+import { History } from '../services';
 import Base from './base';
 import { STORE_LOADING, STORE_LOADED } from '../services/Constant';
 

+ 66 - 18
server/build.gradle

@@ -5,6 +5,7 @@ apply from: 'dependencyDefine.gradle'
 buildscript {
     ext {
         springBootVersion = '2.1.3.RELEASE'
+//        wrapperVersion = '1.0.21.RELEASE'
     }
     repositories {
         mavenLocal()
@@ -15,6 +16,7 @@ buildscript {
         }
     }
     dependencies {
+//        classpath("org.springframework.boot.experimental:spring-boot-thin-gradle-plugin:${wrapperVersion}")
         classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
     }
 }
@@ -22,6 +24,7 @@ buildscript {
 subprojects {
     apply plugin: 'java'
     apply plugin: "idea"
+    apply plugin: 'maven'
 //    apply plugin: 'eclipse'
     apply plugin: 'org.springframework.boot'
     apply plugin: 'io.spring.dependency-management'
@@ -41,29 +44,54 @@ subprojects {
         maven { url = "http://maven.aliyun.com/nexus/content/groups/public" }
         mavenCentral()
     }
+
+    configurations{
+        parentClasspath {}
+    }
+
+// 清除现有的lib目录
+    task clearJar(type: Delete) {
+        delete "$buildDir/libs/lib"
+    }
+
+// 将依赖包复制到lib目录
+    task copyJar(type: Copy, dependsOn: 'clearJar') {
+        from configurations.compileClasspath
+        into "$buildDir/libs/lib"
+    }
+
     dependencies {
-        compile("org.springframework.boot:spring-boot-starter")
-        compile("org.springframework.boot:spring-boot-starter-web")
-        compile('org.springframework.boot:spring-boot-starter-aop')
-        compile('org.springframework.boot:spring-boot-starter-jdbc')
-        compile('org.springframework.boot:spring-boot-starter-data-jpa')
-//	compile("org.springframework.boot:spring-boot-starter-security")
-        compile("org.springframework.boot:spring-boot-starter-actuator")
-        compile('org.springframework.boot:spring-boot-starter-logging')
-        compile('org.springframework.boot:spring-boot-starter-cache')
-        compile('org.springframework.boot:spring-boot-starter-data-redis')
-        compile("org.springframework.boot:spring-boot-devtools")
-
-        compile('mysql:mysql-connector-java')
+        compileClasspath("org.springframework.boot:spring-boot-starter")
+        compileClasspath("org.springframework.boot:spring-boot-starter-web")
+        compileClasspath('org.springframework.boot:spring-boot-starter-aop')
+        compileClasspath('org.springframework.boot:spring-boot-starter-jdbc')
+        compileClasspath('org.springframework.boot:spring-boot-starter-data-jpa')
+//	compileClasspath("org.springframework.boot:spring-boot-starter-security")
+        compileClasspath("org.springframework.boot:spring-boot-starter-actuator")
+        compileClasspath('org.springframework.boot:spring-boot-starter-logging')
+        compileClasspath('org.springframework.boot:spring-boot-starter-cache')
+        compileClasspath('org.springframework.boot:spring-boot-starter-data-redis')
+        compileClasspath("org.springframework.boot:spring-boot-devtools")
+
+        compileClasspath('mysql:mysql-connector-java')
+        compileClasspath(libraries."mybatis", libraries."mybatis-page")
+        compileClasspath("tk.mybatis:mapper-spring-boot-starter:2.1.5"){
+            exclude group: "javax.persistence"
+        }
 
         testCompile("org.springframework.boot:spring-boot-starter-test")
 
-        compile fileTree(dir:'libs',include:['*.jar'])
-    }
 
+        compileClasspath group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.9'
+        compileClasspath group: 'com.alibaba', name: 'fastjson', version: '1.2.46'
+        compileClasspath 'javax.persistence:javax.persistence-api:2.2'
+
+        compileClasspath fileTree(dir:'libs',include:['*.jar'])
+    }
 
 //自定义环境 start
-    def env = System.getProperty("env") ?: "dev"
+    def env = System.getProperty("ENV") ?: (System.getenv("ENV") ?: "dev")
+    println(env)
     sourceSets {
         main {
             resources {
@@ -85,6 +113,8 @@ subprojects {
 configure(subprojects.findAll {it.name.contains('api')}) {
     apply plugin: 'war'
     apply plugin: 'application'
+//    apply plugin: 'org.springframework.boot.experimental.thin-launcher'
+
     springBoot {
         buildInfo()
     }
@@ -95,10 +125,26 @@ configure(subprojects.findAll {it.name.contains('api')}) {
 //        }
 //    }
 
+//    task createPom {
+//        doLast {
+//            pom {
+//                withXml(dependencyManagement.pomConfigurer)
+//            }.writeTo("build/resources/main/META-INF/maven/${project.group}/${project.name}/pom.xml")
+//        }
+//    }
+//
+//    thinResolvePrepare {
+//        into new File("${buildDir}/thin/deploy")
+//    }
+//
+//    jar.dependsOn = [createPom]
+
+
     dependencies {
 //    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
-        providedRuntime 'org.springframework.boot:spring-boot-starter-jetty'
+//        providedRuntime 'org.springframework.boot:spring-boot-starter-jetty'
     }
+
 }
 
 project(':data') {
@@ -110,5 +156,7 @@ project(':gateway-api') {
     dependencies {
         compile(project(":tools"))
         compile(project(":data"))
+        compileClasspath project(path:":tools", configuration: 'parentClasspath')
+        compileClasspath project(path:":data", configuration: 'parentClasspath')
     }
-}
+}

+ 6 - 2
server/data/build.gradle

@@ -10,10 +10,11 @@ repositories {
 
 dependencies {
     //mybatis
-    compile(libraries."mybatis", libraries."mybatis-mapper")
+//    compileClasspath(libraries."mybatis", libraries."mybatis-mapper", libraries."mybatis-page")
 
     //flyway
-    compile(libraries."flyway")
+    compileClasspath libraries."flyway" 
+    parentClasspath libraries."flyway"
 }
 
 //mybatis generator plugin ------ start
@@ -67,5 +68,8 @@ flyway {
 apply plugin: 'java-library'
 
 jar {
+    // lib目录的清除和复制任务
+//    dependsOn clearJar
+//    dependsOn copyJar
     enabled=true
 }

+ 0 - 1
server/data/src/main/java/com/qxgmat/data/relation/UserPaperRelationMapper.java

@@ -1,6 +1,5 @@
 package com.qxgmat.data.relation;
 
-import com.github.pagehelper.Page;
 import com.qxgmat.data.dao.entity.UserPaper;
 import org.apache.ibatis.annotations.Param;
 

+ 33 - 12
server/gateway-api/build.gradle

@@ -8,30 +8,51 @@ repositories {
     mavenCentral()
 }
 
-bootJar {
-    classifier = 'boot'
-    manifest {
-        attributes 'Start-Class': mainClassName
-    }
-    excludeDevtools = false
-}
 
 dependencies {
     // shiro
 //    compile(libraries."shiro-core", libraries."shiro-spring", libraries."shiro-cache")
-    compile(libraries."shiro")
+    compileClasspath libraries."shiro"
 
     // druid
-    compile('com.alibaba:druid-spring-boot-starter:1.1.10')
+    compileClasspath 'com.alibaba:druid-spring-boot-starter:1.1.10'
 
     // swagger
-    compile(libraries."springfox-bean-validators", libraries."springfox-swagger2", libraries."springfox-swagger-ui")
+    compileClasspath libraries."springfox-bean-validators", libraries."springfox-swagger2", libraries."springfox-swagger-ui"
 
-    compile 'com.github.penggle:kaptcha:2.3.2'
+    compileClasspath 'com.github.penggle:kaptcha:2.3.2'
 
 //    compile group: 'commons-lang', name: 'commons-lang', version:'2.6'
 //    compile group: 'commons-fileupload', name: 'commons-fileupload', version:'1.3.3'
 //    compile group: 'commons-io', name: 'commons-io', version:'2.6'
 //    compile group: 'commons-codec', name: 'commons-codec', version:'1.11'
 //    compile group: 'commons-configuration', name: 'commons-configuration', version:'1.10'
-}
+}
+
+bootJar {
+    classifier = 'boot'
+
+    // lib目录的清除和复制任务
+    dependsOn clearJar
+    dependsOn copyJar
+
+    manifest {
+        // Properties 允许加载扩展jar,是compileClasspath生效,定义在loader.properties
+        // https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#executable-jar-launching
+        attributes 'Main-Class': 'org.springframework.boot.loader.PropertiesLauncher'
+        attributes 'Start-Class': mainClassName
+    }
+    excludeDevtools = true
+}
+
+bootRun {
+    dependsOn copyJar
+    classpath +=files(fileTree(dir:"${libsDir}/lib/",include:['*.jar']))
+//    jvmArgs = ["-Dloader.path=${libsDir}/lib", "-Dloader.debug=true"]
+//    mainClassName = 'org.springframework.boot.loader.PropertiesLauncher'
+}
+//task runLocal(type: JavaExec) {
+//    dependsOn bootJar
+//    main="org.springframework.boot.loader.PropertiesLauncher"
+//    args("-Dloader.path=${libsDir}/lib -Dloader.debug=true")
+//}

+ 1 - 2
server/gateway-api/src/main/java/com/qxgmat/help/SmsHelp.java

@@ -1,6 +1,5 @@
 package com.qxgmat.help;
 
-import com.aliyuncs.exceptions.ClientException;
 import com.qxgmat.data.constants.SessionKey;
 import com.qxgmat.dto.SmsSessionDto;
 import com.nuliji.tools.Transform;
@@ -53,7 +52,7 @@ public class SmsHelp {
         try {
             Object response = aliyun.sendSms(mobile, templateId, code);
             dto.setResponse(Transform.convert(response, SendSmsResponse.class));
-        } catch (ClientException e) {
+        } catch (Exception e) {
             logger.error("发送短信失败", e);
             return false;
         }

+ 1 - 1
server/gateway-api/src/main/profile/dev/application-runtime.yml

@@ -1,5 +1,5 @@
 server:
-  port: 8080
+  port: 8888
   tomcat:
     uri-encoding: utf-8
 

+ 7 - 0
server/gateway-api/src/main/profile/prod/application-runtime.yml

@@ -82,3 +82,10 @@ spring:
         max-wait: 10000
     # 连接超时时间(毫秒)
     timeout: 0
+
+upload:
+  local_path: ./upload/
+  web_url: /upload/
+
+third:
+  redirectUrl: http://127.0.0.1:8080

+ 91 - 0
server/gateway-api/src/main/profile/test/application-runtime.yml

@@ -0,0 +1,91 @@
+server:
+  port: 8080
+  tomcat:
+    uri-encoding: utf-8
+
+spring:
+  datasource:
+    druid:
+      # 数据库访问配置, 使用druid数据源
+      type: com.alibaba.druid.pool.DruidDataSource
+      driver-class-name: com.mysql.cj.jdbc.Driver
+      url: jdbc:mysql://127.0.0.1:3306/qianxing?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
+      username: qianxing
+      password: qianxing
+      # 连接池配置
+      initial-size: 5
+      min-idle: 5
+      max-active: 20
+      # 连接等待超时时间
+      max-wait: 30000
+      # 配置检测可以关闭的空闲连接间隔时间
+      time-between-eviction-runs-millis: 60000
+      # 配置连接在池中的最小生存时间
+      min-evictable-idle-time-millis: 300000
+      validation-query: select '1' from dual
+      test-while-idle: true
+      test-on-borrow: false
+      test-on-return: false
+      # 打开PSCache,并且指定每个连接上PSCache的大小
+      pool-prepared-statements: true
+      max-open-prepared-statements: 20
+      max-pool-prepared-statement-per-connection-size: 20
+      # 配置监控统计拦截的filters, 去掉后监控界面sql无法统计, 'wall'用于防火墙
+      filters: stat
+      # Spring监控AOP切入点,如x.y.z.service.*,配置多个英文逗号分隔
+      aop-patterns: cc.mrbird.servie.*
+
+      # WebStatFilter配置
+      web-stat-filter:
+        enabled: true
+        # 添加过滤规则
+        url-pattern: /*
+        # 忽略过滤的格式
+        exclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*'
+
+      # StatViewServlet配置
+      stat-view-servlet:
+        enabled: true
+        # 访问路径为/druid时,跳转到StatViewServlet
+        url-pattern: /druid/*
+        # 是否能够重置数据
+        reset-enable: false
+        # 需要账号密码才能访问控制台
+        login-username: druid
+        login-password: druid123
+        # IP白名单
+        # allow: 127.0.0.1
+        # IP黑名单(共同存在时,deny优先于allow)
+        # deny: 192.168.1.218
+
+      # 配置StatFilter
+      filter:
+        stat:
+          log-slow-sql: true
+
+  redis:
+    # Redis数据库索引(默认为0)
+    database: 0
+    # Redis服务器地址
+    host: 127.0.0.1
+    # Redis服务器连接端口
+    port: 6379
+    jedis:
+      pool:
+        # 连接池中的最小空闲连接
+        min-idle: 8
+        # 连接池中的最大空闲连接
+        max-idle: 500
+        # 连接池最大连接数(使用负值表示没有限制)
+        max-active: 2000
+        # 连接池最大阻塞等待时间(使用负值表示没有限制)
+        max-wait: 10000
+    # 连接超时时间(毫秒)
+    timeout: 0
+
+upload:
+  local_path: ./upload/
+  web_url: /upload/
+
+third:
+  redirectUrl: http://127.0.0.1:8080

+ 2 - 0
server/gateway-api/src/main/resources/loader.properties

@@ -0,0 +1,2 @@
+loader.path=lib/
+loader.debug=true

+ 17 - 0
server/pm2-gateway-api.json

@@ -0,0 +1,17 @@
+{
+  "apps": [
+    {
+      "name": "gateway",
+      "instances": 1,
+      "exec_mode": "fork",
+      "script": "/usr/bin/java",
+      "args": [
+        "-jar",
+        "./gateway-api-boot.jar"
+      ],
+      "interpreter": "",
+      "interpreter_args": "",
+      "cwd": "./"
+    }
+  ]
+}

+ 17 - 9
server/tools/build.gradle

@@ -10,36 +10,44 @@ repositories {
 dependencies {
     // shiro
 //    compile(libraries."shiro-core", libraries."shiro-spring", libraries."shiro-cache")
-    compile(libraries."shiro")
+    compileClasspath libraries."shiro"
+    parentClasspath libraries."shiro"
 
     //swagger
-    compile(libraries."springfox-swagger2")
+    compileClasspath libraries."springfox-swagger2"
+    parentClasspath libraries."springfox-swagger2"
 
     //mybatis
-    compile(libraries."mybatis", libraries."mybatis-mapper", libraries."mybatis-generator", libraries."mybatis-page")
+    compileClasspath libraries."mybatis-generator"
+    parentClasspath libraries."mybatis-generator"
     
     // redis 依赖
-    compile(libraries."commons-pool2")
+    compileClasspath libraries."commons-pool2"
+    parentClasspath libraries."commons-pool2"
 
     // cache
-    compile(libraries."ehcache", libraries."ehcache-api")
+    compileClasspath libraries."ehcache", libraries."ehcache-api"
+    parentClasspath libraries."ehcache", libraries."ehcache-api"
     
     // modelmapper
-    compile 'com.github.rozidan:modelmapper-spring-boot-starter:1.0.0'
+    compileClasspath 'com.github.rozidan:modelmapper-spring-boot-starter:1.0.0'
+    parentClasspath 'com.github.rozidan:modelmapper-spring-boot-starter:1.0.0'
 
     // https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
-    compile group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.2.0'
+    compileClasspath group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.2.0'
+    parentClasspath group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.2.0'
 
     compile group: 'com.aliyun', name: 'aliyun-java-sdk-core', version:'3.3.1'
     compile group: 'com.aliyun', name: 'aliyun-java-sdk-dysmsapi', version: '1.0.0'
     compile group: 'com.aliyun.oss', name: 'aliyun-sdk-oss', version:'2.5.0'
-    compile group: 'com.alibaba', name: 'fastjson', version: '1.2.46'
-    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.9'
 
 }
 
 apply plugin: 'java-library'
 
 jar {
+    // lib目录的清除和复制任务
+//    dependsOn clearJar
+//    dependsOn copyJar
     enabled=true
 }