Project not respecting fly.toml

Hello. I have a fly.toml with this configuration:

app = 'company-backend'
primary_region = 'mia'

[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = 'stop'
  auto_start_machines = true
  min_machines_running = 1
  processes = ['app']

[[vm]]
  memory = '1gb'
  cpu_kind = 'shared'
  cpus = 1

[build]
  dockerfile = "Dockerfile"

[env]
  PORT = "8080"

However, I’m getting 2 machines in the SCL region instead of MIA, and my project is scaling to zero. So it always is suspended and with both machines stopped, unless I make a request to the server and one of the machine gets temporarily activated for a short time, then goes back into suspension.

What’s up with this?
Thanks in advance

Assuming that there isn’t an issue on Fly.io, did you accidentally create your app in scl and then updated your config to mia? If so, fly deploy doesn’t look at the region, it only configures that at launch (initial) time. fly scale count 0 to clear them, then go back up to 2. min_machines_running only applies to the original primary region.

I used fly launch for creating the project with the fly.toml already created and configured like I showed. I tried fly scale count 0 and setting it back to 2 but that didn’t work. I’m still getting the new machines on SCL, even though my config is still in MIA.

I’m wondering if your new app is actually using the fly.toml above or if the launch scanner is detecting your app and creating a new fly.toml file with the primary region set to your closest region?

When you ran fly launch did you note the region that was output in the suggested settings for the app?

You can also specify the region when you run that scale command using the --region mia option. Just note if you still have machines in the scl region, you’ll want to specify that region when you scale it to 0.

I think this might be it. Why is this happening and how can I fix this?

That would fix the region issue manually, but I want to make fly respect the fly.toml file I have, since the region is only one of the issues (I want also to respect the other configs in fly.toml, like min_machines_running=1)

You need to make sure the fly.toml file with the settings you want is at the top level of your project directory where you run your commands.

If you then scale to zero (fly scale count 0)and then redeploy with fly deploy, the deploy (and any subsequent deploys) should respect the fly.toml settings.

Did that with fly.toml at the root of my project and still, no luck. Still deploying at a different region and probably not respecting any other configs inside my fly.toml

My project looks something like this:

/project-directory
│
├── my_backend/
│   └── app.py
│
├── .env
├── Dockerfile
├── fly.toml
├── poetry.lock
└── pyproject.toml

My Dockerfile is clearly being respected since the deployment is successful and functional. Here is my dockerfile:

FROM python:3.11.9-bookworm AS builder

ENV PYTHONUNBUFFERED=1 \

PYTHONDONTWRITEBYTECODE=1

RUN pip install poetry && poetry config virtualenvs.in-project true

WORKDIR /app

COPY pyproject.toml poetry.lock ./

RUN poetry install

# Runtime stage

FROM python:3.11.9-slim-bookworm

WORKDIR /app

# Install python-dotenv

RUN pip install python-dotenv

COPY --from=builder /app .

COPY my_backend/ ./my_backend/

COPY .env .env

CMD ["/app/.venv/bin/python", "my_backend/app.py", "--host=0.0.0.0", "--port=8080"]

I can’t wrap my head around why it’s not respecting the fly.toml configs

is this only happening for mia? Can you try a different primary_region to see if that repros

Tried Spain (Madrid) and Mexico. Nothing.

It’s just fly not respecting the configs inside my fly.toml

I took at a peek at your fly.toml from our side and it’s not the same file you posted above. It looks like a default file, with default settings, and the region set to “scl”.

I’m not sure why!

Could you try making a copy of your project and just running fly launch in it? You can say y to tweak settings and change the region to mia before deploy. Once it’s deployed, open the new fly.toml file and edit min_machines_running to 1, save it, then run fly deploy. This should result in the app behaviour and settings you want.

this solved my issue, so i was probably making a very DUMB mistake. I’m sorry and thank you.

1 Like

I’m going to do some testing of what happens when you use fly launch with an existing fly.toml and see if we can improve things at all. It should be an acceptable workflow and it might not be clear enough what’s happening. Glad your app is working as it should now!

I tried that a few weeks ago and it overwrote and added some configs on the existing fly.toml

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