Browse Source

init from phab

xielq 4 years ago
parent
commit
621c71b386

+ 0 - 0
README.md


+ 21 - 0
build.gradle

@@ -0,0 +1,21 @@
+apply from: "$rootDir/gradle/service-base.gradle"
+apply from: "$rootDir/gradle/publish.gradle"
+apply from: "$rootDir/gradle/docker.gradle"
+
+group 'com.uas.cloud.base'
+version '0.1.0'
+
+ext {
+    baseName = 'base-edge-service'
+    artifactId = 'base-edge-service'
+}
+
+jar {
+    baseName = "${baseName}"
+    version = "${version}"
+}
+
+dependencies {
+    compile 'org.springframework.cloud:spring-cloud-starter-zuul'
+    compile 'org.springframework.cloud:spring-cloud-starter-oauth2'
+}

+ 40 - 0
gradle/docker.gradle

@@ -0,0 +1,40 @@
+buildscript {
+    ext {
+        springBootVersion = '1.4.4.RELEASE'
+    }
+    repositories {
+        maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
+        mavenCentral()
+        jcenter()
+    }
+    dependencies {
+        classpath('se.transmode.gradle:gradle-docker:1.2')
+    }
+}
+
+//apply plugin: 'docker'
+apply plugin: se.transmode.gradle.plugins.docker.DockerPlugin
+
+// 这里产生的镜像的标签会和 project。group一样,暂未找到解决办法
+// tag = "${project.group}/${applicationName}:${tagVersion}"
+task buildDocker(type:Docker, dependsOn: build) {
+    push = true
+//    applicationName = jar.baseName
+
+    tag = "10.10.100.200:5000/${jar.baseName}"
+    dockerfile = file('src/main/docker/Dockerfile')
+    doFirst {
+        copy {
+            from jar
+            into stageDir
+        }
+    }
+}
+
+docker {
+    hostUrl 'https://192.168.99.100:2376' // set the URL used to contact the Docker server. Defaults to http://localhost:2375
+    dockerBinary 'C:\\Program Files\\Docker Toolbox\\docker.exe'
+    useApi false // Use the Docker Remote API instead of a locally installed docker binary.
+    maintainer  'yangck'// The name and email address of the image maintainer.
+    registry '10.10.100.200:5000' // The hostname and port of the Docker image registry unless the Docker Hub Registry is used.
+}

+ 78 - 0
gradle/publish.gradle

@@ -0,0 +1,78 @@
+task sourcesJar(type: Jar) {
+    baseName "${baseName}"
+    classifier 'sources'
+    from sourceSets.main.allSource
+}
+artifacts {
+    archives sourcesJar
+}
+
+apply plugin: 'distribution'
+
+distributions {
+    main {
+        baseName = archivesBaseName
+
+        contents {
+            from { libsDir }
+        }
+    }
+
+    docs {
+        baseName = "$archivesBaseName-docs"
+
+        contents {
+            from(libsDir) {
+                include sourcesJar.archiveName
+            }
+        }
+    }
+}
+
+ext {
+    artifactoryBaseUrl = 'http://113.105.74.141:8081/artifactory'
+    artifactorySnapshotRepoUrl = "$artifactoryBaseUrl/libs-snapshot-local"
+    artifactoryReleaseRepoUrl = "$artifactoryBaseUrl/libs-release-local"
+}
+
+apply plugin: 'maven-publish'
+
+publishing {
+    publications {
+        plugin(MavenPublication) {
+            from components.java
+            artifactId "${artifactId}"
+
+            pom.withXml {
+                def root = asNode()
+                root.appendNode('name', 'dfs service')
+                root.appendNode('description', '商城首页 app')
+                root.appendNode('inceptionYear', '2017')
+
+                def developer = root.appendNode('developers').appendNode('developer')
+                developer.appendNode('id', 'yangck')
+                developer.appendNode('name', '杨朝坤')
+                developer.appendNode('email', 'yangck@usoftchina.com')
+            }
+
+            artifact sourcesJar
+        }
+    }
+
+    repositories {
+        maven {
+            name 'myLocal'
+            url "file://$projectDir/repo"
+        }
+
+        maven {
+            name 'remoteArtifactory'
+            url project.version.endsWith('-SNAPSHOT') ? artifactorySnapshotRepoUrl : artifactoryReleaseRepoUrl
+
+            credentials {
+                username = 'yingp'
+                password = '111111'
+            }
+        }
+    }
+}

+ 61 - 0
gradle/service-base.gradle

