Skip to content

Commit 2aabab1

Browse files
Improve deployment with Nginx reverse proxy support
1 parent 1e45429 commit 2aabab1

2 files changed

Lines changed: 61 additions & 26 deletions

File tree

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,23 @@ Manage your entire project from one place:
4040

4141
## 🚀 Production Deployment
4242

43-
Deploying your CMS is now a single command:
43+
Deploying your CMS with a production-grade Nginx reverse proxy is now a single command:
4444

4545
```bash
4646
pythoncms deploy
4747
```
4848

49-
This generates a production-ready `Dockerfile` and `docker-compose.yml`. You can deploy this directly to:
50-
- **Fly.io**: `fly launch`
51-
- **Railway**: Connect your repo
52-
- **VPS**: `docker-compose up -d --build`
49+
This generates:
50+
- **Dockerfile**: Optimized for Gunicorn performance.
51+
- **nginx.conf**: Configured for request buffering and fast static file serving.
52+
- **docker-compose.yml**: Orchestrates the app and Nginx containers.
53+
54+
### Quick Start
55+
1. Run `pythoncms deploy`.
56+
2. (Optional) Edit `nginx.conf` to add your domain.
57+
3. Run `docker-compose up --build -d`.
58+
59+
Your site will be live on port 80 with Nginx handling all incoming traffic.
5360

5461
---
5562

pythoncms/cli.py

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def run(debug, port, host):
134134

135135
@cli.command("deploy")
136136
def deploy():
137-
"""Generate production deployment files"""
137+
"""Generate production deployment files (Docker + Nginx)"""
138138

139139
dockerfile_content = """FROM python:3.11-slim
140140
@@ -144,9 +144,9 @@ def deploy():
144144
ENV PYTHONUNBUFFERED 1
145145
ENV FLASK_APP=pythoncms.app:create_app
146146
147-
RUN apt-get update && apt-get install -y --no-install-recommends \
148-
gcc \
149-
libpq-dev \
147+
RUN apt-get update && apt-get install -y --no-install-recommends \\
148+
gcc \\
149+
libpq-dev \\
150150
&& rm -rf /var/lib/apt/lists/*
151151
152152
COPY requirements.txt .
@@ -155,40 +155,68 @@ def deploy():
155155
156156
COPY . .
157157
158-
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "pythoncms.app:create_app('production')"]
158+
# Ensure static files are collected if needed
159+
# RUN flask shopyo-collectstatic
160+
161+
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "4", "pythoncms.app:create_app('production')"]
159162
"""
160163

161-
dockerignore_content = """__pycache__
162-
*.pyc
163-
*.pyo
164-
*.pyd
165-
.Python
166-
env/
167-
venv/
168-
.env
169-
.DS_Store
164+
nginx_content = """server {
165+
listen 80;
166+
server_name localhost;
167+
168+
location / {
169+
proxy_pass http://web:8000;
170+
proxy_set_header Host $host;
171+
proxy_set_header X-Real-IP $remote_addr;
172+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
173+
proxy_set_header X-Forwarded-Proto $scheme;
174+
}
175+
176+
location /static/ {
177+
alias /app/pythoncms/static/;
178+
expires 30d;
179+
add_header Cache-Control "public, no-transform";
180+
}
181+
}
170182
"""
171183

172184
docker_compose_content = """version: '3.8'
173185
174186
services:
175187
web:
176188
build: .
177-
command: gunicorn --bind 0.0.0.0:8000 "pythoncms.app:create_app('production')"
178189
volumes:
179190
- .:/app
180-
ports:
181-
- "8000:8000"
191+
- static_volume:/app/pythoncms/static
182192
env_file:
183193
- .env
184194
environment:
185195
- FLASK_ENV=production
196+
197+
nginx:
198+
image: nginx:alpine
199+
restart: always
200+
ports:
201+
- "80:80"
202+
volumes:
203+
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
204+
- static_volume:/app/pythoncms/static:ro
205+
depends_on:
206+
- web
207+
208+
volumes:
209+
static_volume:
186210
"""
187211

188212
trymkfile("Dockerfile", dockerfile_content)
189-
trymkfile(".dockerignore", dockerignore_content)
213+
trymkfile("nginx.conf", nginx_content)
190214
trymkfile("docker-compose.yml", docker_compose_content)
215+
trymkfile(".dockerignore", "__pycache__\\n*.pyc\\n.env\\nvenv/\\ninstance/\\n")
191216

192-
click.echo("🚀 Deployment files generated!")
193-
click.echo("Run 'docker-compose up --build' to test locally.")
194-
click.echo("Or deploy the Dockerfile to any cloud provider (Fly.io, Railway, etc).")
217+
click.echo("🚀 Production deployment files generated!")
218+
click.echo("Included: Dockerfile, nginx.conf, docker-compose.yml")
219+
click.echo("")
220+
click.echo("To deploy:")
221+
click.echo("1. Edit 'nginx.conf' to set your real domain name.")
222+
click.echo("2. Run 'docker-compose up --build -d'")

0 commit comments

Comments
 (0)