mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
Optimize docker build
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
node_modules
|
node_modules
|
||||||
release/app/node_modules
|
release/app/node_modules
|
||||||
release/app/dist
|
release/app/dist
|
||||||
src/server/node_modules
|
server/node_modules
|
||||||
|
|||||||
+14
-8
@@ -2,15 +2,22 @@
|
|||||||
FROM node:16.5-alpine as ui-builder
|
FROM node:16.5-alpine as ui-builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
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
|
# Stage 2 - Build server
|
||||||
FROM node:16.5-alpine as server-builder
|
FROM node:16.5-alpine as server-builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY src/server .
|
COPY server .
|
||||||
RUN ls -lh
|
RUN npm install && npx prisma generate
|
||||||
RUN npm install
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
RUN npm prune --production
|
||||||
|
RUN npm cache clean --force
|
||||||
|
RUN rm -rf /root/.cache
|
||||||
|
|
||||||
|
|
||||||
# Stage 3 - Deploy
|
# Stage 3 - Deploy
|
||||||
FROM node:16.5-alpine
|
FROM node:16.5-alpine
|
||||||
@@ -19,12 +26,12 @@ RUN mkdir appdata
|
|||||||
RUN mkdir feishin-server
|
RUN mkdir feishin-server
|
||||||
RUN mkdir feishin-client
|
RUN mkdir feishin-client
|
||||||
|
|
||||||
# Install server modules
|
RUN npm cache clean --force
|
||||||
COPY src/server/package.json ./feishin-server
|
RUN npm prune --production
|
||||||
RUN cd ./feishin-server && npm install --production
|
|
||||||
|
|
||||||
# Add server build files
|
# Add server build files
|
||||||
COPY --from=server-builder /app/dist ./feishin-server
|
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
|
COPY --from=server-builder /app/prisma ./feishin-server/prisma
|
||||||
|
|
||||||
# Add client build files
|
# 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
|
COPY docker-entrypoint.sh ./feishin-server/docker-entrypoint.sh
|
||||||
RUN chmod +x ./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
|
RUN npm install pm2 -g
|
||||||
|
|
||||||
WORKDIR /root/feishin-server
|
WORKDIR /root/feishin-server
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ services:
|
|||||||
- TOKEN_EXPIRATION=${TOKEN_EXPIRATION}
|
- TOKEN_EXPIRATION=${TOKEN_EXPIRATION}
|
||||||
- TOKEN_REFRESH_EXPIRATION=${TOKEN_REFRESH_EXPIRATION}
|
- TOKEN_REFRESH_EXPIRATION=${TOKEN_REFRESH_EXPIRATION}
|
||||||
ports:
|
ports:
|
||||||
- '9321:9321'
|
- '8843:9321'
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
prisma:
|
prisma:
|
||||||
container_name: feishin_prisma_studio
|
container_name: feishin_prisma_studio
|
||||||
|
|||||||
+10
-7
@@ -3,27 +3,30 @@ services:
|
|||||||
db:
|
db:
|
||||||
container_name: feishin_db
|
container_name: feishin_db
|
||||||
image: postgres:13
|
image: postgres:13
|
||||||
ports:
|
|
||||||
- '5432:5432'
|
|
||||||
volumes:
|
volumes:
|
||||||
- ${DATABASE_PERSIST_PATH}:/var/lib/postgresql/data
|
- ${DATABASE_PERSIST_PATH}:/var/lib/postgresql/data
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_USER=${DATABASE_USERNAME}
|
- POSTGRES_USER=${DATABASE_USERNAME}
|
||||||
- POSTGRES_PASSWORD=${DATABASE_PASSWORD}
|
- POSTGRES_PASSWORD=${DATABASE_PASSWORD}
|
||||||
- POSTGRES_DB=${DATABASE_NAME}
|
- POSTGRES_DB=${DATABASE_NAME}
|
||||||
restart: always
|
ports:
|
||||||
|
- '${DATABASE_PORT}:5432'
|
||||||
|
restart: unless-stopped
|
||||||
server:
|
server:
|
||||||
container_name: feishin
|
container_name: feishin
|
||||||
image: feishin:latest
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
image: feishin
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
environment:
|
environment:
|
||||||
- APP_BASE_URL=${APP_BASE_URL}
|
- 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_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_SECRET=${TOKEN_SECRET}
|
||||||
- TOKEN_EXPIRATION=${TOKEN_EXPIRATION}
|
- TOKEN_EXPIRATION=${TOKEN_EXPIRATION}
|
||||||
- TOKEN_REFRESH_EXPIRATION=${TOKEN_REFRESH_EXPIRATION}
|
- TOKEN_REFRESH_EXPIRATION=${TOKEN_REFRESH_EXPIRATION}
|
||||||
ports:
|
ports:
|
||||||
- '9321:9321'
|
- '8643:9321'
|
||||||
restart: always
|
restart: unless-stopped
|
||||||
|
|||||||
+2
-2
@@ -4,6 +4,6 @@ DATABASE_NAME=feishin
|
|||||||
DATABASE_PORT=5432
|
DATABASE_PORT=5432
|
||||||
DATABASE_PERSIST_PATH=C:/docker/feishin/db
|
DATABASE_PERSIST_PATH=C:/docker/feishin/db
|
||||||
TOKEN_SECRET=SUPERSECRET
|
TOKEN_SECRET=SUPERSECRET
|
||||||
TOKEN_EXPIRATION=15d
|
TOKEN_EXPIRATION=30m
|
||||||
TOKEN_REFRESH_EXPIRATION=90d
|
TOKEN_REFRESH_EXPIRATION=90d
|
||||||
APP_BASE_URL=http://localhost:4343
|
APP_BASE_URL=http://localhost:8643
|
||||||
|
|||||||
@@ -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
@@ -5,7 +5,7 @@
|
|||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nodemon --legacy-watch -e ts,js --exec ts-node -r tsconfig-paths/register server.ts",
|
"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",
|
"dev:debug": "nodemon --config nodemon.json --inspect-brk server.ts",
|
||||||
"build": "tsc --project . && tsconfig-replace-paths --project tsconfig.json"
|
"build": "tsc --project . && tsconfig-replace-paths --project tsconfig.json"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user