deploy to cloud run
This commit is contained in:
parent
ddf9587ca1
commit
608992ff30
|
@ -0,0 +1,61 @@
|
|||
# Git
|
||||
.git
|
||||
.gitignore
|
||||
|
||||
# Python
|
||||
__pycache__
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
.Python
|
||||
env
|
||||
venv
|
||||
.venv
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
.tox
|
||||
.coverage
|
||||
.coverage.*
|
||||
.pytest_cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.log
|
||||
.mypy_cache
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# IDE
|
||||
.vscode
|
||||
.idea
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
._*
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
# Documentation
|
||||
README.md
|
||||
TUTORIAL.txt
|
||||
|
||||
# Development files
|
||||
circle.png
|
||||
|
||||
# Node modules (if any)
|
||||
node_modules
|
||||
npm-debug.log*
|
||||
|
||||
# Vercel
|
||||
vercel.json
|
||||
|
||||
# Large static files that can be re-generated
|
||||
static/files/*.pkl
|
||||
static/files/*.png
|
||||
static/files/*.csv
|
|
@ -0,0 +1,46 @@
|
|||
# Use Python 3.8 slim image
|
||||
FROM python:3.8-slim
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Install system dependencies required for ML libraries
|
||||
RUN apt-get update && apt-get install -y \
|
||||
gcc \
|
||||
g++ \
|
||||
wget \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Upgrade pip to version 25 (latest available)
|
||||
RUN pip install --upgrade pip
|
||||
|
||||
# Copy requirements first for better caching
|
||||
COPY requirements_docker.txt .
|
||||
|
||||
# Install Python dependencies
|
||||
RUN pip install --no-cache-dir -r requirements_docker.txt
|
||||
|
||||
# Download NLTK data
|
||||
RUN python -c "import nltk; nltk.download('punkt'); nltk.download('stopwords')"
|
||||
|
||||
# Copy application code
|
||||
COPY . .
|
||||
|
||||
# Create necessary directories for file uploads and static files
|
||||
RUN mkdir -p static/files
|
||||
|
||||
# Set environment variables
|
||||
ENV FLASK_APP=app.py
|
||||
ENV FLASK_ENV=production
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8080
|
||||
|
||||
# Create non-root user for security
|
||||
RUN useradd --create-home --shell /bin/bash app \
|
||||
&& chown -R app:app /app
|
||||
USER app
|
||||
|
||||
# Command to run the application
|
||||
CMD ["python", "-m", "gunicorn", "--bind", "0.0.0.0:8080", "--workers", "1", "--timeout", "120", "app:app"]
|
Binary file not shown.
3
app.py
3
app.py
|
@ -433,4 +433,5 @@ def visualisasi():
|
|||
return render_template('visualisasi.html')
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
||||
port = int(os.environ.get("PORT", 8080))
|
||||
app.run(host="0.0.0.0", port=port, debug=False)
|
|
@ -0,0 +1,27 @@
|
|||
apiVersion: serving.knative.dev/v1
|
||||
kind: Service
|
||||
metadata:
|
||||
annotations:
|
||||
run.googleapis.com/ingress: all
|
||||
run.googleapis.com/execution-environment: gen2
|
||||
name: flask-sentiment-analysis
|
||||
spec:
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
run.googleapis.com/execution-environment: gen2
|
||||
run.googleapis.com/cpu-throttling: "false"
|
||||
spec:
|
||||
containerConcurrency: 1000
|
||||
timeoutSeconds: 300
|
||||
containers:
|
||||
- image: gcr.io/PROJECT_ID/flask-sentiment-analysis
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
resources:
|
||||
limits:
|
||||
memory: 2Gi
|
||||
cpu: 1000m
|
||||
env:
|
||||
- name: PORT
|
||||
value: "8080"
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Set your project variables
|
||||
PROJECT_ID="your-gcp-project-id"
|
||||
SERVICE_NAME="flask-sentiment-analysis"
|
||||
REGION="asia-southeast1" # Singapore region (closest to Indonesia)
|
||||
|
||||
echo "Building Docker image..."
|
||||
docker build -t gcr.io/$PROJECT_ID/$SERVICE_NAME .
|
||||
|
||||
echo "Pushing image to Google Container Registry..."
|
||||
docker push gcr.io/$PROJECT_ID/$SERVICE_NAME
|
||||
|
||||
echo "Deploying to Cloud Run..."
|
||||
gcloud run deploy $SERVICE_NAME \
|
||||
--image gcr.io/$PROJECT_ID/$SERVICE_NAME \
|
||||
--platform managed \
|
||||
--region $REGION \
|
||||
--allow-unauthenticated \
|
||||
--memory 2Gi \
|
||||
--cpu 1 \
|
||||
--timeout 300 \
|
||||
--max-instances 10 \
|
||||
--port 8080
|
||||
|
||||
echo "Deployment completed!"
|
||||
echo "Your app should be available at the URL shown above."
|
|
@ -0,0 +1,29 @@
|
|||
# Core Flask dependencies
|
||||
Flask==2.3.3
|
||||
gunicorn==21.2.0
|
||||
Werkzeug==2.3.7
|
||||
|
||||
# Machine Learning & Data Processing
|
||||
scikit-learn==1.3.0
|
||||
pandas==2.0.3
|
||||
numpy==1.24.3
|
||||
nltk==3.8.1
|
||||
textblob==0.17.1
|
||||
|
||||
# Indonesian NLP
|
||||
Sastrawi==1.0.1
|
||||
|
||||
# Social Media API
|
||||
tweepy==4.14.0
|
||||
|
||||
# Translation
|
||||
googletrans==4.0.0rc1
|
||||
|
||||
# Image Processing & Visualization
|
||||
matplotlib==3.7.2
|
||||
wordcloud==1.9.2
|
||||
Pillow==10.0.0
|
||||
|
||||
# Utilities
|
||||
requests==2.31.0
|
||||
urllib3==2.0.4
|
Loading…
Reference in New Issue