From ea5029b52d88645f8f8490f8040a827fc703c7f1 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Tue, 6 Nov 2018 15:24:12 +0200 Subject: [PATCH] chore: optimize docker build --- .dockerignore | 12 ++++++++++++ Dockerfile | 10 ++++++++-- webpack.config.ts | 18 ++++++++++++------ 3 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..c7c2f5ec --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +* +!src/ +!config +!demo/favicon.png + +!custom.d.ts +!typings/styled-patch.d.ts +!tsconfig.json +!webpack.config.ts + +!package.json +!yarn.lock diff --git a/Dockerfile b/Dockerfile index 0e2bfed2..c7c67307 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,10 +9,16 @@ FROM node:alpine RUN apk update && apk add --no-cache git -# generate bundle +# Install dependencies WORKDIR /build -COPY . /build +COPY package.json yarn.lock /build/ RUN yarn install --frozen-lockfile --ignore-optional --ignore-scripts + +# copy only required for the build files +COPY src /build/src +COPY webpack.config.ts tsconfig.json custom.d.ts /build/ +COPY typings/styled-patch.d.ts /build/typings/styled-patch.d.ts + RUN npm run bundle:standalone FROM nginx:alpine diff --git a/webpack.config.ts b/webpack.config.ts index d40adfca..507d50b9 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -17,12 +17,18 @@ const nodeExternals = require('webpack-node-externals')({ }); const VERSION = JSON.stringify(require('./package.json').version); -const REVISION = JSON.stringify( - require('child_process') - .execSync('git rev-parse --short HEAD') - .toString() - .trim(), -); +let REVISION; + +try { + REVISION = JSON.stringify( + require('child_process') + .execSync('git rev-parse --short HEAD') + .toString() + .trim(), + ); +} catch (e) { + console.error('Skipping REDOC_REVISION'); +} const BANNER = `ReDoc - OpenAPI/Swagger-generated API Reference Documentation -------------------------------------------------------------