mirror of
https://github.com/pacnpal/markov-discord.git
synced 2025-12-20 03:01:04 -05:00
Optimize docker build
This commit is contained in:
49
Dockerfile
49
Dockerfile
@@ -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" ]
|
||||
Reference in New Issue
Block a user