yingp 8 rokov pred
rodič
commit
bfece1eda0

+ 15 - 0
build.gradle

@@ -4,6 +4,8 @@ version '1.0.0'
 buildscript {
     ext {
         springBootVersion = '1.4.4.RELEASE'
+        dockerVersion = '0.12.0'
+        dockerRegistry = "10.10.100.200:5000"
     }
     repositories {
         maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
@@ -14,6 +16,7 @@ buildscript {
     }
     dependencies {
         classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
+        classpath "gradle.plugin.com.palantir.gradle.docker:gradle-docker:${dockerVersion}"
     }
 }
 
@@ -21,6 +24,7 @@ apply plugin: 'java'
 apply plugin: 'idea'
 apply plugin: 'maven'
 apply plugin: 'org.springframework.boot'
+apply plugin: "com.palantir.docker"
 
 jar {
     baseName = project.name
@@ -33,6 +37,7 @@ repositories {
     mavenLocal()
     maven { url "http://repo.spring.io/libs-milestone" }
     maven { url "http://repo.spring.io/libs-release" }
+	maven { url "http://10.10.101.21:8081/artifactory/libs-release-local" }
     maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
     mavenCentral()
 }
@@ -52,6 +57,16 @@ dependencies {
     compile "com.alibaba:fastjson:$fastjsonVersion"
 }
 
+bootRun {
+    addResources = true
+}
+
+docker {
+    name "${dockerRegistry}/${project.name}:${project.version}"
+    dockerfile "${projectDir}/src/main/docker/Dockerfile"
+    files "${buildDir}/libs/${project.name}.jar"
+}.dependsOn build
+
 uploadArchives {
     repositories {
         mavenDeployer {

+ 6 - 0
src/main/docker/Dockerfile

@@ -0,0 +1,6 @@
+FROM hub.c.163.com/library/java:8-jre-alpine
+VOLUME /tmp # reate a temporary file on my host under "/var/lib/docker" and link it to the container under "/tmp".
+ADD uas_database.jar app.jar
+RUN sh -c "touch /app.jar" #  "touch" the jar file so that it has a file modification time (Docker creates all container files in an "unmodified" state by default). This actually isn’t important for the simple app that we wrote, but any static content (e.g. "index.html") would require the file to have a modification time.
+ENV JAVA_OPTS=""
+ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -Dspring.profiles.active=prod -Duser.timezone=GMT+08 -Djava.security.egd=file:/dev/./urandom -jar /app.jar"] # To reduce Tomcat startup time we added a system property pointing to "/dev/urandom" as a source of entropy.

+ 2 - 0
src/main/java/com/uas/erp/database/config/DataSourceConfig.java

@@ -6,6 +6,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
 import org.springframework.jdbc.core.JdbcTemplate;
 
 import javax.sql.DataSource;
@@ -18,6 +19,7 @@ import java.util.HashMap;
 @Configuration
 public class DataSourceConfig{
 
+    @Primary
     @Bean(name = "primaryDataSource")
     @ConfigurationProperties(prefix = "spring.datasource.primary")
     public DataSource primaryDataSource(){

+ 1 - 1
src/main/resources/application.yml

@@ -46,4 +46,4 @@ spring:
   profiles: prod
   datasource:
     primary:
-      url: jdbc:h2:file:~/data/db;DB_CLOSE_ON_EXIT=FALSE
+      url: jdbc:h2:file:~/data/uas_database;FILE_LOCK=NO;DB_CLOSE_ON_EXIT=FALSE