From 77ccb135df3c3b69e38da8927560ac283f3c60d2 Mon Sep 17 00:00:00 2001 From: fengkx Date: Thu, 19 Mar 2020 19:29:49 +0800 Subject: [PATCH] feat: smaller image (#4278) --- .dockerignore | 15 ++++++++++++++- Dockerfile | 6 +++--- clean-nm.sh | 4 ++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 clean-nm.sh diff --git a/.dockerignore b/.dockerignore index 4d977e32e0bc18..6e5a39cf4aba48 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,7 +4,6 @@ Dockerfile* docker-compose* .dockerignore .gitignore -README.md LICENSE .vscode .github @@ -12,3 +11,17 @@ assets coverage docs test +.codecov.yml +.eslint* +.prettier* +.(yarn|npm|nvm)rc +*.md +process.json +app.json +.travis.yml + +#git but keep the git commit hash +.git/logs +.git/objects +.git/index +.git/info diff --git a/Dockerfile b/Dockerfile index ec4bbcbf4f2a1e..8da23534991fd1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ RUN apt-get update && apt-get install -yq libgconf-2-4 apt-transport-https git d WORKDIR /app -COPY package.json /app +COPY package.json clean-nm.sh /app/ RUN if [ "$USE_CHINA_NPM_REGISTRY" = 1 ]; then \ echo 'use npm mirror'; npm config set registry https://registry.npm.taobao.org; \ @@ -33,10 +33,10 @@ RUN if [ "$PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" = 0 ]; then \ && rm -rf /var/lib/apt/lists/* \ && apt-get purge --auto-remove -y wget\ && rm -rf /src/*.deb \ - && npm install --production; \ + && npm install --production && sh ./clean-nm.sh;\ else \ export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true && \ - npm install --production; \ + npm install --production && sh ./clean-nm.sh;\ fi; COPY . /app diff --git a/clean-nm.sh b/clean-nm.sh new file mode 100644 index 00000000000000..be46df480137ff --- /dev/null +++ b/clean-nm.sh @@ -0,0 +1,4 @@ +#!/bin/sh +find ./node_modules -type f |grep -E "(.idea|.vscode|benchmark.js|.eslintrc.js|changelog|AUTHORS|license|LICENSE|LICENCE|.travis.yml|.eslintrc.json|.eslintrc.yml|Makefile|.npmignore|.DS_Store|.jshintrc|.eslintrc.BSD|.editorconfig|tsconfig.json|.coveralls.yml|appveyor.yml|.gitattributes|.eslintignore|.eslintrc|.eslintignore.BSD|.babelrc)" |xargs rm -rf; +find node_modules -type f | grep -E "\.(md|mdon|markdown|log|ts|swp|jst|coffee|txt|BSD|m?js.map)$" | xargs rm -f; +find node_modules -type d | grep -E "(examples|example|.githubs|@types)" | xargs rm -rf;