Browse Source

完成docker的自动打包和上传到及镜像中心的配置

tuonina 6 years ago
parent
commit
30a6d68c78

+ 55 - 1
README.md

@@ -77,4 +77,58 @@ Jetty 更加轻量化,更符合Spring Cloud 分布式部署;当然,这个
 - 日志记录
 - 即时通信(估计会另外建一个项目来做即时通信)
 - 网关的权限管理。
-- 阿里云对象存储,前后端文件上传功能。
+- 阿里云对象存储,前后端文件上传功能。
+
+
+## Docker 相关介绍
+### 打包
+运行任务 : task dockerBuilder。
+特别注意在打包之前需要在idea 的命令行中登陆到镜像中心。
+登陆命令为:docker login --username=gxzcalyqy registry.cn-qingdao.aliyuncs.com
+密码为:docker20181018
+
+
+如果一切没有问题,打包成功之后会自动上传到镜像中心。等待上传完成。出现如下提示说明上传完成:
+
+        
+    BUILD SUCCESSFUL in 4m 10s
+    26 actionable tasks: 5 executed, 21 up-to-date
+    17:40:25: Task execution finished 'dockerBuilder'.
+
+
+### 关键参数
+- IP 宿主机的ip
+- PORT 服务部署的端口号
+- NAME 容器名称,这个自定义
+- IMAGE_NAME 镜像名称或者镜像的ID
+
+### 运行命令
+
+docker run -t  --name `NAME` --expose=`PORT`  -p `PORT`:`PORT` -e "EUREKA_INSTANCE_IP-ADDRESS=`IP`" -e "SERVER_PORT=`PORT`"  IMAGE_NAME
+
+### 注意事项
+
+- 修改zen-web下的zen-web.gradle 中 task dockerBuilder applicationName为项目自己的内容
+
+以下片段位于zen-web.gradle ,修改其中的applicationName
+
+
+        task dockerBuilder(type: Docker) {
+            registry='registry.cn-qingdao.aliyuncs.com/gxzc-envir'
+            applicationName = 'fw'
+            tagVersion = jar.version
+            addFile("./build/libs/${jar.baseName}-${jar.version}.jar","app.jar")
+            entryPoint(["java","-Djava.security.egd=file:/dev/./urandom","-jar",'app.jar'])
+            exposePort(11000)
+            doFirst {
+                copy {
+                    from jar
+                    into stageDir
+                }
+            }
+            push = true
+        }
+        
+        
+        
+## 其他说明

+ 2 - 2
build.gradle

