refacto(Dockerfile): optimized with new setup

This commit is contained in:
Florent Chehab 2020-04-19 17:18:38 +02:00
parent dcc5191a3c
commit 6c5016003a
No known key found for this signature in database
GPG Key ID: 9A0CE018889EA246
3 changed files with 35 additions and 11 deletions

2
.dockerignore Normal file
View File

@ -0,0 +1,2 @@
**/node_modules
**/git

View File

@ -1,4 +1,26 @@
FROM node:11 FROM node:11 as base
# Create app directory
RUN mkdir -p /opt/app
WORKDIR /opt/app
# Install app dependencies
COPY ./package.json package-lock.json ./
RUN npm ci
# Bundle frontend
COPY src ./src
COPY assets ./assets
COPY config ./config
RUN npm run build
#####################
# Final image
#####################
FROM node:11-alpine
ENV NODE_ENV=prod
MAINTAINER cracker0dks MAINTAINER cracker0dks
@ -6,12 +28,11 @@ MAINTAINER cracker0dks
RUN mkdir -p /opt/app RUN mkdir -p /opt/app
WORKDIR /opt/app WORKDIR /opt/app
# Install app dependencies COPY ./package.json ./package-lock.json ./
COPY ./package.json /opt/app RUN npm ci --only=prod
RUN npm install
# Bundle app source COPY scripts ./scripts
COPY . /opt/app COPY --from=base /opt/app/public ./public
EXPOSE 8080 EXPOSE 8080
CMD [ "npm", "start" ] ENTRYPOINT [ "npm", "run", "start:prod-no-build" ]

View File

@ -1,7 +1,3 @@
const webpack = require("webpack");
const WebpackDevServer = require("webpack-dev-server");
const config = require("../config/webpack.dev");
const devServerConfig = { const devServerConfig = {
hot: true, hot: true,
inline: true, inline: true,
@ -19,6 +15,11 @@ const devServerConfig = {
} }
function startFrontendDevServer(port) { function startFrontendDevServer(port) {
// require here to prevent prod dependency to webpack
const webpack = require("webpack");
const WebpackDevServer = require("webpack-dev-server");
const config = require("../config/webpack.dev");
new WebpackDevServer(webpack(config), devServerConfig) new WebpackDevServer(webpack(config), devServerConfig)
.listen(port, (err) => { .listen(port, (err) => {
if (err) { if (err) {