Skip to content

Commit

Permalink
feat(docker): Dockerfile optimization (#98)
Browse files Browse the repository at this point in the history
* feat(docker): Optimization

* chore(docker): add seperator here

* fix(docker): copy assets folder before the dist folder

* feat(docker): add ignore file

* feat(docker): Optimization

* chore(docker): add seperator here

* fix(docker): copy assets folder before the dist folder

* feat(docker): add ignore file
  • Loading branch information
Hazmi35 authored Oct 1, 2020
1 parent 2c70020 commit 5a91a1b
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 15 deletions.
111 changes: 111 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# 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/

# 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

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt

# 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

# TypeScript out directory
dist
dist/

# Git files
.github/
.git
.dependabot

# VSCode settings folder
.vscode
38 changes: 23 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,44 @@ FROM node:12-alpine as build-stage

WORKDIR /tmp/build

COPY . .
# Copy package.json and yarn.lock
COPY package.json .
COPY yarn.lock .

# Install build tools for node-gyp
RUN apk add --no-cache build-base curl git python3 \
# Some required shared libraries for node-canvas
cairo-dev jpeg-dev pango-dev giflib-dev pixman-dev pangomm-dev libjpeg-turbo-dev freetype-dev
# And some required shared libraries for node-canvas
cairo-dev jpeg-dev pango-dev giflib-dev pixman-dev pangomm-dev libjpeg-turbo-dev freetype-dev

# Install node dependencies
RUN yarn install \
RUN yarn install

# Now copy project files
COPY . .

# Build typescript project
&& yarn build \
RUN yarn run build

# Prune dev dependencies
&& yarn install --production
RUN yarn install --production

# Get ready for production
FROM node:12-alpine

LABEL name "Yumeko"

WORKDIR /app

# Copy needed project files
COPY --from=build-stage /tmp/build/dist ./dist
COPY --from=build-stage /tmp/build/config.json ./
COPY --from=build-stage /tmp/build/assets ./assets
COPY --from=build-stage /tmp/build/node_modules ./node_modules
COPY --from=build-stage /tmp/build/package.json ./

# Install dependencies
RUN apk add --no-cache pixman cairo pango giflib libjpeg-turbo freetype \
# node-canvas default font
ttf-opensans ttf-dejavu ttf-droid ttf-freefont ttf-liberation ttf-ubuntu-font-family fontconfig
# and node-canvas default font
ttf-opensans ttf-dejavu ttf-droid ttf-freefont ttf-liberation ttf-ubuntu-font-family fontconfig

# Copy needed project files
COPY --from=build-stage /tmp/build/package.json .
COPY --from=build-stage /tmp/build/yarn.lock .
COPY --from=build-stage /tmp/build/node_modules ./node_modules
COPY --from=build-stage /tmp/build/assets ./assets
COPY --from=build-stage /tmp/build/dist .

CMD ["node", "dist"]

0 comments on commit 5a91a1b

Please sign in to comment.