From 43ea897bd83647bba59d8a60e86a43a2455ad701 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 25 Jul 2019 14:34:47 +0800 Subject: [PATCH 01/12] add: frontend Dockerfile --- docker/frontend/Dockerfile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 docker/frontend/Dockerfile diff --git a/docker/frontend/Dockerfile b/docker/frontend/Dockerfile new file mode 100644 index 0000000..2f56613 --- /dev/null +++ b/docker/frontend/Dockerfile @@ -0,0 +1,19 @@ +# BUILDING +FROM node:lts-alpine AS builder + +LABEL maintainer="llitfkitfk@gmail.com" +WORKDIR /app + +RUN apk add --no-cache git +RUN git clone --depth 1 https://github.com/thx/rap2-dolores.git ./ + +RUN yarn install && yarn run lint && yarn run build + +# RUNNING +FROM node:lts-alpine +LABEL maintainer="llitfkitfk@gmail.com" +RUN npm install -g serve +WORKDIR /app +COPY --from=builder /app/build/* ./ + +CMD [ "serve", "-s", "/app", "-p", "80" ] \ No newline at end of file From 6ea733547c6bd28d6a173bca820d30dc0aa34452 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 25 Jul 2019 14:35:07 +0800 Subject: [PATCH 02/12] update: backend Dockerfile --- Dockerfile | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 23f7d3d..e560b35 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,23 @@ -FROM node:8.11.1-alpine +# BUILDING +FROM node:lts-alpine AS builder +LABEL maintainer="llitfkitfk@gmail.com" + +RUN npm install -g typescript + +WORKDIR /app +# cache dependencies +COPY package.json ./ +RUN npm install + +# build +COPY . ./ +RUN npm run build + +# RUNNING +FROM node:lts-alpine + +LABEL maintainer="llitfkitfk@gmail.com" WORKDIR /app -ADD . /tmp -RUN /bin/sh -c 'cd /tmp && npm install && npm install -g typescript && npm run build && mv ./dist/* /app/ && mv ./node_modules /app/ && rm -rf /tmp' \ No newline at end of file +COPY --from=builder /app/dist/* ./ +COPY --from=builder /app/node_modules ./node_modules \ No newline at end of file From cd0221d6627d6c486ee6f9ee2b782d0a97119509 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 25 Jul 2019 14:35:30 +0800 Subject: [PATCH 03/12] update: docker-compose add frontend container --- docker-compose.yml | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c485e74..474fb91 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,55 +1,57 @@ # mail@dongguochao.com +# llitfkitfk@gmail.com -version: '2.2' +version: "3" services: + # frontend + dolores: + build: + # will use image from the frontend repo in the future + context: docker/frontend + command: serve -s /app -p 80 + ports: + - 38081:80 + # backend delos: - container_name: rap2-delos # build from ./Dockerfile -# build: . + build: . # build from images # you can find last tag from https://hub.docker.com/r/blackdog1987/rap2-delos - image: blackdog1987/rap2-delos:2.6.aa3be03 + # image: blackdog1987/rap2-delos:2.6.aa3be03 environment: # if you have your own mysql, config it here, and disable the 'mysql' config blow - - MYSQL_URL=rap2-mysql # links will maintain /etc/hosts, just use 'container_name' + - MYSQL_URL=mysql # links will maintain /etc/hosts, just use 'container_name' - MYSQL_PORT=3306 - MYSQL_USERNAME=root - MYSQL_PASSWD= - MYSQL_SCHEMA=rap2 # redis config - - REDIS_URL=rap2-redis + - REDIS_URL=redis - REDIS_PORT=6379 # production / development - NODE_ENV=production - working_dir: /app - privileged: true ###### 'sleep 30 && node scripts/init' will drop the tables ###### RUN ONLY ONCE THEN REMOVE 'sleep 30 && node scripts/init' - command: /bin/sh -c 'sleep 30; node scripts/init; node dispatch.js' + command: /bin/sh -c 'node dispatch.js' # init the databases -# command: sleep 30 && node scripts/init && node dispatch.js + # command: sleep 30 && node scripts/init && node dispatch.js # without init -# command: node dispatch.js - links: - - redis - - mysql + # command: node dispatch.js depends_on: - redis - mysql ports: - - "38080:8080" # expose 38080 + - "38080:8080" # expose 38080 redis: - container_name: rap2-redis - image: redis:4.0.9 + image: redis:4 # disable this if you have your own mysql mysql: - container_name: rap2-mysql - image: mysql:5.7.22 + image: mysql:5.7 # expose 33306 to client (navicat) #ports: # - 33306:3306 From 9db1c9cc6ff3066d70fc9cb36f1c041af5818b77 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 25 Jul 2019 16:00:45 +0800 Subject: [PATCH 04/12] update: using nginx as frontend & backend proxy --- docker/frontend/Dockerfile | 16 +++++++--------- docker/frontend/config/config.prod.ts | 9 +++++++++ docker/nginx/conf.d/delos.conf | 17 +++++++++++++++++ docker/nginx/conf.d/dolores.conf | 12 ++++++++++++ 4 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 docker/frontend/config/config.prod.ts create mode 100644 docker/nginx/conf.d/delos.conf create mode 100644 docker/nginx/conf.d/dolores.conf diff --git a/docker/frontend/Dockerfile b/docker/frontend/Dockerfile index 2f56613..9d8d937 100644 --- a/docker/frontend/Dockerfile +++ b/docker/frontend/Dockerfile @@ -6,14 +6,12 @@ WORKDIR /app RUN apk add --no-cache git RUN git clone --depth 1 https://github.com/thx/rap2-dolores.git ./ +RUN yarn install +COPY config/config.prod.ts ./src/config/config.prod.ts +RUN yarn run lint +RUN yarn run build -RUN yarn install && yarn run lint && yarn run build +# nginx +FROM nginx:stable-alpine -# RUNNING -FROM node:lts-alpine -LABEL maintainer="llitfkitfk@gmail.com" -RUN npm install -g serve -WORKDIR /app -COPY --from=builder /app/build/* ./ - -CMD [ "serve", "-s", "/app", "-p", "80" ] \ No newline at end of file +COPY --from=builder /app/build /app \ No newline at end of file diff --git a/docker/frontend/config/config.prod.ts b/docker/frontend/config/config.prod.ts new file mode 100644 index 0000000..1894d51 --- /dev/null +++ b/docker/frontend/config/config.prod.ts @@ -0,0 +1,9 @@ +const config: IConfig = { + serve: 'http://localhost:38080', + keys: ['some secret hurr'], + session: { + key: 'koa:sess', + }, +} + +export default config diff --git a/docker/nginx/conf.d/delos.conf b/docker/nginx/conf.d/delos.conf new file mode 100644 index 0000000..a767a76 --- /dev/null +++ b/docker/nginx/conf.d/delos.conf @@ -0,0 +1,17 @@ +server { + listen 38080; + server_name localhost; + + #charset koi8-r; + #access_log /var/log/nginx/host.access.log main; + + location / { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_set_header X-Nginx-Proxy true; + proxy_set_header Connection ""; + proxy_pass http://delos:8080/; + } +} + diff --git a/docker/nginx/conf.d/dolores.conf b/docker/nginx/conf.d/dolores.conf new file mode 100644 index 0000000..738a581 --- /dev/null +++ b/docker/nginx/conf.d/dolores.conf @@ -0,0 +1,12 @@ +server { + listen 38081; + server_name localhost; + + root /app; + #charset koi8-r; + #access_log /var/log/nginx/host.access.log main; + + location / { + try_files $uri /index.html; + } +} From 74c74df761c0e9f1a924d71d70531fd29cba36a6 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 25 Jul 2019 16:03:00 +0800 Subject: [PATCH 05/12] update: compose add nginx as proxy --- Dockerfile | 8 ++++---- docker-compose.yml | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index e560b35..33c4f5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,21 +3,21 @@ FROM node:lts-alpine AS builder LABEL maintainer="llitfkitfk@gmail.com" -RUN npm install -g typescript +RUN yarn global add typescript WORKDIR /app # cache dependencies COPY package.json ./ -RUN npm install +RUN yarn install # build COPY . ./ -RUN npm run build +RUN yarn run build # RUNNING FROM node:lts-alpine LABEL maintainer="llitfkitfk@gmail.com" WORKDIR /app -COPY --from=builder /app/dist/* ./ +COPY --from=builder /app/dist . COPY --from=builder /app/node_modules ./node_modules \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 474fb91..b9ac341 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,13 +5,17 @@ version: "3" services: # frontend - dolores: + nginx: + # image: nginx:stable-alpine build: # will use image from the frontend repo in the future context: docker/frontend - command: serve -s /app -p 80 + volumes: + - ./docker/nginx/conf.d:/etc/nginx/conf.d ports: - - 38081:80 + - 38080:38080 + - 38081:38081 + # backend delos: # build from ./Dockerfile @@ -43,8 +47,6 @@ services: depends_on: - redis - mysql - ports: - - "38080:8080" # expose 38080 redis: image: redis:4 From b7d33a60c6ab268c0e426ff2faf42c680f195763 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 25 Jul 2019 16:21:52 +0800 Subject: [PATCH 06/12] update: new docker deployment flow --- README.md | 114 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 60 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index ce41938..e024539 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,61 @@ -# RAP2-DELOS 开源社区版本 (后端API服务器) +# RAP2-DELOS 开源社区版本 (后端 API 服务器) [![Build Status](https://travis-ci.org/thx/rap2-delos.svg?branch=master)](https://travis-ci.org/thx/rap2-delos) -RAP2是在RAP1基础上重做的新项目,它包含两个组件(对应两个Github Repository)。 +RAP2 是在 RAP1 基础上重做的新项目,它包含两个组件(对应两个 Github Repository)。 -* rap2-delos: 后端数据API服务器,基于Koa + MySQL[link](http://github.com/thx/rap2-delos) -* rap2-dolores: 前端静态资源,基于React [link](http://github.com/thx/rap2-dolores) +- rap2-delos: 后端数据 API 服务器,基于 Koa + MySQL[link](http://github.com/thx/rap2-delos) +- rap2-dolores: 前端静态资源,基于 React [link](http://github.com/thx/rap2-dolores) ### Resources -* [Official Site 官网: rap2.taobao.org](http://rap2.taobao.org) -* 钉钉群ID: 11789704 -* [热心网友提供的部署文档,供参考](https://github.com/thx/rap2-delos/issues/119) +- [Official Site 官网: rap2.taobao.org](http://rap2.taobao.org) +- 钉钉群 ID: 11789704 +- [热心网友提供的部署文档,供参考](https://github.com/thx/rap2-delos/issues/119) + +## 快速部署(Docker) + +```sh +# 1. 安装docker +# 2. 修改docker-compose.xml中的配置。默认使用mysql和redis的镜像。可修改为自己的配置 +# 3. 下载源码并执行。 +docker-compose up -d + +# ⚠️注意: 第一次运行需要手动初始化mysql数据库。分别执行以下命令: +docker-compose exec delos node scripts/init + +# 部署成功后 访问 +http://localhost:38081 # 前端 +http://localhost:38080 # 后端 + +# 如果仍然有问题,重新启动 +docker-compose down +# 重新运行 +docker-compose up -d +``` ## 部署 ### 环境要求 -* Node.js 8.9.4+ -* MySQL 5.7+ -* Redis 4.0+ + +- Node.js 8.9.4+ +- MySQL 5.7+ +- Redis 4.0+ ### 开发模式 -#### 安装MySQL和Redis服务器 +#### 安装 MySQL 和 Redis 服务器 -请自行查找搭建方法,mysql/redis配置在config.*.ts文件中,在不修改任何配置的情况下, -redis会通过默认端口 + 本机即可正常访问,确保redis-server打开即可。 +请自行查找搭建方法,mysql/redis 配置在 config.\*.ts 文件中,在不修改任何配置的情况下, +redis 会通过默认端口 + 本机即可正常访问,确保 redis-server 打开即可。 -#### 启动redis-server +#### 启动 redis-server ```sh redis-server ``` -后台执行可以使用nohup或pm2,这里推荐使用pm2,下面命令会安装pm2,并通过pm2来启动redis缓存服务 +后台执行可以使用 nohup 或 pm2,这里推荐使用 pm2,下面命令会安装 pm2,并通过 pm2 来启动 redis 缓存服务 ```bash npm install -g pm2 @@ -52,9 +74,9 @@ mysql -e 'CREATE DATABASE IF NOT EXISTS RAP2_DELOS_APP DEFAULT CHARSET utf8 COLL npm install ``` -confirm configurations in /config/config.dev.js (used in development mode),确认/config/config.dev.js中的配置(.dev.js后缀表示用于开发模式)。 +confirm configurations in /config/config.dev.js (used in development mode),确认/config/config.dev.js 中的配置(.dev.js 后缀表示用于开发模式)。 -#### 安装 && TypeScript编译 +#### 安装 && TypeScript 编译 ```bash npm install -g typescript @@ -67,12 +89,14 @@ npm run build npm run create-db ``` -#### 执行mocha测试用例和js代码规范检查 +#### 执行 mocha 测试用例和 js 代码规范检查 + ```bash npm run check ``` #### 启动开发模式的服务器 监视并在发生代码变更时自动重启 + ```bash npm run dev ``` @@ -86,43 +110,25 @@ npm start ``` -## Dockerfile (本地源码通过docker运行) -```sh -# 1. 安装docker -# 2. 修改docker-compose.xml中的配置。默认使用mysql和redis的镜像。可修改为自己的配置 -# 3. 通过源码运行。 - docker-compose up -d -# 4. 第一次运行需要手动初始化mysql数据库。分别执行以下命令: - docker exec -it rap2-delos sh - // 登录成功以后执行: - node scripts/init - // 执行完毕后退出 - exit - // 如果仍然有问题,重新启动 - docker-compose down - // 重新运行 - docker-compose up -d -``` - - ## Author -* 版权: 阿里妈妈前端团队 -* 作者: - * RAP2 2017/10前版本作者为[墨智(@Nuysoft)](https://github.com/nuysoft/), [mockjs](mockjs.com)的作者。 - * 2017/10之后版本开发者 - * [霍雍(Bosn)](http://github.com/bosn/),[RAP1](http://github.com/thx/RAP)作者,RAP最早的创始人。 - * [承虎(alvarto)](http://github.com/alvarto/) + +- 版权: 阿里妈妈前端团队 +- 作者: + - RAP2 2017/10 前版本作者为[墨智(@Nuysoft)](https://github.com/nuysoft/), [mockjs](mockjs.com)的作者。 + - 2017/10 之后版本开发者 + - [霍雍(Bosn)](http://github.com/bosn/),[RAP1](http://github.com/thx/RAP)作者,RAP 最早的创始人。 + - [承虎(alvarto)](http://github.com/alvarto/) ### Tech Arch -* 前端架构(rap2-dolores) - * React / Redux / Saga / Router - * Mock.js - * SASS / Bootstrap 4 beta - * server: nginx -* 后端架构(rap2-delos) - * Koa - * Sequelize - * MySQL - * Server - * server: node +- 前端架构(rap2-dolores) + - React / Redux / Saga / Router + - Mock.js + - SASS / Bootstrap 4 beta + - server: nginx +- 后端架构(rap2-delos) + - Koa + - Sequelize + - MySQL + - Server + - server: node From 7d9959710935d09483f4f3b2912f0266d0186314 Mon Sep 17 00:00:00 2001 From: bigfengyu Date: Thu, 31 Oct 2019 19:20:54 +0800 Subject: [PATCH 07/12] =?UTF-8?q?feat:=20docker=20=E9=83=A8=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 19 +++++++++++++++++++ Dockerfile | 15 ++++++++++++--- docker-compose.yml | 17 +++++++---------- docker/frontend/Dockerfile | 17 ----------------- docker/frontend/config/config.prod.ts | 9 --------- docker/nginx/conf.d/delos.conf | 17 ----------------- docker/nginx/conf.d/dolores.conf | 12 ------------ package.json | 3 ++- src/config/config.dev.ts | 2 +- src/config/config.local.ts | 2 +- src/config/config.prod.ts | 2 +- 11 files changed, 43 insertions(+), 72 deletions(-) create mode 100644 .dockerignore delete mode 100644 docker/frontend/Dockerfile delete mode 100644 docker/frontend/config/config.prod.ts delete mode 100644 docker/nginx/conf.d/delos.conf delete mode 100644 docker/nginx/conf.d/dolores.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..95adf9c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,19 @@ +# See https://help.github.com/ignore-files/ for more about ignoring files. + +# dependencies +/node_modules + +# testing +/coverage + +# misc +.DS_Store +.env +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# css +src/**/*.css +build +build.zip diff --git a/Dockerfile b/Dockerfile index 33c4f5a..e81267d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,15 @@ # BUILDING FROM node:lts-alpine AS builder -LABEL maintainer="llitfkitfk@gmail.com" +# base on work of llitfkitfk@gmail.com +LABEL maintainer="chibing.fy@alibaba-inc.com" RUN yarn global add typescript WORKDIR /app # cache dependencies COPY package.json ./ -RUN yarn install +RUN yarn config set registry https://registry.npm.taobao.org/ && yarn install # build COPY . ./ @@ -17,7 +18,15 @@ RUN yarn run build # RUNNING FROM node:lts-alpine -LABEL maintainer="llitfkitfk@gmail.com" +# base on work of llitfkitfk@gmail.com +LABEL maintainer="chibing.fy@alibaba-inc.com" +# use China mirror of: https://github.com/jgm/pandoc/releases/download/2.7.3/pandoc-2.7.3-linux.tar.gz +RUN wget http://q08gwzg9o.bkt.clouddn.com/pandoc-2.7.3-linux.tar.gz && \ + tar -xf pandoc-2.7.3-linux.tar.gz && \ + cp pandoc-2.7.3/bin/* /usr/bin/ && \ + pandoc -v && \ + rm -rf pandoc-2.7.3-linux.tar.gz pandoc-2.7.3 + WORKDIR /app COPY --from=builder /app/dist . COPY --from=builder /app/node_modules ./node_modules \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index b9ac341..d8a60f9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,29 +1,26 @@ # mail@dongguochao.com # llitfkitfk@gmail.com +# chibing.fy@alibaba-inc.com version: "3" services: # frontend - nginx: + dolores: # image: nginx:stable-alpine - build: - # will use image from the frontend repo in the future - context: docker/frontend - volumes: - - ./docker/nginx/conf.d:/etc/nginx/conf.d + image: rapcore/rap2-dolores:latest ports: - - 38080:38080 - 38081:38081 # backend delos: # build from ./Dockerfile - build: . + image: rapcore/rap2-delos:latest + ports: + - 38080:38080 # build from images - # you can find last tag from https://hub.docker.com/r/blackdog1987/rap2-delos - # image: blackdog1987/rap2-delos:2.6.aa3be03 environment: + - SERVE_PORT=38080 # if you have your own mysql, config it here, and disable the 'mysql' config blow - MYSQL_URL=mysql # links will maintain /etc/hosts, just use 'container_name' - MYSQL_PORT=3306 diff --git a/docker/frontend/Dockerfile b/docker/frontend/Dockerfile deleted file mode 100644 index 9d8d937..0000000 --- a/docker/frontend/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -# BUILDING -FROM node:lts-alpine AS builder - -LABEL maintainer="llitfkitfk@gmail.com" -WORKDIR /app - -RUN apk add --no-cache git -RUN git clone --depth 1 https://github.com/thx/rap2-dolores.git ./ -RUN yarn install -COPY config/config.prod.ts ./src/config/config.prod.ts -RUN yarn run lint -RUN yarn run build - -# nginx -FROM nginx:stable-alpine - -COPY --from=builder /app/build /app \ No newline at end of file diff --git a/docker/frontend/config/config.prod.ts b/docker/frontend/config/config.prod.ts deleted file mode 100644 index 1894d51..0000000 --- a/docker/frontend/config/config.prod.ts +++ /dev/null @@ -1,9 +0,0 @@ -const config: IConfig = { - serve: 'http://localhost:38080', - keys: ['some secret hurr'], - session: { - key: 'koa:sess', - }, -} - -export default config diff --git a/docker/nginx/conf.d/delos.conf b/docker/nginx/conf.d/delos.conf deleted file mode 100644 index a767a76..0000000 --- a/docker/nginx/conf.d/delos.conf +++ /dev/null @@ -1,17 +0,0 @@ -server { - listen 38080; - server_name localhost; - - #charset koi8-r; - #access_log /var/log/nginx/host.access.log main; - - location / { - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $http_host; - proxy_set_header X-Nginx-Proxy true; - proxy_set_header Connection ""; - proxy_pass http://delos:8080/; - } -} - diff --git a/docker/nginx/conf.d/dolores.conf b/docker/nginx/conf.d/dolores.conf deleted file mode 100644 index 738a581..0000000 --- a/docker/nginx/conf.d/dolores.conf +++ /dev/null @@ -1,12 +0,0 @@ -server { - listen 38081; - server_name localhost; - - root /app; - #charset koi8-r; - #access_log /var/log/nginx/host.access.log main; - - location / { - try_files $uri /index.html; - } -} diff --git a/package.json b/package.json index e52a152..e60c1b4 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "start": "cross-env NODE_ENV=production pm2 start dist/dispatch.js --name=rap-server-delos", "lint": "echo \"TSLint checking...\" && tslint -c tslint.json 'src/**/*.ts' 'src/**/*.tsx'", "start:redis": "pm2 start redis-server --name redis-server", - "clean": "pm2 delete all" + "clean": "pm2 delete all", + "build:docker": "docker build --rm -f \"Dockerfile\" -t rapteam/rap2-delos:latest ." }, "author": "bosn, nuysoft", "license": "ISC", diff --git a/src/config/config.dev.ts b/src/config/config.dev.ts index facf669..8519047 100644 --- a/src/config/config.dev.ts +++ b/src/config/config.dev.ts @@ -3,7 +3,7 @@ import { IConfigOptions } from "../types" let config: IConfigOptions = { version: 'v2.7.0', serve: { - port: 8080, + port: (process.env.SERVE_PORT && parseInt(process.env.SERVE_PORT)) || 8080, path: '', }, keys: ['some secret hurr'], diff --git a/src/config/config.local.ts b/src/config/config.local.ts index 7af4172..00d5516 100644 --- a/src/config/config.local.ts +++ b/src/config/config.local.ts @@ -3,7 +3,7 @@ import { IConfigOptions } from "../types" let config: IConfigOptions = { version: '2.7.0', serve: { - port: 8080, + port: (process.env.SERVE_PORT && parseInt(process.env.SERVE_PORT)) || 8080, path: '', }, keys: ['some secret hurr'], diff --git a/src/config/config.prod.ts b/src/config/config.prod.ts index 36252a7..2459717 100644 --- a/src/config/config.prod.ts +++ b/src/config/config.prod.ts @@ -4,7 +4,7 @@ import { IConfigOptions } from "../types" let config: IConfigOptions = { version: '2.7.0', serve: { - port: (process.env.EXPOSE_PORT && parseInt(process.env.EXPOSE_PORT)) || 8080, + port: (process.env.SERVE_PORT && parseInt(process.env.SERVE_PORT)) || 8080, path: '', }, keys: ['some secret hurr'], From 8ac7b626aec8b8e16a6c68d691cf5518170119b7 Mon Sep 17 00:00:00 2001 From: bigfengyu Date: Thu, 31 Oct 2019 19:56:59 +0800 Subject: [PATCH 08/12] fix: dockerfile --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e81267d..a93f902 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,8 @@ RUN yarn global add typescript WORKDIR /app # cache dependencies COPY package.json ./ -RUN yarn config set registry https://registry.npm.taobao.org/ && yarn install +# 在国内打开下面一行加速 +#RUN yarn config set registry https://registry.npm.taobao.org/ && yarn install # build COPY . ./ From a25862cc90eeef9642c9c912434a9bcfc298f3bb Mon Sep 17 00:00:00 2001 From: bigfengyu Date: Thu, 31 Oct 2019 22:08:59 +0800 Subject: [PATCH 09/12] fix: Dockerfile --- Dockerfile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index a93f902..a5ae15e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,17 +4,21 @@ FROM node:lts-alpine AS builder # base on work of llitfkitfk@gmail.com LABEL maintainer="chibing.fy@alibaba-inc.com" -RUN yarn global add typescript - WORKDIR /app + # cache dependencies COPY package.json ./ + # 在国内打开下面一行加速 -#RUN yarn config set registry https://registry.npm.taobao.org/ && yarn install +#RUN npm config set registry https://registry.npm.taobao.org/ + +# instal dependencies +RUN npm install typescript -g && \ + npm install # build COPY . ./ -RUN yarn run build +RUN npm run build # RUNNING FROM node:lts-alpine From c1f22a2c5f5b88e10e22147acef0e9acedb1c60b Mon Sep 17 00:00:00 2001 From: bigfengyu Date: Thu, 31 Oct 2019 22:39:18 +0800 Subject: [PATCH 10/12] =?UTF-8?q?fix:=20=E7=BB=9F=E4=B8=80=20build-docker?= =?UTF-8?q?=20=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e60c1b4..bcf5b0a 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "lint": "echo \"TSLint checking...\" && tslint -c tslint.json 'src/**/*.ts' 'src/**/*.tsx'", "start:redis": "pm2 start redis-server --name redis-server", "clean": "pm2 delete all", - "build:docker": "docker build --rm -f \"Dockerfile\" -t rapteam/rap2-delos:latest ." + "build-docker": "docker build --rm -f \"Dockerfile\" -t rapteam/rap2-delos:latest ." }, "author": "bosn, nuysoft", "license": "ISC", From 057a44065c44eceaa2f31bf8ed2999dcfc374422 Mon Sep 17 00:00:00 2001 From: bigfengyu Date: Thu, 31 Oct 2019 22:44:37 +0800 Subject: [PATCH 11/12] fix: update docker-compose.yml --- docker-compose.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index d8a60f9..13102a6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,18 +7,15 @@ version: "3" services: # frontend dolores: - # image: nginx:stable-alpine - image: rapcore/rap2-dolores:latest + image: rapteam/rap2-dolores:latest ports: - 38081:38081 # backend delos: - # build from ./Dockerfile - image: rapcore/rap2-delos:latest + image: rapteam/rap2-delos:latest ports: - 38080:38080 - # build from images environment: - SERVE_PORT=38080 # if you have your own mysql, config it here, and disable the 'mysql' config blow From c2b178cfb308890412bd4ad4624da784555ab2da Mon Sep 17 00:00:00 2001 From: bigfengyu Date: Thu, 31 Oct 2019 23:41:34 +0800 Subject: [PATCH 12/12] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84=20readme?= =?UTF-8?q?=EF=BC=8C=E6=9B=B4=E6=94=B9=E9=BB=98=E8=AE=A4=E7=AB=AF=E5=8F=A3?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 60 +++++++++++++++++++++++++++++++++++----------- docker-compose.yml | 4 +++- 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 275addb..b52a7b0 100644 --- a/README.md +++ b/README.md @@ -2,41 +2,73 @@ [![Build Status](https://travis-ci.org/thx/rap2-delos.svg?branch=master)](https://travis-ci.org/thx/rap2-delos) -RAP2 是在 RAP1 基础上重做的新项目,它包含两个组件(对应两个 Github Repository)。 +RAP2 是在 RAP1 基础上重做的新项目,它能给你提供方便的接口文档管理、Mock、导出等功能,包含两个组件(对应两个 Github Repository)。 - rap2-delos: 后端数据 API 服务器,基于 Koa + MySQL[link](http://github.com/thx/rap2-delos) - rap2-dolores: 前端静态资源,基于 React [link](http://github.com/thx/rap2-dolores) + +**Rap 官方服务站点,无需安装直接体验: [rap2.taobao.org](http://rap2.taobao.org)** + +**有急事来官方钉钉群,响应更迅速: 11789704** + +***2019-10-31:现已支持 Docker 一键部署,欢迎大家体验&反馈*** + ***2019-09-27:更新的用户请注意按照下面指引安装 pandoc 以启用文档导出功能*** -### Resources -- [Official Site 官网: rap2.taobao.org](http://rap2.taobao.org) -- 钉钉群 ID: 11789704 -- [热心网友提供的部署文档,供参考](https://github.com/thx/rap2-delos/issues/119) +## 推荐使用 Docker 快速部署 + +### 安装 Docker + +国内用户可参考 [https://get.daocloud.io/](https://get.daocloud.io/) 安装 Docker 以及 Docker Compose (Linux 用户需要单独安装),建议按照链接指引配置 Docker Hub 的国内镜像提高加载速度。 + +### 配置项目 + +在任意地方建立目录 rap + +把本仓库中的 [docker-compose.yml](https://raw.githubusercontent.com/thx/rap2-delos/master/docker-compose.yml) 放到 rap 目录中 -## 快速部署(Docker) +Rap 前端服务的端口号默认为 3000,你可以在 docker-compose.yml 中按照注释自定义 + +在 rap 目录下执行下面的命令: ```sh -# 1. 安装docker -# 2. 修改docker-compose.xml中的配置。默认使用mysql和redis的镜像。可修改为自己的配置 -# 3. 下载源码并执行。 +# 拉取镜像并启动 docker-compose up -d -# ⚠️注意: 第一次运行需要手动初始化mysql数据库。分别执行以下命令: +# 启动后,第一次运行需要手动初始化mysql数据库 +# ⚠️注意: 只有第一次该这样做 docker-compose exec delos node scripts/init # 部署成功后 访问 -http://localhost:38081 # 前端 +http://localhost:3000 # 前端(可自定义端口号) http://localhost:38080 # 后端 -# 如果仍然有问题,重新启动 +# 如果访问不了可能是数据库没有链接上,关闭 rap 服务 docker-compose down -# 重新运行 +# 再重新运行 docker-compose up -d ``` -## 部署 +**⚠️注意:第一次运行后 rap 目录下会被自动创建一个 docker 目录,里面存有 rap 的数据库数据,可千万不要删除。** + +#### 镜像升级 + +Rap 经常会进行 bugfix 和功能升级,用 Docker 可以很方便地跟随主项目升级 + +```sh +# 拉取一下最新的镜像 +docker-compose pull +# 暂停当前应用 +docker-compose down +# 重新构建并启动 +docker-compose up -d --build +# 清空不被使用的虚悬镜像 +docker image prune -f +``` + +## 手动部署 ### 环境要求 diff --git a/docker-compose.yml b/docker-compose.yml index 13102a6..69f94cb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,12 +9,14 @@ services: dolores: image: rapteam/rap2-dolores:latest ports: - - 38081:38081 + #冒号前可以自定义前端端口号,冒号后不要动 + - 3000:38081 # backend delos: image: rapteam/rap2-delos:latest ports: + # 这里的配置不要改哦 - 38080:38080 environment: - SERVE_PORT=38080