superfly / docs

Apache License 2.0
102 stars 1.06k forks source link

Machines docs use `flyio/fastify-functions` which confused me #157

Open simonw opened 2 years ago

simonw commented 2 years ago

I've been following the Machines tutorial. It suggested running an image using flyio/fastify-functions - I'm not entirely sure what that is, but https://hub.docker.com/r/flyio/fastify-functions says:

Example Fastify server with auto-shutdown on idle

At any rate, I found its behaviour confusing. I had more success following that tutorial by switching that out for https://hub.docker.com/r/nginxdemos/hello/

curl -i -X POST \
  -H "Authorization: Bearer ${FLY_API_TOKEN}" \
  -H "Content-Type: application/json" \
  "http://${FLY_API_HOSTNAME}/v1/apps/fly-machines-demo/machines" \
  -d '{
  "name": "my-first-nginx",
  "config": {
    "image": "nginxdemos/hello",
    "services": [
      {
        "ports": [
          {
            "port": 80,
            "handlers": [
              "http"
            ]
          }
        ],
        "protocol": "tcp",
        "internal_port": 80
      }
    ]
  }
}'

Running that in place of flyio/fastify-functions gave me a page on the IPv4 address I had allocated which showed me the NGINX debug page and demonstrated that everything was working correctly.

jsierles commented 2 years ago

What was the confusing behavior? That image just spits out some JSON, but the main reason we use it is its auto-idle behavior. An nginx image will stay up forever until you stop it. Of course, we could put this auto-idle proxy in front of nginx. Maybe this is a better idea.

simonw commented 2 years ago

That was the problem - the auto-idling meant that when I went to look at my list of machines it was in "stopped" state, despite me having recently launched it, which was a surprise.

I think the real problem is that the text didn't explain this was going to happen. Adding a paragraph explaining what's happening there (and how the fastify-functions container works) would have clarified things for me.

simonw commented 2 years ago

Did a bit more digging around this - understanding how the tired-proxy mechanism worked was really helpful: https://gist.github.com/simonw/dadf9d218e8cf4f6a84161de45092e3c

bendytree commented 2 years ago

I think it'd be helpful if we could see the source code for flyio/fastify-functions to understand how it idles itself. My initial thought was that we should exit the process with code 0, but maybe we're just supposed to unbind from the port? I've seen both as examples. Maybe both are ok?

bendytree commented 2 years ago

I found the fastify-functions source code but looks like the important part is actually in tired-proxy where they exit(0) to idle. Still a bit confused though because bfaas unbinds the server and has the exit command commented out.