Skip to content

Commit

Permalink
Reducing docker image size (#9)
Browse files Browse the repository at this point in the history
Also
* Update dependencies
* Adopt standard github gitignore for node projects
* Using body typography
  • Loading branch information
andrewrlee authored Dec 15, 2020
1 parent ccc0c03 commit ac0dfa6
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 159 deletions.
139 changes: 119 additions & 20 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,29 +1,128 @@
.sass-cache
.DS_Store
.start.pid
.port.tmp
public
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

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

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*



assets/stylesheets/*.css
lib/govuk_template.html
govuk_modules
node_modules/*
.tmuxp.*
.idea
.vscode
npm-debug.log
build/*
uploads/*
test-results.xml
build-info.json
.env
yarn-error.log
.eslintcache
dist/
test_results/
integration_tests/videos/
integration_tests/screenshots/
.localstack
*/*.iml
*secrets*.yaml
!secrets-example.yaml
!**/templates/secrets.yaml
27 changes: 16 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Build stage 1.
# Stage: base image
ARG BUILD_NUMBER
ARG GIT_REF

Expand All @@ -17,24 +17,28 @@ WORKDIR /app
RUN apt-get update && \
apt-get upgrade -y

# Build stage 2.
# Stage: build assets
FROM base as build
ARG BUILD_NUMBER
ARG GIT_REF

RUN apt-get install -y make python g++

COPY package*.json ./
RUN CYPRESS_INSTALL_BINARY=0 npm ci --no-audit

COPY . .
RUN npm run build

ENV BUILD_NUMBER ${BUILD_NUMBER:-1_0_0}
ENV GIT_REF ${GIT_REF:-dummy}

RUN CYPRESS_INSTALL_BINARY=0 npm ci --no-audit && npm run build && \
export BUILD_NUMBER=${BUILD_NUMBER} && \
RUN export BUILD_NUMBER=${BUILD_NUMBER} && \
export GIT_REF=${GIT_REF} && \
npm run record-build-info

# Build stage 3.
RUN npm prune --no-audit --production

# Stage: copy production assets and dependencies
FROM base

RUN apt-get autoremove -y && \
Expand All @@ -43,19 +47,20 @@ RUN apt-get autoremove -y && \
COPY --from=build --chown=appuser:appgroup \
/app/package.json \
/app/package-lock.json \
/app/dist \
/app/build-info.json \
./

COPY --from=build --chown=appuser:appgroup \
/app/assets ./assets
/app/assets ./assets

COPY --from=build --chown=appuser:appgroup \
/app/node_modules ./node_modules
/app/dist ./dist

RUN npm prune --production
COPY --from=build --chown=appuser:appgroup \
/app/node_modules ./node_modules

EXPOSE 3000
ENV NODE_ENV='production'
USER 2000

CMD [ "npm", "start" ]
CMD [ "npm", "start" ]
Loading

0 comments on commit ac0dfa6

Please sign in to comment.