@@ -134,7 +134,7 @@ def run(debug, port, host):
134134
135135@cli .command ("deploy" )
136136def 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():
144144ENV PYTHONUNBUFFERED 1
145145ENV 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
152152COPY requirements.txt .
@@ -155,40 +155,68 @@ def deploy():
155155
156156COPY . .
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
174186services:
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