Help me out with networking in machines API

I want to do following things.

Everytime I need to execute a task, I will spawn an app, spawn a single machine behind that app to run my mini-server.

I want the machine or app to be publicly accessibly by a address or domain name so I can reach out to my server to accomplish my task. (Preferably SSL)

I want to spawn different apps everytime because I want to maintain separation every time and no data should cross between both the apps/machines.

I can do some of this using command line. I want do this using API only (be it creating app or creating machine or assigning the public IP and domain name)

Eventually, I want to use my own wildcard domain name to randomly assign each app a domain name like random.composio.dev.

How can I accomplish this? The networking component in machines API seems unjustly complicated and I can’t figure this out.

Any other suggestions will also help.

Thanks.

One way to do this is with two apps. The first has an exposed http service, exposed via SSL, and runs nginx. The second runs your application, one per machine.

Your nginx configuration would look something like the following:

server {
  server_name sub1.example.com;
  location / {
    add_header Fly-Replay instance=328739ef5e5985
    return 307;
  }
}
server {
  server_name sub2.example.com;
  location / {
    add_header Fly-Replay instance=148e5267a1d128
    return 307;
  }
}

Notes:

  • Run nginx and your app on the same port as fly-replay doesn’t allow you to modify the port.
  • Fly-replay is limited to 1MB requests, so is not suitable for file uploads (but actually is fine for websockets). If you need file uploads, set up an nginx reverse proxy, perhaps only on specific paths.
  • When you configuration changes, write out the new configuration, and reload nginx.

I run a variation of this myself, the key difference being that I run one fly app and every machine runs nginx and will replay or reverse proxy requests that are misrouted. If you go this way, you can take advantage of auto_stop_machines = true.

This works great. I like the idea of 2 apps. Can you tell me how to do this via APIs?

APIs are for starting and stopping machines. What those machine do is controlled by Dockerfiles. In this case, the Dockerfile can be as little as two lines, which is just enough to start nginx with your config file:

Thanks but I plan to create a new app dynamically (the one behind the main app). How do I do that with the right networking settings? I can setup docker & nginx which is not an issue but I still don’t know how to call the API to make an app or machine with the right networking settings? can you tell me how to do that or give me some example code somewhere?

which networking settings are you referring to?

If you Create a Machine, the response will contain an id, as well as a private-ip.

You can use Fly.io .internal addresses to get a list of machines, or to connect to a machine given its machine id.

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