Optimize docker build

This commit is contained in:
Charlie Laabs
2019-12-23 13:07:59 -06:00
parent 42576bbb87
commit d9a412ed75
4 changed files with 52 additions and 19 deletions

View File

@@ -4,3 +4,4 @@
# Allow files and directories
!*.js
!*.json
!*.ts

View File

@@ -1,18 +1,49 @@
FROM keymetrics/pm2:latest-stretch
# Create app directory
########
# BASE
########
FROM keymetrics/pm2:12-alpine as base
WORKDIR /usr/src/markbot
# Install app dependencies
COPY package*.json ./
# Install build tools for erlpack, then install prod deps only, then remove build tools
RUN apk add --no-cache make gcc g++ python && \
npm ci --only=production && \
apk del make gcc g++ python
########
# BUILD
########
FROM base as build
# Copy all *.json, *.js, *.ts
COPY . .
# Prod deps already installed, add dev deps
RUN npm i
RUN npm run build
########
# DEPLOY
########
FROM keymetrics/pm2:12-alpine as deploy
WORKDIR /usr/src/markbot
ENV NPM_CONFIG_LOGLEVEL warn
# Steal node_modules from base image
COPY --from=base /usr/src/markbot/node_modules ./node_modules/
# Steal compiled code from build image
COPY --from=build /usr/src/markbot/dist ./
# Copy package.json for version number
COPY package*.json ./
# If you are building your code for production
ENV NPM_CONFIG_LOGLEVEL warn
RUN npm ci --only=production
# Copy PM2 config
COPY ecosystem.config.js .
# Bundle app source
COPY . .
RUN mkdir config
RUN ls -al
# RUN ls -al
CMD [ "pm2-runtime", "start", "ecosystem.config.js" ]

15
package-lock.json generated
View File

@@ -483,11 +483,12 @@
"dev": true
},
"erlpack": {
"version": "github:discordapp/erlpack#674ebfd3439ba4b7ce616709821d27630f7cdc61",
"from": "github:discordapp/erlpack",
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/erlpack/-/erlpack-0.1.3.tgz",
"integrity": "sha512-QeG9v8CVsY/a/IoQi8zjn23aYKcziOihAxwjUl3tI/KB4R1FjTtctDAAMovgtpC16S+WiOauers2oWwIOQtKBQ==",
"requires": {
"bindings": "^1.2.1",
"nan": "^2.1.0"
"bindings": "^1.5.0",
"nan": "^2.14.0"
}
},
"error-ex": {
@@ -1284,9 +1285,9 @@
"dev": true
},
"nan": {
"version": "2.8.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.8.0.tgz",
"integrity": "sha1-7XFfP+neArV6XmJS2QqWZ14fCFo="
"version": "2.14.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz",
"integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg=="
},
"natural-compare": {
"version": "1.4.0",

View File

@@ -27,7 +27,7 @@
"dependencies": {
"bufferutil": "^4.0.1",
"discord.js": "^11.5.1",
"erlpack": "github:discordapp/erlpack",
"erlpack": "^0.1.3",
"markov-strings": "^2.1.0",
"node-schedule": "^1.3.2",
"source-map-support": "^0.5.16",