@@ -0,0 +1,61 @@
+buildscript {
+    ext {
+        springBootVersion = '1.4.4.RELEASE'
+    }
+    repositories {
+        maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
+        mavenCentral()
+        jcenter()
+    }
+    dependencies {
+        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
+    }
+}
+
+apply plugin: 'idea'
+apply plugin: 'eclipse'
+apply plugin: 'java'
+//apply plugin: 'spring-boot'
+apply plugin: org.springframework.boot.gradle.plugin.SpringBootPlugin // applying a plugin by plugin id is not supported in script plugins. You must use the plugin's fully qualified class name.
+sourceCompatibility = 1.8 // 必须在apply java插件之后
+targetCompatibility = 1.8
+
+bootRun {
+    addResources = true
+}
+idea {
+    module {
+        downloadSources = true
+        downloadJavadoc = false
+        inheritOutputDirs = false
+        outputDir = file("$buildDir/classes/main/")
+    }
+}
+
+repositories {
+    mavenLocal()
+    maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
+    maven {
+        url 'http://10.10.101.21:8081/artifactory/libs-release'
+    }
+    maven {
+        url 'http://10.10.101.21:8081/artifactory/libs-snapshot'
+    }
+    maven {
+        url 'http://10.10.101.21:8081/artifactory/plugins-snapshot'
+    }
+    mavenCentral()
+}
+
+dependencyManagement {
+    imports {
+        mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Camden.SR5'
+    }
+}
+dependencies {
+    testCompile 'org.springframework.boot:spring-boot-starter-test'
+    compile 'org.springframework.cloud:spring-cloud-starter-config'
+    compile("org.springframework.boot:spring-boot-devtools")
+    compile "org.springframework.cloud:spring-cloud-starter-eureka"
+
+}

+ 2 - 0
settings.gradle

@@ -0,0 +1,2 @@
+rootProject.name = 'base-edge-service'
+

+ 11 - 0
src/main/docker/Dockerfile

@@ -0,0 +1,11 @@
+FROM frolvlad/alpine-oraclejdk8:slim
+VOLUME /tmp # reate a temporary file on my host under "/var/lib/docker" and link it to the container under "/tmp".
+ADD base-edge-service-0.1.0.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="\
+-server \
+-Xmx4g \
+-Xms1g \
+-Duser.timezone=GMT+08 \
+-Dfile.encoding=utf-8"
+ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar --spring.profiles.active=test"] # To reduce Tomcat startup time we added a system property pointing to "/dev/urandom" as a source of entropy.

+ 23 - 0
src/main/java/com/elasticjee/EdgeServiceApplication.java

@@ -0,0 +1,23 @@
+package com.elasticjee;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.netflix.hystrix.EnableHystrix;
+import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
+
+/**
+ * 网关服务
+ *
+ * @author chaokunyang
+ */
+@SpringBootApplication
+@EnableDiscoveryClient
+@EnableZuulProxy
+//@EnableResourceServer
+@EnableHystrix
+public class EdgeServiceApplication {
+    public static void main(String[] args) {
+        SpringApplication.run(EdgeServiceApplication.class, args);
+    }
+}

+ 24 - 0
src/main/resources/application.yml

@@ -0,0 +1,24 @@
+zuul:
+  ignored-services: '*'
+  ignoredPatterns: /**/api/**
+  routes:
+    account-service: /account/**
+    payment-service: /payment/**
+    inventory-service: /inventory/**
+    order-service: /order/**
+    user-service: /user/**
+    catalog-service: /catalog/**
+    shopping-cart-service: /shoppingcart/**
+security:
+  oauth2:
+    resource:
+      userInfoUri: http://localhost:20140/auth/user
+  ignored: /catalog/**
+eureka:
+  instance:
+    prefer-ip-address: true
+  client:
+    registerWithEureka: true
+    fetchRegistry: true
+    serviceUrl:
+      defaultZone: http://localhost:8761/eureka/

+ 29 - 0
src/main/resources/bootstrap.yml

@@ -0,0 +1,29 @@
+spring:
+  application:
+    name: edge-service
+  profiles:
+    active: dev
+server:
+  port: 20130
+---
+spring:
+  cloud:
+    config:
+      profile: dev
+      label: master
+      # 这个地址可能会发生变动,要注意下
+      uri: http://10.10.100.24:28001/
+---
+spring:
+  cloud:
+    config:
+      profile: test
+      label: master
+      uri: http://configserver:28001/
+---
+spring:
+  cloud:
+    config:
+      profile: prod
+      label: master
+      uri: http://configserver:28001/