From d9e362993a5c751731af251c00fde47b862999f9 Mon Sep 17 00:00:00 2001
From: bigfengyu <kuailewudi@yeah.net>
Date: Thu, 31 Oct 2019 19:29:38 +0800
Subject: [PATCH] =?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            | 22 ++++++++++++++++++++++
 docker/config.prod.ts |  9 +++++++++
 docker/nginx.conf     | 10 ++++++++++
 package.json          |  5 +++--
 5 files changed, 63 insertions(+), 2 deletions(-)
 create mode 100644 .dockerignore
 create mode 100644 Dockerfile
 create mode 100644 docker/config.prod.ts
 create mode 100644 docker/nginx.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
new file mode 100644
index 0000000..c26ef9c
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,22 @@
+# BUILDING 
+FROM node:lts-alpine AS builder
+WORKDIR /app
+COPY . ./
+COPY docker/config.prod.ts ./src/config/config.prod.ts
+RUN apk --no-cache --virtual build-dependencies add \
+    python \
+    make \
+    g++ && \
+    yarn config set registry https://registry.npm.taobao.org/ && \
+    yarn install && \
+    apk del build-dependencies && \
+    yarn global add typescript && \
+    yarn run lint && \
+    SERVE_URL=http://localhost:8080 yarn run build
+
+# nginx
+FROM nginx:stable-alpine
+
+COPY --from=builder app/build /dolores
+RUN rm /etc/nginx/conf.d/default.conf
+COPY docker/nginx.conf /etc/nginx/conf.d/
\ No newline at end of file
diff --git a/docker/config.prod.ts b/docker/config.prod.ts
new file mode 100644
index 0000000..1894d51
--- /dev/null
+++ b/docker/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 b/docker/nginx.conf
new file mode 100644
index 0000000..fadaa09
--- /dev/null
+++ b/docker/nginx.conf
@@ -0,0 +1,10 @@
+server {
+    listen       38081;
+    server_name  localhost;
+
+    root /dolores;
+
+    location / {
+        try_files $uri /index.html;
+    }
+}
diff --git a/package.json b/package.json
index 8868cd0..e7f019d 100644
--- a/package.json
+++ b/package.json
@@ -13,7 +13,8 @@
     "test-backup": "npm run lint && react-scripts test --env=jsdom",
     "test": "npm run lint",
     "eject": "react-scripts eject",
-    "lint": "tslint --project ./ -c tslint.json"
+    "lint": "tslint --project ./ -c tslint.json",
+    "build:docker": "docker build --rm -f \"Dockerfile\" -t rapteam/rap2-dolores:latest ."
   },
   "repository": {
     "type": "git",
@@ -104,7 +105,7 @@
     "@types/sortablejs": "^1.7.2",
     "@types/urijs": "^1.19.3",
     "@types/yup": "^0.26.21",
-    "node-sass": "4.12.0",
+    "node-sass": "4.13.0",
     "npm-run-all": "4.1.5",
     "pre-commit": "^1.2.2",
     "react-scripts": "^3.0.1",