diff --git a/docker/Dockerfile.backend b/docker/Dockerfile.backend index 2732b21..c6e3d64 100644 --- a/docker/Dockerfile.backend +++ b/docker/Dockerfile.backend @@ -1,5 +1,8 @@ # Backend Dockerfile -FROM node:16-alpine +FROM node:18-slim + +# Установка зависимостей для сборки нативных модулей +RUN apt-get update && apt-get install -y python3 build-essential curl && apt-get clean # Set working directory WORKDIR /app @@ -8,7 +11,7 @@ WORKDIR /app COPY package*.json ./ # Install dependencies -RUN npm ci --only=production +RUN npm install --only=production # Copy source code COPY . . @@ -24,4 +27,4 @@ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD curl -f http://localhost:3001/health || exit 1 # Start application -CMD ["npm", "start"] +CMD ["npm", "start"] \ No newline at end of file diff --git a/docker/Dockerfile.frontend b/docker/Dockerfile.frontend index 660a042..f68f4b6 100644 --- a/docker/Dockerfile.frontend +++ b/docker/Dockerfile.frontend @@ -4,11 +4,11 @@ FROM nginx:alpine # Copy static files COPY . /usr/share/nginx/html/ -# Copy nginx config -COPY nginx.conf /etc/nginx/conf.d/default.conf +# Устанавливаем правильные права +RUN chmod -R 755 /usr/share/nginx/html/ # Expose port EXPOSE 80 # Start nginx -CMD ["nginx", "-g", "daemon off;"] +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index dbf397b..cdd6a23 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,24 +1,21 @@ version: '3.8' - services: # Frontend Service frontend: build: - context: ./frontend - dockerfile: Dockerfile + context: ../frontend + dockerfile: ../docker/Dockerfile.frontend container_name: cash_system_frontend ports: - "3000:80" - depends_on: - - backend networks: - cash_system_network - + # Backend Service backend: build: - context: ./backend - dockerfile: Dockerfile + context: ../backend + dockerfile: ../docker/Dockerfile.backend container_name: cash_system_backend ports: - "3001:3001" @@ -27,10 +24,10 @@ services: - PORT=3001 - DB_PATH=/app/data/database.sqlite volumes: - - ./data:/app/data + - ../data:/app/data networks: - cash_system_network - + # Nginx Reverse Proxy nginx: image: nginx:alpine @@ -38,7 +35,7 @@ services: ports: - "80:80" volumes: - - ./docker/nginx.conf:/etc/nginx/nginx.conf + - ./nginx.conf:/etc/nginx/nginx.conf depends_on: - frontend - backend @@ -50,4 +47,4 @@ networks: driver: bridge volumes: - database_data: + database_data: \ No newline at end of file diff --git a/docker/nginx.conf b/docker/nginx.conf index 2c39cc2..783fefe 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -10,11 +10,11 @@ http { upstream backend { server backend:3001; } - + server { listen 80; server_name localhost; - + # Frontend routes location / { proxy_pass http://frontend; @@ -23,7 +23,7 @@ http { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } - + # API routes location /api/ { proxy_pass http://backend; @@ -32,7 +32,7 @@ http { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } - + # Static files location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ { proxy_pass http://frontend; @@ -40,4 +40,4 @@ http { add_header Cache-Control "public, immutable"; } } -} +} \ No newline at end of file diff --git a/frontend/api.js b/frontend/api.js index d49fe7b..20d9b45 100644 --- a/frontend/api.js +++ b/frontend/api.js @@ -1,5 +1,5 @@ //API -const API_BASE_URL = "http://localhost:3001/api"; +const API_BASE_URL = "http://195.209.214.159/api"; //Login async function loginUser(username, password) {