From 072b9c2dfcc2fafac108c76d0040ebb2feb6f3d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Sun, 7 Oct 2018 17:51:27 +0800 Subject: [PATCH] add docker support (#2459) * add docker support * remove test:all to package.json * add gzip config --- .dockerignore | 38 +++++++++++++++++++++++++ Dockerfile | 17 +++++++++++ docker/Dockerfile.dev => Dockerfile.dev | 1 + README.md | 19 +++++++++++++ README.zh-CN.md | 18 ++++++++++++ docker/Dockerfile | 13 --------- docker/docker-compose.dev.yml | 10 ++++--- docker/docker-compose.yml | 4 ++- docker/nginx.conf | 13 +++++++++ package.json | 9 ++++-- 10 files changed, 121 insertions(+), 21 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile rename docker/Dockerfile.dev => Dockerfile.dev (99%) delete mode 100644 docker/Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..28592158 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,38 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +**/node_modules +# roadhog-api-doc ignore +/src/utils/request-temp.js +_roadhog-api-doc + +# production +/dist +/.vscode + +# misc +.DS_Store +npm-debug.log* +yarn-error.log + +/coverage +.idea +yarn.lock +package-lock.json +*bak +.vscode + +# visual studio code +.history +*.log + +functions/mock +.temp/** + +# umi +.umi +.umi-production + +# screenshot +screenshot +.firebase \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..384b5e56 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM node:latest + +WORKDIR /usr/src/app/ + +COPY package.json ./ +RUN npm install --silent --no-cache + +COPY ./ ./ + +RUN apt-get update +RUN apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \ + libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \ + libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \ + libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \ + ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget + +CMD ["npm", "run", "build"] diff --git a/docker/Dockerfile.dev b/Dockerfile.dev similarity index 99% rename from docker/Dockerfile.dev rename to Dockerfile.dev index fdbb0e00..f5a50e58 100644 --- a/docker/Dockerfile.dev +++ b/Dockerfile.dev @@ -7,4 +7,5 @@ RUN npm install --silent --no-cache COPY ./ ./ + CMD ["npm", "run", "start"] diff --git a/README.md b/README.md index 72f60633..c7215752 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,8 @@ We need your help: https://github.com/ant-design/ant-design-pro/issues/120 ## Usage +### Use bash + ```bash $ git clone https://github.com/ant-design/ant-design-pro.git --depth=1 $ cd ant-design-pro @@ -86,6 +88,23 @@ $ npm install $ npm start # visit http://localhost:8000 ``` +### Use by docker + +```bash +// dev +$ npm run docker:dev + +// build +$ npm run docker:build + + +// production dev +$ npm run docker-prod:dev + +// production build +$ npm run docker-prod:build +``` + More instructions at [documentation](http://pro.ant.design/docs/getting-started). ## Browsers support diff --git a/README.zh-CN.md b/README.zh-CN.md index dc9a48b0..d4aae9f3 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -72,6 +72,7 @@ ## 使用 +### 使用命令行 ```bash $ git clone https://github.com/ant-design/ant-design-pro.git --depth=1 $ cd ant-design-pro @@ -79,6 +80,23 @@ $ npm install $ npm start # 访问 http://localhost:8000 ``` +### 使用 docker + +```bash +// dev +$ npm run docker:dev + +// build +$ npm run docker:build + + +// production dev +$ npm run docker-prod:dev + +// production build +$ npm run docker-prod:build +``` + 更多信息请参考 [使用文档](http://pro.ant.design/docs/getting-started)。 ## 支持环境 diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 54e1a4a7..00000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM node:latest - -WORKDIR /usr/src/app/ - -COPY package.json ./ -RUN npm install --silent --no-cache - -COPY ./ ./ - -RUN sh ./tests/fix_puppeteer.sh -RUN npm run test:all - -CMD ["npm", "run", "build"] diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml index d206d872..d7ab2138 100644 --- a/docker/docker-compose.dev.yml +++ b/docker/docker-compose.dev.yml @@ -2,11 +2,13 @@ version: "3.5" services: ant-design-pro_dev: + ports: + - 8000:8000 build: - context: ./ + context: ../ dockerfile: Dockerfile.dev container_name: "ant-design-pro_dev" volumes: - - ./src:/usr/src/app/src - - ./config:/usr/src/app/config - - ./mock:/usr/src/app/mock + - ../src:/usr/src/app/src + - ../config:/usr/src/app/config + - ../mock:/usr/src/app/mock diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index fa849a04..d0556006 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -2,13 +2,15 @@ version: "3.5" services: ant-design-pro_build: - build: ./ + build: ../ container_name: "ant-design-pro_build" volumes: - dist:/usr/src/app/dist ant-design-pro_web: image: nginx + ports: + - 80:80 container_name: "ant-design-pro_web" restart: unless-stopped volumes: diff --git a/docker/nginx.conf b/docker/nginx.conf index 38c7f17b..84d04c4e 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -1,9 +1,22 @@ server { listen 80; + # gzip config + gzip on; + gzip_min_length 1k; + gzip_comp_level 9 + gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; + gzip_vary on; + gzip_disable "MSIE [1-6]\."; root /usr/share/nginx/html; location / { try_files $uri $uri/ /index.html; } + location /api { + proxy_pass https://preview.pro.ant.design; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + } } diff --git a/package.json b/package.json index 70e5a507..4c37cdac 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "private": true, "scripts": { "precommit": "npm run lint-staged", - "presite": "npm run generate-mock && cd functions && npm install", + "presite": "node ./scripts/generateMock.js && cd functions && npm install", "start": "cross-env APP_TYPE=site umi dev", "start:no-mock": "cross-env MOCK=none umi dev", "build": "umi build", @@ -17,10 +17,13 @@ "lint-staged": "lint-staged", "lint-staged:js": "eslint --ext .js", "test": "umi test", - "generate-mock": "node ./scripts/generateMock.js", "test:component": "umi test ./src/components", "test:all": "node ./tests/run-tests.js", - "prettier": "prettier --write ./src/**/**/**/*" + "prettier": "prettier --write ./src/**/**/**/*", + "docker:dev":"docker-compose -f ./docker/docker-compose.dev.yml up", + "docker:build":"docker-compose -f ./docker/docker-compose.dev.yml build", + "docker-prod:dev":"docker-compose -f ./docker/docker-compose.yml up", + "docker-prod:build":"docker-compose -f ./docker/docker-compose.yml build" }, "dependencies": { "@antv/data-set": "^0.9.6", -- GitLab