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

@@ -3,4 +3,5 @@
# Allow files and directories # Allow files and directories
!*.js !*.js
!*.json !*.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 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 ./ COPY package*.json ./
# If you are building your code for production # Copy PM2 config
ENV NPM_CONFIG_LOGLEVEL warn COPY ecosystem.config.js .
RUN npm ci --only=production
# Bundle app source
COPY . .
RUN mkdir config RUN mkdir config
RUN ls -al # RUN ls -al
CMD [ "pm2-runtime", "start", "ecosystem.config.js" ] CMD [ "pm2-runtime", "start", "ecosystem.config.js" ]

15
package-lock.json generated
View File

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

View File

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