From 4d0bc9a4c6c41191c20599c7a182ffe266e71dc6 Mon Sep 17 00:00:00 2001 From: tedoaba Date: Mon, 28 Oct 2024 08:22:33 +0300 Subject: [PATCH] render deployment --- Dockerfile | 30 ++++++++++++++++-------------- app/requirements.txt | 28 ++++++++++++++++++++++++++++ docker-compose.yml | 34 ++++++++++++++++++++++++++-------- render.yaml | 22 ++++++++++++++++++++++ 4 files changed, 92 insertions(+), 22 deletions(-) create mode 100644 app/requirements.txt create mode 100644 render.yaml diff --git a/Dockerfile b/Dockerfile index 50d7b1e..03298fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,26 @@ -# Use the official Python image as a base image +# Use official Python image FROM python:3.10 -# Set the working directory in the container +# Set environment variables for Flask +ENV PYTHONUNBUFFERED=1 + +# Set working directory WORKDIR /app -# Copy the requirements file into the container +# Copy requirements file and install dependencies COPY requirements.txt . +RUN pip install -r requirements.txt -# Install the dependencies -RUN pip install --no-cache-dir -r requirements.txt - -# Copy the entire application into the container +# Copy project files COPY . . -# Set environment variables -ENV FLASK_APP=app -ENV FLASK_ENV=development +# Install npm and necessary packages (for running Tailwind CSS commands) +RUN apt-get update && apt-get install -y nodejs npm +WORKDIR /app/app # Move to where `package.json` is located +RUN npm install -# Expose the port the app runs on -EXPOSE 5000 +# Expose Flask port +EXPOSE 8000 -# Command to run the application -CMD ["flask", "run", "--host=0.0.0.0"] +# Command to run on container start +CMD ["flask", "--app", "app", "run", "--host=0.0.0.0", "--port=8000", "--debug"] diff --git a/app/requirements.txt b/app/requirements.txt new file mode 100644 index 0000000..0cdb288 --- /dev/null +++ b/app/requirements.txt @@ -0,0 +1,28 @@ +pandas +numpy +matplotlib +seaborn +dbt +dbt-postgres +psycopg2 +psycopg2-binary +telethon +sqlalchemy +databases +scikit-learn +scipy +python-dotenv +xgboost +mlflow +imblearn +tensorflow +shap +lime +mlflow +flask +click +flask_sqlalchemy +Flask-Migrate +pytest +dbt +dash \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index df81bb2..050913d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,40 @@ services: - flask: + web: build: . + container_name: flask_app + command: flask --app app run --host=0.0.0.0 --port=8000 --debug ports: - - "5000:5000" + - "8000:8000" environment: - - DATABASE_URL=${DATABASE_URL} + - FLASK_APP=app + - FLASK_SECRET_KEY=${FLASK_SECRET_KEY} + - SQLALCHEMY_DATABASE_URI=postgresql://postgres:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB} + - ENVIRONMENT=${ENVIRONMENT} depends_on: - db + - css + volumes: + - .:/app db: image: postgres:17 - restart: always + container_name: postgres_db environment: - - POSTGRES_DB=${POSTGRES_DB} - - POSTGRES_USER=${POSTGRES_USER} - - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + ports: + - "5432:5432" volumes: - postgres_data:/var/lib/postgresql/data + css: + image: node:14 + container_name: css_processor + working_dir: /app/app + volumes: + - .:/app + command: ["npm", "run", "create-css"] + volumes: - postgres_data: \ No newline at end of file + postgres_data: diff --git a/render.yaml b/render.yaml new file mode 100644 index 0000000..3778c0e --- /dev/null +++ b/render.yaml @@ -0,0 +1,22 @@ +services: + - type: web + name: css-builder + env: node + buildCommand: "npm install" + startCommand: "npx tailwindcss -i ./static/src/input.css -o ./static/css/main.css --minify" + plan: free + + - type: web + name: init-db + env: python + buildCommand: "pip install -r requirements.txt" + startCommand: "flask --app app init-db" + plan: free + autoDeploy: false + + - type: web + name: flask-dash-app + env: python + buildCommand: "pip install -r requirements.txt" + startCommand: "flask --app app run --host 0.0.0.0 --port 8000 --debug" + plan: free