Skip to content

Commit

Permalink
I focused on Docker issues and that's the result
Browse files Browse the repository at this point in the history
- Use package-lock.json through command: npm ci
- Fixes regarding Docker Compose setup
- Multistage build to get only what is needed for PRD image

Useful links
- https://git.io/JebrQ
- webpack/webpack#520 (comment)
  • Loading branch information
willianantunes committed Dec 30, 2019
1 parent e77db4f commit d7959c2
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 204 deletions.
26 changes: 26 additions & 0 deletions .dockerignore
@@ -0,0 +1,26 @@
# Defaults
.git
*Dockerfile*
*docker-compose*

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by some tools
coverage

# Dependency directory
node_modules

# Custom
__tests__
jest.config.js
20 changes: 17 additions & 3 deletions Dockerfile
@@ -1,9 +1,23 @@
FROM node:12.14.0-alpine
FROM node:12-alpine as build

WORKDIR /app

COPY . /app

RUN npm run build
# I don't know why but Next.JS require devDependencies to build the project
RUN npm ci --only=production
RUN cp -R node_modules prod_node_modules
RUN npm ci && npm run build

FROM node:12-alpine

WORKDIR /app

# Copy production node_modules
COPY --from=build /app/prod_node_modules ./node_modules
COPY --from=build /app/package.json ./
# Server-side
COPY --from=build /app/src ./src
# SPA
COPY --from=build /app/dist ./dist

CMD npm run start
10 changes: 6 additions & 4 deletions docker-compose.yml
Expand Up @@ -6,17 +6,19 @@ services:
env_file: .env
ports:
- "${NEXTJS_BIND_PORT}:${NEXTJS_BIND_PORT}"
unit-tests:
unit-test:
image: node:12.14.0-alpine
env_file: .env
working_dir: /app
volumes:
- .:/app
command: npm run test-unit
int-tests:
command: >
sh -c "npm ci && npm run unit-test"
int-test:
image: node:12.14.0-alpine
env_file: .env
working_dir: /app
volumes:
- .:/app
command: npm run test-int
command: >
sh -c "npm ci && npm run int-test"

0 comments on commit d7959c2

Please sign in to comment.