Optimize deployment and improve package.json

This commit is contained in:
2025-08-23 21:55:21 +03:00
Unverified
parent 91e815029e
commit 1fa1178397
4 changed files with 47 additions and 3 deletions
+7 -1
View File
@@ -1,19 +1,25 @@
# 1. Install pip dependencies
FROM python:3.12 AS builder FROM python:3.12 AS builder
WORKDIR /app WORKDIR /app
RUN python3 -m venv .venv RUN python3 -m venv .venv
COPY backend/requirements.txt . COPY backend/requirements.txt .
RUN ./.venv/bin/pip3 install -r requirements.txt RUN --mount=type=cache,target=/root/.cache/pip \
./.venv/bin/pip3 install -r requirements.txt
# 2. Runtime stage
FROM python:3.12-slim AS runtime FROM python:3.12-slim AS runtime
# 2.1. Non-root user
WORKDIR /app WORKDIR /app
RUN useradd -u 1000 app && \ RUN useradd -u 1000 app && \
chown -R app /app chown -R app /app
USER app USER app
# 2.2. Copy content and create dirs
COPY --chown=app backend . COPY --chown=app backend .
COPY --from=builder --chown=app /app/.venv .venv COPY --from=builder --chown=app /app/.venv .venv
RUN mkdir -p /app/data RUN mkdir -p /app/data
# 3. Final command
ENTRYPOINT exec ./.venv/bin/fastapi run --port ${PORT:-8300} main.py ENTRYPOINT exec ./.venv/bin/fastapi run --port ${PORT:-8300} main.py
+18
View File
@@ -9,6 +9,13 @@ services:
- "8300:8300" - "8300:8300"
volumes: volumes:
- "data:/app/data" - "data:/app/data"
develop:
watch:
- action: sync+restart
path: ../backend
target: /app
- action: rebuild
path: ../backend/requirements.txt
frontend: frontend:
build: build:
@@ -19,6 +26,17 @@ services:
BACKEND_HOST: http://backend:8300 BACKEND_HOST: http://backend:8300
ports: ports:
- "8301:8301" - "8301:8301"
depends_on:
- backend
develop:
watch:
- action: rebuild
path: ../frontend
- action: sync+restart
path: server.js
target: /server/server.js
- action: rebuild
path: package.json
volumes: volumes:
data: data:
+15 -2
View File
@@ -1,26 +1,39 @@
# 1. Build the frontend
FROM node:24 AS frontend FROM node:24 AS frontend
# 1.1. Install npm dependencies
WORKDIR /app WORKDIR /app
COPY package.json . COPY package.json .
RUN npm install --ignore-scripts RUN --mount=type=cache,target=/root/.npm \
npm install --ignore-scripts
# 1.2. Build
COPY frontend frontend COPY frontend frontend
RUN npm run build RUN npm run build
# 2. Build the static file server
FROM node:24 AS server FROM node:24 AS server
# 2.1. Install npm dependencies
WORKDIR /server WORKDIR /server
COPY deployment/frontend/package.json . COPY deployment/frontend/package.json .
RUN npm install RUN --mount=type=cache,target=/root/.npm \
npm install
# 2.2. Copy the code
COPY deployment/frontend/ . COPY deployment/frontend/ .
# 3. Put it all together
FROM node:24-slim FROM node:24-slim
# 3.1. Frontend static files
WORKDIR /app WORKDIR /app
COPY --from=frontend /app/frontend/dist . COPY --from=frontend /app/frontend/dist .
# 3.2. Static file server
WORKDIR /server WORKDIR /server
COPY --from=server /server . COPY --from=server /server .
# 4. Final command
ENV STATIC_FILE_PATH=/app ENV STATIC_FILE_PATH=/app
ENTRYPOINT ["npm", "run", "start"] ENTRYPOINT ["npm", "run", "start"]
+7
View File
@@ -7,12 +7,19 @@
"backend:run": "cd backend && ../.venv/bin/fastapi dev --port 8300 main.py", "backend:run": "cd backend && ../.venv/bin/fastapi dev --port 8300 main.py",
"backend:dependencies": "python3 -m venv .venv && ./.venv/bin/pip3 install -r backend/requirements.txt", "backend:dependencies": "python3 -m venv .venv && ./.venv/bin/pip3 install -r backend/requirements.txt",
"backend:reinstall": "rm -rf .venv && npm run backend:dependencies", "backend:reinstall": "rm -rf .venv && npm run backend:dependencies",
"backend:clean": "rm -rf backend/data",
"frontend:dev": "vite frontend", "frontend:dev": "vite frontend",
"frontend:build": "tsc --project frontend && vite build frontend", "frontend:build": "tsc --project frontend && vite build frontend",
"frontend:preview": "vite preview frontend", "frontend:preview": "vite preview frontend",
"frontend:dependencies": "npm install", "frontend:dependencies": "npm install",
"frontend:clean": "rm -rf frontend/dist",
"dev": "concurrently 'npm run frontend:dev' 'npm run backend:run'", "dev": "concurrently 'npm run frontend:dev' 'npm run backend:run'",
"build": "npm run frontend:build", "build": "npm run frontend:build",
"preview": "cd deployment && docker compose up --build --watch",
"preview:clean": "cd deployment && docker compose down -v",
"clean": "npm run backend:clean && npm run frontend:clean && npm run preview:clean",
"install": "npm run backend:dependencies" "install": "npm run backend:dependencies"
}, },
"devDependencies": { "devDependencies": {