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
@ -6,12 +28,11 @@ MAINTAINER cracker0dks
RUN mkdir -p /opt/app
WORKDIR /opt/app
# Install app dependencies
COPY ./package.json /opt/app
RUN npm install
COPY ./package.json ./package-lock.json ./
RUN npm ci --only=prod
# Bundle app source
COPY . /opt/app
COPY scripts ./scripts
COPY --from=base /opt/app/public ./public
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 = {
hot: true,
inline: true,
@ -19,6 +15,11 @@ const devServerConfig = {
}
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)
.listen(port, (err) => {
if (err) {