Commit a3ff74ba authored by Markus Mößler's avatar Markus Mößler
Browse files

added docker files and nginx files for production mode

parent 71187442
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
version: '3.8'

services:
  react-frontend:
    build:
      context: ./react-frontend
      dockerfile: Dockerfile.prod
    depends_on:
      - tornado-backend
    networks:
      - app-network      

  tornado-backend:
    build: ./tornado-backend
    command: --db_host=postgres
    depends_on:
      - postgres
    networks:
      - app-network    

  postgres:
    image: postgres:10.3
    environment:
      POSTGRES_USER: blog
      POSTGRES_PASSWORD: blog
      POSTGRES_DB: blog
    volumes:
      - ./pg_data:/var/lib/postgresql/data:rw
    networks:
      - app-network      

  adminer:
    image: adminer
    ports:
      - 8080:8080
    networks:
      - app-network      

  nginx:
    image: nginx:latest
    ports:
      - "80:80"
    volumes:
      - ./react-frontend/my-react-app/build:/usr/share/nginx/html:ro
      - ./nginx/nginx.prod.conf:/etc/nginx/nginx.conf:ro
    depends_on:
      - react-frontend
      - tornado-backend
    networks:
      - app-network

networks:
  app-network:
    driver: bridge
+1 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ services:
  react-frontend:
    build:
      context: ./react-frontend
      dockerfile: Dockerfile
    volumes:
      - ./react-frontend/my-react-app:/app
    ports:

nginx/nginx.prod.conf

0 → 100644
+31 −0
Original line number Diff line number Diff line
events { }

http {

    upstream tornado {
        server tornado-backend:8888;
    }

    server {
        listen 80;
        server_name localhost;

        # Serve React frontend build files
        root /usr/share/nginx/html;
        index index.html;

        # Route all frontend paths to index.html (for React Router)
        location / {
            try_files $uri /index.html;
        }

        # Proxy API calls to Tornado backend
        location /tornado-backend/ {
            proxy_pass http://tornado;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
}
+13 −0
Original line number Diff line number Diff line
FROM node:20 AS builder

WORKDIR /app

# Install dependencies
COPY ./my-react-app/package*.json ./
RUN npm install

# Copy source code
COPY ./my-react-app ./

# Build the production-ready app
RUN npm run build