diff --git a/README.md b/README.md index 3fd4891..09525f8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # spring-cloud-base 微服务基础框架,基于 SpringCloud 及 SpringBoot 开发。 使用 Oauth2 统一授权、认证, Oauth示例客户端使用 Vue 开发,具有用户管理、 资源管理、 角色管理等模块,后端包括授权中心、 基础数据中心(资源服务器)等应用,可作为微服务快速开发脚手架。 可通过 docker 快速构建部署。 -Demo website:http://www.ityouknow.com/ username: xxx password: 123456 +Demo website:http://112.74.60.248:8080/ username: test password: 123456 ## Model @@ -20,6 +20,127 @@ Demo website:http://www.ityouknow.com/ username: xxx password: 123456 ## Quick Start -1. 开发环境搭建 -2. 通过 docker-compose 快速启动 -3. 通过共享镜像启动 +### 项目结构 +``` +├─spring-cloud-base +│ │ +│ ├─api-gateway--------------网关负载中心 +│ │ +│ ├─auth-center-----------------服务授权中心 +│ │ ├─auth-center-api----------------授权中心公共模块 +│ │ ├─auth-center-provider----------------授权中心服务端 +│ │ ├─auth-spring-boot-autoconfigure----------------授权中心autoconfigure +│ │ └─auth-spring-boot-starter----------------授权中心starter模块 +│ │ +│ ├─common----------------通用脚手架 +│ │ +│ ├─config-git-----------------配置中心 +│ │ +│ ├─db-mybatis-pagehelper---------------Mybatis通用Mapper、分页模块 +│ │ ├─db-spring-boot-autoconfigure----------------autoconfigure +│ │ ├─db-spring-boot-samples----------------db模块使用示例 +│ │ └─db-spring-boot-starter----------------db starter +│ │ +│ ├─docker-compose---------------docker-compose编排 +│ │ +│ ├─main-data--------------基础数据模块 +│ │ ├─main-data-api----------------基础数据公共模块 +│ │ ├─main-data-client----------------基础数据模块客户端 +│ │ ├─main-data-provider----------------基础数据模块服务端 +│ │ +│ └─web-app--------------vue前端应用 +│ +``` + +### 依赖环境 +JDK8、 Maven、 Mysql、 Redis、Consul(暂不支持0.7.3以上)、 Nodejs、 Docker(可选)、 docker-compose(可选) +### 运行步骤 +1. Mysql导入数据: 运行main-data/schema.sql 文件 +2. 更改 application配置文件(服务授权中心、网关负载中心、基础数据模块),jdbcUrl、 consul、 redis、 key-uri(服务授权中心公钥,资源服务器需配置) +3. 依此启动 mysql、 redis、 consul、 auth-center/auth-center-provider/AuthCenterProviderApplication.main(服务授权中心)、 api-gateway/ApiGatewayApplication.main()(网关负载中心)、 main-data/main-data-provider/MainDataApplication.main()(基础数据模块)、 web-app(前端vue项目) + +### 通过 docker-compose 快速启动 +1. 需要 docker-compose 环境,windows 可安装 DockerToolbox。 +需先通过 Maven 插件 docker-maven-plugin 打包镜像, +``` + + + + org.springframework.boot + spring-boot-maven-plugin + + + com.spotify + docker-maven-plugin + ${docker.plugin.version} + + ${project.artifactId} + src/main/docker + + + / + ${project.build.directory} + ${project.build.finalName}.jar + + + + + + +``` + +2. 分别构建 auth-center-provider、 main-data-provider、 api-gateway: +``` +mvn clean +mvn package docker:build +``` +构建 node-app: +``` +cd /spring-cloud-base/web-app +docker build -t node-app . +``` + +3. 更改配置 docker-compose.yml: +``` + node-app: + image: node-app + ports: + - '8080:8080' + depends_on: + - 'auth-center' + - 'api-gateway' + # 基础路径,授权时的redirectUrl,为 宿主机IP:本容器映射端口 + - BASE_URL=http://192.168.99.100:8080 + # 后台接口,对于网关 + - SERVER_URL=http://192.168.99.100:18000 + # 授权中心 + - AUTH_URL=http://192.168.99.100:18001/auth +``` + +4. 运行 +``` +cd /spring-cloud-base/docker-compose +docker-compose up [-d] +``` + +### 通过共享镜像启动 + +## Preview +* 登陆页: +![avatar](https://github.com/fp2952/spring-cloud-base/tree/master/doc/login.png) + +* 用户管理: +![avatar](https://github.com/fp2952/spring-cloud-base/tree/master/doc/user.png) + +* 角色管理: +![avatar](https://github.com/fp2952/spring-cloud-base/tree/master/doc/role.png) + +* 应用管理: +![avatar](https://github.com/fp2952/spring-cloud-base/tree/master/doc/client.png) + +* 系统管理: +![avatar](https://github.com/fp2952/spring-cloud-base/tree/master/doc/system.png) + +* 模块管理: +![avatar](https://github.com/fp2952/spring-cloud-base/tree/master/doc/module.png) + diff --git a/api-gateway/pom.xml b/api-gateway/pom.xml index 11e623f..bbd2f7b 100644 --- a/api-gateway/pom.xml +++ b/api-gateway/pom.xml @@ -48,17 +48,20 @@ - + - + \ No newline at end of file diff --git a/api-gateway/src/main/docker/Dockerfile b/api-gateway/src/main/docker/Dockerfile index 149f160..fd4323e 100644 --- a/api-gateway/src/main/docker/Dockerfile +++ b/api-gateway/src/main/docker/Dockerfile @@ -1,12 +1,8 @@ -FROM frolvlad/alpine-oraclejdk8:slim +FROM livingobjects/jre8 VOLUME /tmp ADD api-gateway-1.0-SNAPSHOT.jar app.jar ADD wait-for-it.sh /wait-for-it.sh -#RUN bash -c 'touch /app.jar' +RUN bash -c 'touch /app.jar' RUN chmod +x /wait-for-it.sh -# install bash -RUN apk update -RUN apk upgrade -RUN apk add --no-cache bash ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] EXPOSE 18000 \ No newline at end of file diff --git a/auth-center/auth-center-provider/pom.xml b/auth-center/auth-center-provider/pom.xml index cb8c2ce..b418f33 100644 --- a/auth-center/auth-center-provider/pom.xml +++ b/auth-center/auth-center-provider/pom.xml @@ -100,18 +100,21 @@ - + - + \ No newline at end of file diff --git a/auth-center/auth-center-provider/src/main/docker/Dockerfile b/auth-center/auth-center-provider/src/main/docker/Dockerfile index 6fd9879..265f039 100644 --- a/auth-center/auth-center-provider/src/main/docker/Dockerfile +++ b/auth-center/auth-center-provider/src/main/docker/Dockerfile @@ -1,12 +1,8 @@ -FROM frolvlad/alpine-oraclejdk8:slim +FROM livingobjects/jre8 VOLUME /tmp ADD auth-center-provider-1.0-SNAPSHOT.jar app.jar ADD wait-for-it.sh /wait-for-it.sh -#RUN bash -c 'touch /app.jar' +RUN bash -c 'touch /app.jar' RUN chmod +x /wait-for-it.sh -# install bash -RUN apk update -RUN apk upgrade -RUN apk add --no-cache bash ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] EXPOSE 18001 \ No newline at end of file diff --git a/doc/client.png b/doc/client.png new file mode 100644 index 0000000..953cdb6 Binary files /dev/null and b/doc/client.png differ diff --git a/doc/login.png b/doc/login.png new file mode 100644 index 0000000..e0d43b5 Binary files /dev/null and b/doc/login.png differ diff --git a/doc/module.png b/doc/module.png new file mode 100644 index 0000000..6d05835 Binary files /dev/null and b/doc/module.png differ diff --git a/doc/role.png b/doc/role.png new file mode 100644 index 0000000..57da56a Binary files /dev/null and b/doc/role.png differ diff --git a/doc/system.png b/doc/system.png new file mode 100644 index 0000000..9a28201 Binary files /dev/null and b/doc/system.png differ diff --git a/doc/user.png b/doc/user.png new file mode 100644 index 0000000..fc1665f Binary files /dev/null and b/doc/user.png differ diff --git a/main-data/main-data-provider/pom.xml b/main-data/main-data-provider/pom.xml index 0bb3b6a..f2f133c 100644 --- a/main-data/main-data-provider/pom.xml +++ b/main-data/main-data-provider/pom.xml @@ -79,17 +79,20 @@ - + - + \ No newline at end of file diff --git a/web-app/src/config/config.js b/web-app/src/config/config.js index f67af5b..1b83da4 100644 --- a/web-app/src/config/config.js +++ b/web-app/src/config/config.js @@ -13,9 +13,13 @@ export default { // 设置后台请求地址前缀 Vue.axios.defaults.baseURL = process.env.SERVER_URL Vue.prototype.$auth.config.baseUrl = process.env.BASE_URL - // Vue.prototype.$auth.config.authUrl = window.serverconf[process.env.NODE_ENV]['authUrl'] Vue.prototype.$auth.config.authUrl = process.env.AUTH_URL + // build后配置 + // Vue.axios.defaults.baseURL = window.serverconf[process.env.NODE_ENV]['baseURL'] + // Vue.prototype.$auth.config.baseUrl = window.serverconf[process.env.NODE_ENV]['baseUrl'] + // Vue.prototype.$auth.config.authUrl = window.serverconf[process.env.NODE_ENV]['authUrl'] + // 配置认证头 Vue.axios.defaults.headers.common['Authorization'] = 'Bearer ' + Vue.prototype.$auth.token() // http 拦截器 diff --git a/web-app/static/config.js b/web-app/static/config.js index 2f3ffff..b653f19 100644 --- a/web-app/static/config.js +++ b/web-app/static/config.js @@ -10,13 +10,13 @@ window.serverconf = { appId: 'test', appSecret: 'test', production: { - baseUrl: 'http://192.168.99.100:8080', - authUrl: 'http://192.168.99.100:21001/auth', - baseURL: 'http://192.168.99.100:21000' + baseUrl: 'http://112.74.60.248:8080/demo', + authUrl: 'http://112.74.60.248:18001/auth', + baseURL: 'http://112.74.60.248:18000' }, development: { baseUrl: 'http://127.0.0.1:8080', - authUrl: 'http://192.168.99.100:21001/auth', - baseURL: 'http://192.168.99.100:21000' + authUrl: 'http://192.168.99.100:18001/auth', + baseURL: 'http://192.168.99.100:18000' } }