Optimize docker build

This commit is contained in:
jeffvli
2022-11-20 16:07:54 -08:00
parent 2cb54a068a
commit 079a400e74
7 changed files with 29 additions and 31 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
node_modules
release/app/node_modules
release/app/dist
src/server/node_modules
server/node_modules
+14 -8
View File
@@ -2,15 +2,22 @@
FROM node:16.5-alpine as ui-builder
WORKDIR /app
COPY . .
RUN npm install && npm run build:renderer
RUN npm install
RUN npm run build:renderer
RUN npm prune --production
RUN npm cache clean --force
RUN rm -rf /root/.cache
# Stage 2 - Build server
FROM node:16.5-alpine as server-builder
WORKDIR /app
COPY src/server .
RUN ls -lh
RUN npm install
COPY server .
RUN npm install && npx prisma generate
RUN npm run build
RUN npm prune --production
RUN npm cache clean --force
RUN rm -rf /root/.cache
# Stage 3 - Deploy
FROM node:16.5-alpine
@@ -19,12 +26,12 @@ RUN mkdir appdata
RUN mkdir feishin-server
RUN mkdir feishin-client
# Install server modules
COPY src/server/package.json ./feishin-server
RUN cd ./feishin-server && npm install --production
RUN npm cache clean --force
RUN npm prune --production
# Add server build files
COPY --from=server-builder /app/dist ./feishin-server
COPY --from=server-builder /app/node_modules ./feishin-server/node_modules
COPY --from=server-builder /app/prisma ./feishin-server/prisma
# Add client build files
@@ -33,7 +40,6 @@ COPY --from=ui-builder /app/release/app/dist/renderer ./feishin-client
COPY docker-entrypoint.sh ./feishin-server/docker-entrypoint.sh
RUN chmod +x ./feishin-server/docker-entrypoint.sh
RUN cd ./feishin-server && npx prisma generate
RUN npm install pm2 -g
WORKDIR /root/feishin-server
+1 -1
View File
@@ -30,7 +30,7 @@ services:
- TOKEN_EXPIRATION=${TOKEN_EXPIRATION}
- TOKEN_REFRESH_EXPIRATION=${TOKEN_REFRESH_EXPIRATION}
ports:
- '9321:9321'
- '8843:9321'
restart: unless-stopped
prisma:
container_name: feishin_prisma_studio
+10 -7
View File
@@ -3,27 +3,30 @@ services:
db:
container_name: feishin_db
image: postgres:13
ports:
- '5432:5432'
volumes:
- ${DATABASE_PERSIST_PATH}:/var/lib/postgresql/data
environment:
- POSTGRES_USER=${DATABASE_USERNAME}
- POSTGRES_PASSWORD=${DATABASE_PASSWORD}
- POSTGRES_DB=${DATABASE_NAME}
restart: always
ports:
- '${DATABASE_PORT}:5432'
restart: unless-stopped
server:
container_name: feishin
image: feishin:latest
build:
context: .
dockerfile: Dockerfile
image: feishin
depends_on:
- db
environment:
- APP_BASE_URL=${APP_BASE_URL}
- DATABASE_URL=postgresql://${DATABASE_USERNAME}:${DATABASE_PASSWORD}@db/${DATABASE_NAME}?schema=public&connection_limit=14&pool_timeout=20
- DATABASE_SECRET=${DATABASE_SECRET}
- DATABASE_PORT=${DATABASE_PORT}
- TOKEN_SECRET=${TOKEN_SECRET}
- TOKEN_EXPIRATION=${TOKEN_EXPIRATION}
- TOKEN_REFRESH_EXPIRATION=${TOKEN_REFRESH_EXPIRATION}
ports:
- '9321:9321'
restart: always
- '8643:9321'
restart: unless-stopped
+2 -2
View File
@@ -4,6 +4,6 @@ DATABASE_NAME=feishin
DATABASE_PORT=5432
DATABASE_PERSIST_PATH=C:/docker/feishin/db
TOKEN_SECRET=SUPERSECRET
TOKEN_EXPIRATION=15d
TOKEN_EXPIRATION=30m
TOKEN_REFRESH_EXPIRATION=90d
APP_BASE_URL=http://localhost:4343
APP_BASE_URL=http://localhost:8643
-11
View File
@@ -1,11 +0,0 @@
# RENAME FILE TO ".env.dev" and use "npm run docker:up" on repository root
DATABASE_USERNAME=admin
DATABASE_PASSWORD=admin
DATABASE_NAME=feishin
DATABASE_PORT=5432
DATABASE_PERSIST_PATH=C:/docker/feishin/db
TOKEN_SECRET=SUPERSECRET
TOKEN_EXPIRATION=15d
TOKEN_REFRESH_EXPIRATION=90d
APP_BASE_URL=http://localhost:4343
+1 -1
View File
@@ -5,7 +5,7 @@
"main": "server.js",
"scripts": {
"dev": "nodemon --legacy-watch -e ts,js --exec ts-node -r tsconfig-paths/register server.ts",
"prod": "ts-node -r tsconfig-paths/register server.ts",
"prod": "ts-node --transpileOnly -r tsconfig-paths/register server.ts",
"dev:debug": "nodemon --config nodemon.json --inspect-brk server.ts",
"build": "tsc --project . && tsconfig-replace-paths --project tsconfig.json"
},