Skip to content

Commit 565cec3

Browse files
committed
upt
1 parent ae66c10 commit 565cec3

File tree

5 files changed

+62
-5
lines changed

5 files changed

+62
-5
lines changed

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Use Python 3.11 as base image
2+
FROM python:3.11-slim
3+
4+
# Set working directory
5+
WORKDIR /app
6+
7+
# Set environment variables
8+
ENV PYTHONDONTWRITEBYTECODE=1
9+
ENV PYTHONUNBUFFERED=1
10+
11+
# Install system dependencies
12+
RUN apt-get update && apt-get install -y \
13+
gcc \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
# Copy requirements first (for better Docker layer caching)
17+
COPY requirements.txt .
18+
19+
# Install Python dependencies
20+
RUN pip install --no-cache-dir -r requirements.txt
21+
22+
# Copy application code
23+
COPY . .
24+
25+
# Create non-root user for security
26+
RUN useradd --create-home --shell /bin/bash app && chown -R app:app /app
27+
USER app
28+
29+
# Expose port
30+
EXPOSE 8080
31+
32+
# Use Gunicorn with Uvicorn workers for FastAPI
33+
CMD ["gunicorn", "main:app", "--workers", "4", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8080", "--timeout", "120"]

deploy.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -e
77
# Configuration
88
PROJECT_ID=${PROJECT_ID:-"your-project-id"}
99
REGION=${REGION:-"us-central1"}
10-
SERVICE_NAME=${SERVICE_NAME:-"whatsapp-bot"}
10+
SERVICE_NAME=${SERVICE_NAME:-"be-project"}
1111
IMAGE_NAME="gcr.io/${PROJECT_ID}/${SERVICE_NAME}"
1212

1313
echo "🚀 Deploying WhatsApp Bot to Google Cloud Run..."
@@ -29,12 +29,12 @@ gcloud run deploy ${SERVICE_NAME} \
2929
--platform managed \
3030
--region ${REGION} \
3131
--allow-unauthenticated \
32-
--memory 1Gi \
33-
--cpu 1 \
32+
--memory 2Gi \
33+
--cpu 2 \
3434
--timeout 300 \
3535
--max-instances 10 \
36-
--set-env-vars PORT=8080 \
37-
--port 8080
36+
--port 8080 \
37+
--set-env-vars PORT=8080
3838

3939
echo "✅ Deployment complete!"
4040

main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,15 @@ async def handle_analyze(self, _, msg: types.Message):
155155
app = FastAPI()
156156
# Create an instance of the WhatsAppBot which registers the handlers
157157
bot = WhatsAppBot(app)
158+
159+
# Add a simple health check endpoint
160+
@app.get("/")
161+
async def health_check():
162+
return {"status": "healthy", "message": "WhatsApp Bot is running"}
163+
164+
if __name__ == "__main__":
165+
import uvicorn
166+
import os
167+
168+
port = int(os.environ.get("PORT", 8080))
169+
uvicorn.run(app, host="0.0.0.0", port=port)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,4 @@ uvloop==0.21.0
6969
watchfiles==1.0.4
7070
websockets==14.2
7171
yarl==1.18.3
72+
gunicorn==23.0.0

start.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# Start the FastAPI application with Gunicorn and Uvicorn workers
4+
exec gunicorn main:app \
5+
--workers 4 \
6+
--worker-class uvicorn.workers.UvicornWorker \
7+
--bind 0.0.0.0:${PORT:-8080} \
8+
--timeout 120 \
9+
--keep-alive 2 \
10+
--max-requests 1000 \
11+
--max-requests-jitter 100

0 commit comments

Comments
 (0)