diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7731813 --- /dev/null +++ b/.dockerignore @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ed7dbaf --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/__pycache__/app.cpython-38.pyc b/__pycache__/app.cpython-38.pyc deleted file mode 100644 index 9f023c4..0000000 Binary files a/__pycache__/app.cpython-38.pyc and /dev/null differ diff --git a/app.py b/app.py index 83e065d..606e207 100644 --- a/app.py +++ b/app.py @@ -433,4 +433,5 @@ def visualisasi(): return render_template('visualisasi.html') if __name__ == "__main__": - app.run(debug=True) \ No newline at end of file + port = int(os.environ.get("PORT", 8080)) + app.run(host="0.0.0.0", port=port, debug=False) \ No newline at end of file diff --git a/cloudrun.yaml b/cloudrun.yaml new file mode 100644 index 0000000..c2003ae --- /dev/null +++ b/cloudrun.yaml @@ -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" diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..ae9b712 --- /dev/null +++ b/deploy.sh @@ -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." diff --git a/requirements_docker.txt b/requirements_docker.txt new file mode 100644 index 0000000..0509bc8 --- /dev/null +++ b/requirements_docker.txt @@ -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