@@ -43,8 +43,8 @@ buildscript {
 }
 
 allprojects {
-    group = "com.gxzc.zen"
-    version = "1.0-SNAPSHOT"
+    group = "cn.gygxzc.cloud"
+    version = "1.0"
 }
 
 subprojects {

+ 1 - 1
cloud-bus/build.gradle

@@ -10,4 +10,4 @@ repositories {
 
 dependencies {
     compile 'org.springframework.cloud:spring-cloud-starter-bus-amqp'
-}
+}

+ 0 - 19
zen-api/src/test/kotlin/com/gxzc/zen/api/PasswordGen.kt

@@ -1,19 +0,0 @@
-package com.gxzc.zen.api
-
-import org.apache.shiro.crypto.hash.SimpleHash
-import org.junit.Test
-
-/**
- *
- * @author NorthLan
- * @date 2018/4/24
- * @url https://noahlan.com
- */
-class PasswordGen {
-    @Test
-    fun genPassword() {
-        println(SimpleHash("md5", "123456", "guest" + "hahahaha", 2))
-        println(SimpleHash("md5", "123456", "guest" + "hahahaha", 2).toHex())
-        println(SimpleHash("md5", "123456", "guest" + "hahahaha", 2).toString())
-    }
-}

+ 0 - 35
zen-api/src/test/kotlin/com/gxzc/zen/api/TestCollectionUtil.kt

@@ -1,35 +0,0 @@
-package com.gxzc.zen.api
-
-import org.apache.commons.collections.CollectionUtils
-import org.junit.Test
-
-/**
- *
- * @author NorthLan
- * @date 2018/5/4
- * @url https://noahlan.com
- */
-@Suppress("UNUSED_VARIABLE")
-class TestCollectionUtil {
-    @Test
-    fun testJiao() {
-        val a = mutableListOf<Int>().apply {
-            add(1)
-            add(2)
-            add(3)
-        }
-
-        val b = mutableListOf<Int>().apply {
-            add(1)
-            add(4)
-        }
-        // 差集 a b
-        val asubb = CollectionUtils.subtract(b, a)
-        // 并集
-        val union = CollectionUtils.union(a, b)
-        // 交集
-        val ins = CollectionUtils.intersection(a, b)
-
-        println("test")
-    }
-}

+ 0 - 110
zen-api/src/test/kotlin/com/gxzc/zen/api/TestDictTypeTreeRedis.kt

@@ -1,110 +0,0 @@
-//package com.gxzc.zen.api
-//
-//import com.fasterxml.jackson.databind.ObjectMapper
-//import com.gxzc.zen.api.sys.common.DictTypeTree
-//import com.gxzc.zen.common.util.TreeUtil
-//import org.junit.Test
-//
-///**
-// *
-// * @author NorthLan
-// * @date 2018/4/28
-// * @url https://noahlan.com
-// */
-//class TestDictTypeTreeRedis {
-//
-//    fun buildData(): MutableList<DictTypeTree> {
-//        return mutableListOf<DictTypeTree>().apply {
-//            add(DictTypeTree().apply {
-//                id = 1
-//                parentId = 0
-//                type = 1
-//            })
-//            add(DictTypeTree().apply {
-//                id = 2
-//                parentId = 1
-//                type = 1
-//            })
-//            add(DictTypeTree().apply {
-//                id = 3
-//                parentId = 1
-//                type = 1
-//            })
-//            add(DictTypeTree().apply {
-//                id = 4
-//                parentId = 2
-//                type = 1
-//                code = "test"
-//            })
-//            add(DictTypeTree().apply {
-//                id = 5
-//                parentId = 4
-//                type = 2
-//                value = "1"
-//                code = "test"
-//            })
-//            add(DictTypeTree().apply {
-//                id = 6
-//                parentId = 4
-//                type = 2
-//                value = "2"
-//                code = "test"
-//            })
-//            add(DictTypeTree().apply {
-//                id = 7
-//                parentId = 4
-//                type = 2
-//                value = "3"
-//                code = "test"
-//            })
-//            add(DictTypeTree().apply {
-//                id = 8
-//                parentId = 4
-//                type = 2
-//                value = "4"
-//                code = "test"
-//            })
-//            add(DictTypeTree().apply {
-//                id = 9
-//                parentId = 4
-//                type = 2
-//                value = "5"
-//                code = "test"
-//            })
-//            add(DictTypeTree().apply {
-//                id = 10
-//                parentId = 4
-//                type = 2
-//                value = "6"
-//                code = "test"
-//            })
-//        }
-//    }
-//
-//    @Test
-//    fun testTreeFind() {
-//        val data = buildData()
-//        val tree = TreeUtil.buildByRecursive(data, 0)
-//
-//        println(ObjectMapper().writeValueAsString(tree))
-//
-//        var now = System.currentTimeMillis()
-//        val find = TreeUtil.findBFS(tree) {
-//            it.type == 1 && it.code == "test"
-//        }
-//
-//        println("BFS: ${System.currentTimeMillis() - now}")
-//
-//        println(ObjectMapper().writeValueAsString(find))
-//
-//        now = System.currentTimeMillis()
-//        val find2 = TreeUtil.findDFS(tree) {
-//            it.type == 1 && it.code == "test"
-//        }
-//
-//        println("DFS: ${System.currentTimeMillis() - now}")
-//
-//
-//        println(ObjectMapper().writeValueAsString(find2))
-//    }
-//}

+ 0 - 24
zen-api/src/test/kotlin/com/gxzc/zen/api/TestKotlinReplace.kt

@@ -1,24 +0,0 @@
-package com.gxzc.zen.api
-
-import org.junit.Test
-import java.util.regex.Pattern
-
-/**
- *
- * @author NorthLan
- * @date 2018/4/29
- * @url https://noahlan.com
- */
-class TestKotlinReplace {
-
-    @Test
-    fun testKotlinReplace() {
-        val url = "/user/info/{*}"
-        val patternUrl = url.replace("\\{\\*}".toRegex(), "[a-zA-Z\\\\d]+")
-        println("^$patternUrl\$")
-
-        println(Pattern.compile("^$patternUrl\$").matcher("/user/info/1").find())
-
-        println("/user/info/haha".startsWith("/user/info" + "/"))
-    }
-}

+ 0 - 22
zen-api/src/test/kotlin/com/gxzc/zen/api/TestTreePath.kt

@@ -1,22 +0,0 @@
-package com.gxzc.zen.api
-
-import com.gxzc.zen.common.contants.ZenConstants
-import org.junit.Test
-
-/**
- *
- * @author NorthLan
- * @date 2018/4/30
- * @url https://noahlan.com
- */
-class TestTreePath {
-    @Test
-    fun test1() {
-        val path = "1-2-3-4"
-        val paths = path.split(ZenConstants.TREE_PATH_SEPARATOR)
-        println(path)
-        println(paths)
-        val a = paths.subList(0, paths.size - 2)
-        println(a)
-    }
-}

+ 0 - 39
zen-api/src/test/kotlin/com/gxzc/zen/api/base/BaseTestKt.kt

@@ -1,39 +0,0 @@
-package com.gxzc.zen.api.base
-
-import org.junit.Before
-import org.junit.runner.RunWith
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.boot.test.context.SpringBootTest
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
-import org.springframework.test.context.web.WebAppConfiguration
-import org.springframework.test.web.servlet.MockMvc
-import org.springframework.test.web.servlet.setup.MockMvcBuilders
-import org.springframework.web.context.WebApplicationContext
-
-/**
- * Spring单元测试基类
- * @author NorthLan
- * @date 2018/1/26
- * @url https://noahlan.com
- */
-@RunWith(SpringJUnit4ClassRunner::class)
-@SpringBootTest
-@WebAppConfiguration
-//@Transactional  // 事物支持
-class BaseTestKt {
-
-    @Autowired
-    lateinit var webApplicationContext: WebApplicationContext
-
-    lateinit var mockMvc: MockMvc
-
-    @Before
-    fun setupMockMvc() {
-        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build()
-    }
-
-    @Before
-    fun initDataBase() {
-        // Nothing
-    }
-}

+ 41 - 2
zen-web/build.gradle

@@ -1,6 +1,9 @@
 //apply plugin: 'jar'
 //apply plugin: 'war'
 
+apply plugin: 'docker'
+apply plugin: 'application'
+
 buildscript {
     repositories {
         mavenCentral()
@@ -9,6 +12,7 @@ buildscript {
         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
         classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
         classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
+        classpath('se.transmode.gradle:gradle-docker:1.2')
     }
 }
 
@@ -17,5 +21,40 @@ dependencies {
     compile project(':cloud-bus')
 }
 
-bootJar { enabled = true }
-jar { enabled = false }
+docker{
+    baseImage 'openjdk:8-jdk-alpine'
+    maintainer 'tina 976056042@qq.com'
+    registry 'registry.cn-qingdao.aliyuncs.com'
+}
+
+task dockerBuilder(type: Docker) {
+    registry='registry.cn-qingdao.aliyuncs.com/gxzc-envir'
+    applicationName = 'fw'
+    tagVersion = jar.version
+    addFile("./build/libs/${jar.baseName}-${jar.version}.jar","app.jar")
+    entryPoint(["java","-Djava.security.egd=file:/dev/./urandom","-jar",'app.jar'])
+    exposePort(11000)
+    doFirst {
+        copy {
+            from jar
+            into stageDir
+        }
+    }
+    push = true
+}
+
+dockerBuilder.dependsOn(bootJar)
+
+
+bootJar {
+    enabled = true
+}
+
+jar {
+    enabled = false
+}
+
+//实际上这个配置是没有用的,distDocker 打包出来的,启动不了
+startScripts{
+    mainClassName='org.springframework.boot.loader.JarLauncher'
+}

+ 0 - 1
zen-web/src/main/resources/bootstrap.yml

@@ -24,7 +24,6 @@ spring:
 
 eureka:
   instance:
-    ip-address: 192.168.1.96  # 改成自己电脑ip,现阶段没有关系
     prefer-ip-address: true
   client:
     service-url:

+ 0 - 11
zen-web/src/test/kotlin/com/gxzc/zen/Test.kt

@@ -1,11 +0,0 @@
-package com.gxzc.zen
-
-/**
- *
- * @author NorthLan
- * @date 2018/9/9
- * @url https://noahlan.com
- */
-class Test {
-
-}

+ 0 - 39
zen-web/src/test/kotlin/com/gxzc/zen/base/BaseTestKt.kt

@@ -1,39 +0,0 @@
-package com.gxzc.zen.base
-
-import org.junit.Before
-import org.junit.runner.RunWith
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.boot.test.context.SpringBootTest
-import org.springframework.test.context.junit4.SpringRunner
-import org.springframework.test.context.web.WebAppConfiguration
-import org.springframework.test.web.servlet.MockMvc
-import org.springframework.test.web.servlet.setup.MockMvcBuilders
-import org.springframework.web.context.WebApplicationContext
-
-/**
- * Spring单元测试基类
- * @author NorthLan
- * @date 2018/1/26
- * @url https://noahlan.com
- */
-@RunWith(SpringRunner::class)
-@SpringBootTest
-@WebAppConfiguration
-//@Transactional  // 事物支持
-class BaseTestKt {
-
-    @Autowired
-    lateinit var webApplicationContext: WebApplicationContext
-
-    lateinit var mockMvc: MockMvc
-
-    @Before
-    fun setupMockMvc() {
-        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build()
-    }
-
-    @Before
-    fun initDataBase() {
-        // Nothing
-    }
-}

+ 0 - 23
zen-web/src/test/kotlin/com/gxzc/zen/cache/TestCacheController.kt

@@ -1,23 +0,0 @@
-package com.gxzc.zen.cache
-
-import com.gxzc.zen.base.BaseTestKt
-import org.junit.Test
-import org.springframework.http.MediaType
-import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
-import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content
-import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
-
-/**
- *
- * @author NorthLan at 2018/2/5
- */
-class TestCacheController : BaseTestKt() {
-
-    @Test
-    fun loadUser() {
-        mockMvc.perform(get("/")
-                .accept(MediaType.parseMediaType("application/response;charset=UTF-8")))
-                .andExpect(status().isOk)
-                .andExpect(content().contentType("application/response"))
-    }
-}

+ 0 - 12
zen-web/src/test/kotlin/com/gxzc/zen/fun/TestLogicDelete.kt

@@ -1,12 +0,0 @@
-package com.gxzc.zen.`fun`
-
-import com.gxzc.zen.base.BaseTestKt
-
-/**
- *
- * @author NorthLan
- * @date 2018/1/30
- * @url https://noahlan.com
- */
-class TestLogicDelete : BaseTestKt() {
-}