Flask app exits immediately after being deployed on Fly

Hello,

I have a very simple Flask (Python) application. The Docker container builds and runs correctly locally.

When I deploy to Fly, it also starts correctly, and if I place a print() statement I can see that it is running.

However, it then immediately exits with code 0, as if the script has finished executing. There are no errors and warnings.

I’ve reduced the app to a minimum (just a route which returns 200). I’m assuming that something is wrong with my Fly configuration, but I’ve been unable to find out what’s wrong.

I’ve made sure that the app uses the correct port. Running fly doctor shows everything OK. I also have a Node app which is running just fine.

What am I doing wrong? What can I do to debug this further?

Logs:

 2023-07-27T08:42:11.380 runner[123] ams [info] Pulling container image registry.fly.io/my-cool-app:deployment-123

2023-07-27T08:42:20.695 runner[123] ams [info] Successfully prepared image registry.fly.io/my-cool-app:deployment-123 (9.315107106s)

2023-07-27T08:42:21.351 runner[123] ams [info] Configuring firecracker

2023-07-27T08:42:22.788 app[123] ams [info] [ 0.040081] PCI: Fatal: No config space access function found

2023-07-27T08:42:23.014 app[123] ams [info] INFO Starting init (commit: 1d1821d)...

2023-07-27T08:42:23.094 app[123] ams [info] INFO Preparing to run: `/cnb/process/web` as 1000

2023-07-27T08:42:23.099 app[123] ams [info] INFO [fly api proxy] listening at /.fly/api

2023-07-27T08:42:23.115 app[123] ams [info] 2023/07/27 08:42:23 listening on [123:123]:22 (DNS: [123::3]:53)

2023-07-27T08:42:24.100 app[123] ams [info] INFO Main child exited normally with code: 0

2023-07-27T08:42:24.100 app[123] ams [info] INFO Starting clean up.

2023-07-27T08:42:24.101 app[123] ams [info] WARN hallpass exited, pid: 256, status: signal: 15 (SIGTERM)

2023-07-27T08:42:24.107 app[123] ams [info] 2023/07/27 08:42:24 listening on [123:123]:22 (DNS: [123::3]:53)

2023-07-27T08:42:25.102 app[123] ams [info] [ 2.350698] reboot: Restarting system

2023-07-27T08:42:25.534 runner[123] ams [info] machine exited with exit code 0, not restarting

fly.toml

app = "my-cool-app"
primary_region = "ams"

[build]
builder = "paketobuildpacks/builder:base"

[env]
PORT = "5000"
LOG_LEVEL = "debug"
FLASK_DEBUG = 1

[deploy]
strategy = "immediate"


[http_service]
internal_port = 5000
force_https = false
auto_stop_machines = false
auto_start_machines = true
min_machines_running = 0
processes = ["app"]

Dockerfile

FROM python:3.9
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
ENV LANGUAGE=C.UTF-8
ENV PYTHONPATH "${PYTHONPATH}:/app/src"
ENV FLASK_DEBUG 1
ENV LOG_LEVEL "debug"

RUN pip install poetry

WORKDIR /app

COPY . /app

RUN poetry install --no-interaction --no-ansi

EXPOSE 5000
# CMD ["poetry", "run", "flask", "--app", "src/app.py", "run", "-h", "0.0.0.0"]
CMD ["poetry", "run", "gunicorn", "--bind", "0.0.0.0:5000", "app:create_app()"]

It seems your fly.toml wants to use a buildpack but you have a Dockerfile. Can you try to remove the [builder] section and try to deploy? INFO Preparing to run: /cnb/process/web as 1000 from your logs seem to indicate your buildpack is the one dictating things.

That did the trick! Thank you for your speedy response, @lubien. Legend!

1 Like

Anytime, glad it worked.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.