feat: add dockerized demo deployment
This commit is contained in:
13
.dockerignore
Normal file
13
.dockerignore
Normal file
@@ -0,0 +1,13 @@
|
||||
.git/
|
||||
.venv/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
.pytest_cache/
|
||||
.mypy_cache/
|
||||
.ruff_cache/
|
||||
.uvicorn.pid
|
||||
|
||||
docs/
|
||||
README.md
|
||||
85
DEPLOYMENT.md
Normal file
85
DEPLOYMENT.md
Normal file
@@ -0,0 +1,85 @@
|
||||
# Demo Deployment
|
||||
|
||||
This project can run behind the existing Caddy edge service with this temporary route:
|
||||
|
||||
```text
|
||||
Caddy -> chatroom-nginx -> chatroom-app
|
||||
```
|
||||
|
||||
The chatroom compose stack joins the existing external Docker network named `caddy_proxy`. No app ports are published to the host.
|
||||
|
||||
## Start the Chatroom Stack
|
||||
|
||||
From this project directory:
|
||||
|
||||
```powershell
|
||||
docker compose up -d --build
|
||||
docker compose ps
|
||||
```
|
||||
|
||||
Test the FastAPI health endpoint through the Nginx container:
|
||||
|
||||
```powershell
|
||||
docker compose exec chatroom-nginx wget -qO- http://chatroom-app:8000/health
|
||||
```
|
||||
|
||||
## Temporary Caddy Change
|
||||
|
||||
Do this manually in:
|
||||
|
||||
```text
|
||||
D:\Programing\Scripts\Home Lab\Interanet\caddy-deployment\config\caddy\Caddyfile
|
||||
```
|
||||
|
||||
Add this temporary block:
|
||||
|
||||
```caddy
|
||||
chat.amiirkhl.ir {
|
||||
import {$CADDY_TLS_MODE:custom_tls}
|
||||
reverse_proxy chatroom-nginx:80
|
||||
}
|
||||
```
|
||||
|
||||
If the current custom certificate does not include `chat.amiirkhl.ir`, use this instead:
|
||||
|
||||
```caddy
|
||||
chat.amiirkhl.ir {
|
||||
import letsencrypt_tls
|
||||
reverse_proxy chatroom-nginx:80
|
||||
}
|
||||
```
|
||||
|
||||
Reload Caddy from the Caddy deployment directory:
|
||||
|
||||
```powershell
|
||||
docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile
|
||||
```
|
||||
|
||||
## Browser Test
|
||||
|
||||
Open:
|
||||
|
||||
```text
|
||||
https://chat.amiirkhl.ir
|
||||
```
|
||||
|
||||
Use two browser tabs, join the same room, and send messages both ways. The frontend builds its WebSocket URL from the current page, so HTTPS should connect with:
|
||||
|
||||
```text
|
||||
wss://chat.amiirkhl.ir/ws/{room}/{user}
|
||||
```
|
||||
|
||||
## Undo After the Demo
|
||||
|
||||
1. Remove the `chat.amiirkhl.ir` block from the Caddyfile.
|
||||
2. Reload Caddy:
|
||||
|
||||
```powershell
|
||||
docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile
|
||||
```
|
||||
|
||||
3. Stop and remove the chatroom stack from this project directory:
|
||||
|
||||
```powershell
|
||||
docker compose down
|
||||
```
|
||||
15
Dockerfile
Normal file
15
Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
||||
FROM python:3.12-slim
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY app ./app
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers", "--forwarded-allow-ips", "*"]
|
||||
30
docker-compose.yml
Normal file
30
docker-compose.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
services:
|
||||
chatroom-app:
|
||||
build:
|
||||
context: .
|
||||
image: chatroom-app:demo
|
||||
restart: unless-stopped
|
||||
expose:
|
||||
- "8000"
|
||||
networks:
|
||||
- chatroom_internal
|
||||
|
||||
chatroom-nginx:
|
||||
image: nginx:alpine
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- chatroom-app
|
||||
expose:
|
||||
- "80"
|
||||
volumes:
|
||||
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
networks:
|
||||
- chatroom_internal
|
||||
- caddy_proxy
|
||||
|
||||
networks:
|
||||
chatroom_internal:
|
||||
driver: bridge
|
||||
caddy_proxy:
|
||||
external: true
|
||||
name: caddy_proxy
|
||||
35
nginx/default.conf
Normal file
35
nginx/default.conf
Normal file
@@ -0,0 +1,35 @@
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
'' close;
|
||||
}
|
||||
|
||||
map $http_x_forwarded_proto $forwarded_proto {
|
||||
default $http_x_forwarded_proto;
|
||||
'' $scheme;
|
||||
}
|
||||
|
||||
upstream chatroom_app {
|
||||
server chatroom-app:8000;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
location / {
|
||||
proxy_pass http://chatroom_app;
|
||||
proxy_http_version 1.1;
|
||||
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
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 $forwarded_proto;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
proxy_set_header X-Forwarded-Port $server_port;
|
||||
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user