Update docker-compose for backend and reverse proxy

master
John Montagu, the 4th Earl of Sandvich 2024-11-07 18:12:53 -08:00
parent 13e9bf390b
commit 067c287fc4
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
3 changed files with 69 additions and 13 deletions

View File

@ -1,15 +1,12 @@
# Use an official Python runtime as a parent image
FROM python:3.11-slim
# Set the working directory in the container
WORKDIR /app
COPY requirements.txt /
# Install dependencies
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
# Copy the entire app into the container
COPY . .
COPY . /app
WORKDIR /app
# Expose the Flask development server port
EXPOSE 5000
@ -19,4 +16,4 @@ ENV FLASK_APP=app.py
ENV FLASK_ENV=development
# Command to run the Flask application
CMD ["flask", "run", "--host=0.0.0.0", "--port=5000"]
CMD ["flask", "run", "--host=0.0.0.0", "--port=5000", "--debug"]

View File

@ -1,11 +1,46 @@
version: '3.9'
services:
# Flask service
backend:
build: ./backend
container_name: backend
build:
context: ./backend-flask
#image: jazzdd/alpine-flask:python3
ports:
- 5000:5000
- ":5000"
volumes:
- ./backend:/app
- ./sqlite3:/app/sqlite3
command: uvicorn src.main:app --reload --host 0.0.0.0 --port 5000
- ./backend-flask:/app
networks:
- dev-network
# Vue + Vite service
frontend:
container_name: frontend
build:
context: ./availabili.tf
ports:
- ":5173"
environment:
- DB_URI=sqlite:///./sqlite3/db.sqlite3
VITE_API_URL: http://localhost:8000 # API endpoint
volumes:
- ./availabili.tf:/app
networks:
- dev-network
# NGINX service
nginx:
image: nginx:latest
ports:
- "8000:80"
volumes:
- ./nginx:/etc/nginx/conf.d
depends_on:
- backend
- frontend
networks:
- dev-network
networks:
dev-network:
driver: bridge

24
nginx/default.conf 100644
View File

@ -0,0 +1,24 @@
server {
listen 80;
# Proxy for the Vite frontend
location / {
proxy_pass http://frontend:5173;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# Proxy for the Flask backend API
location /api/ {
proxy_pass http://backend:5000;
proxy_set_header Host $host;
}
location /apidoc/ {
proxy_pass http://backend:5000;
proxy_set_header Host $host;
}
}