As shown in in a Fly blog post, it is possible to scale to 0 with machines. In this blog post, tired-proxy is introduced to shut down the machine after a configurable amount of time with no requests. However, it could be improved a bit. Therefore, I forked the repository and added my two cents:
- Proper shut down of the server
- Ability to wait for the web server to come online before starting the proxy server. Previously, the first request to the machine would return a HTTP 502, except if the web server starts very fast.
- Logging that is easier to parse
You can find the repository with details here. Oh, and there is a docker image: tiesv/tired-proxy
Give it a try (in your container deployed to a machine):
./run-my-webserver & /tired-proxy --origin=http://localhost:3000 --wait-for-port=10
For me the application is useful, hopefully for you too!
Breaking changes compared to superfly/tired-proxy:
Some options have been renamed:
-
--host
=>--origin
-
--time
=>--idle-time
@fly staff: you are of course free to port these changes back into your version. That is what FOSS is all about