Skip to content

Commit 0643b57

Browse files
Phase 11: Add deploy command to generate Dockerfile
1 parent 98f5d6d commit 0643b57

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

pythoncms/cli.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,65 @@ def run(debug):
103103
args.append("--debug")
104104
args.append("run")
105105
subprocess.run(args, check=True)
106+
107+
108+
@cli.command("deploy")
109+
def deploy():
110+
"""Generate production deployment files"""
111+
112+
dockerfile_content = """FROM python:3.11-slim
113+
114+
WORKDIR /app
115+
116+
ENV PYTHONDONTWRITEBYTECODE 1
117+
ENV PYTHONUNBUFFERED 1
118+
ENV FLASK_APP=pythoncms.app:create_app
119+
120+
RUN apt-get update && apt-get install -y --no-install-recommends \
121+
gcc \
122+
libpq-dev \
123+
&& rm -rf /var/lib/apt/lists/*
124+
125+
COPY requirements.txt .
126+
RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
127+
RUN pip install gunicorn
128+
129+
COPY . .
130+
131+
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "pythoncms.app:create_app('production')"]
132+
"""
133+
134+
dockerignore_content = """__pycache__
135+
*.pyc
136+
*.pyo
137+
*.pyd
138+
.Python
139+
env/
140+
venv/
141+
.env
142+
.DS_Store
143+
"""
144+
145+
docker_compose_content = """version: '3.8'
146+
147+
services:
148+
web:
149+
build: .
150+
command: gunicorn --bind 0.0.0.0:8000 "pythoncms.app:create_app('production')"
151+
volumes:
152+
- .:/app
153+
ports:
154+
- "8000:8000"
155+
env_file:
156+
- .env
157+
environment:
158+
- FLASK_ENV=production
159+
"""
160+
161+
trymkfile("Dockerfile", dockerfile_content)
162+
trymkfile(".dockerignore", dockerignore_content)
163+
trymkfile("docker-compose.yml", docker_compose_content)
164+
165+
click.echo("🚀 Deployment files generated!")
166+
click.echo("Run 'docker-compose up --build' to test locally.")
167+
click.echo("Or deploy the Dockerfile to any cloud provider (Fly.io, Railway, etc).")

0 commit comments

Comments
 (0)