Fly.io
Fly.io has robust WebSocket support and can deploy your app to a data center that is close to your users. They have very attractive pricing with a generous free tier which allows you to host up to 3 applications for free.
To get started with Fly install flyctl and then authenticate:
flyctl auth login
To deploy the app with flyctl
you have to add the following 3 files into the folder with your Python app.
Create requirements.txt
with a list of application dependencies. At minimum it should contain flet
module:
flet
Create fly.toml
describing Fly application:
app = "<your-app-name>"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []
[env]
FLET_SERVER_PORT = "8080"
[experimental]
allowed_public_ports = []
auto_rollback = true
[[services]]
http_checks = []
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
Replace <your-app-name>
with desired application name which will be also used in application URL, such as https://<your-app-name>.fly.dev
.
Note we are setting the value of FLET_SERVER_PORT
environment variable to 8080
which is an internal TCP port Flet web app is going to run on.
Create Dockerfile
containing the commands to build your application container:
FROM python:3-alpine
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8080
CMD ["python", "./main.py"]
main.py
is a file with your Python program.
Fly.io deploys every app as a Docker container, but a great thing about Fly is that it provides a free remote Docker builder, so you don't need Docker installed on your machine.
Next, switch command line to a folder with your app and run the following command to create and initialize a new Fly app:
flyctl apps create --name <your-app-name>
Deploy the app by running:
flyctl deploy
That's it! Open your app in the browser by running:
flyctl apps open