I have been on this for days. I know it is because my app is not connecting on the port. This are my files:
Docker file
# Use the official Python image from the Docker Hub
FROM python:3.9-slim
# Set the working directory in the container
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
ENV PORT=8080
# Make port 8080 available to the world outside this container
EXPOSE 8080
# Run flask app
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
fly.staging.toml:
# fly.toml app configuration file generated for oddience-scripts on 2024-07-28T20:03:16+01:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = 'oddience-scripts'
primary_region = 'lhr'
kill_signal = "SIGINT"
kill_timeout = 60
processes = []
[deploy]
strategy = "bluegreen"
[build]
builder = 'paketobuildpacks/builder:base'
buildpacks = ["gcr.io/paketo-buildpacks/python"]
[env]
PORT = '8080'
[[services]]
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 1
[[services.http_checks]]
path = "/"
interval = "10s"
timeout = "2s"
[services.concurrency]
hard_limit = 5000
soft_limit = 2500
type = "requests"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
main.py:
from fastapi import FastAPI, HTTPException
from models import UserData
from data_processing import process_user_data
from apscheduler.schedulers.background import BackgroundScheduler
from config import UPDATE_INTERVALS
from table_update_script import update_table
app = FastAPI()
def job_function():
print("Scheduler is alive!");
update_table()
sched = BackgroundScheduler(daemon=True)
sched.add_job(job_function,'interval',hours=int(UPDATE_INTERVALS))
sched.start()
@app.post('/process_user')
def process_user(data: UserData):
user_id = data.user_id
social = data.social
if not user_id or not social:
raise HTTPException(status_code=400, detail="user_id and social are required")
scored_df, post_metrics_df, pricing_df = process_user_data(user_id, social)
if scored_df is None or post_metrics_df is None or pricing_df is None:
raise HTTPException(status_code=500, detail="Failed to fetch user data")
return {"message": "Data processed and appended successfully"}
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, host='0.0.0.0', port=8080)
I getting this error on deployment: