Optimize docker builds

This commit is contained in:
Yarmo Mackenbach 2022-02-27 19:45:18 +01:00
parent 626faf2778
commit c32da606ab
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
5 changed files with 18 additions and 8 deletions

1
.gitignore vendored
View file

@ -30,5 +30,6 @@ node_modules
.env .env
/.direnv/ /.direnv/
dist
static static
!static/**/*.png !static/**/*.png

View file

@ -6,6 +6,8 @@
**/*.env **/*.env
**/*.pug **/*.pug
dist/
package.json package.json
yarn.lock yarn.lock
robots.txt robots.txt

View file

@ -1,23 +1,23 @@
FROM node:14-alpine as builder FROM node:16-alpine as builder
WORKDIR /app WORKDIR /app
COPY . . COPY . .
RUN yarn --pure-lockfile RUN yarn --pure-lockfile
RUN yarn run build
RUN yarn run build:static RUN yarn run build:static
### ###
FROM node:14-alpine FROM node:16-alpine
WORKDIR /app WORKDIR /app
COPY --from=builder /app/package.json /app/package.json
COPY . . COPY --from=builder /app/dist /app/dist
COPY --from=builder /app/content /app/content
COPY --from=builder /app/views /app/views
COPY --from=builder /app/static /app/static COPY --from=builder /app/static /app/static
RUN yarn --production --pure-lockfile
EXPOSE 3000 EXPOSE 3000
CMD yarn start CMD node ./dist/

View file

@ -22,6 +22,7 @@
"string-replace-middleware": "^1.0.2" "string-replace-middleware": "^1.0.2"
}, },
"devDependencies": { "devDependencies": {
"@vercel/ncc": "^0.33.3",
"css-loader": "^6.6.0", "css-loader": "^6.6.0",
"license-check-and-add": "^4.0.3", "license-check-and-add": "^4.0.3",
"mini-css-extract-plugin": "^2.5.3", "mini-css-extract-plugin": "^2.5.3",
@ -35,6 +36,7 @@
"start": "node ./", "start": "node ./",
"dev": "yarn run watch & yarn run build:static:dev", "dev": "yarn run watch & yarn run build:static:dev",
"watch": "./node_modules/.bin/nodemon --config nodemon.json ./", "watch": "./node_modules/.bin/nodemon --config nodemon.json ./",
"build": "ncc build index.js -o dist",
"build:static": "webpack --config webpack.config.js --env static=true --env mode=production", "build:static": "webpack --config webpack.config.js --env static=true --env mode=production",
"build:static:dev": "webpack --config webpack.config.js --env static=true --env mode=development", "build:static:dev": "webpack --config webpack.config.js --env static=true --env mode=development",
"license:check": "./node_modules/.bin/license-check-and-add check", "license:check": "./node_modules/.bin/license-check-and-add check",

View file

@ -455,6 +455,11 @@
dependencies: dependencies:
"@types/node" "*" "@types/node" "*"
"@vercel/ncc@^0.33.3":
version "0.33.3"
resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.33.3.tgz#aacc6b3ea9f7b175e0c9a18c9b97e4005a2f4fcc"
integrity sha512-JGZ11QV+/ZcfudW2Cz2JVp54/pJNXbsuWRgSh2ZmmZdQBKXqBtIGrwI1Wyx8nlbzAiEFe7FHi4K1zX4//jxTnQ==
"@webassemblyjs/ast@1.11.1": "@webassemblyjs/ast@1.11.1":
version "1.11.1" version "1.11.1"
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7"