https://github.com/fly-apps/hello-rust
Rust example app on Fly.io
https://github.com/fly-apps/hello-rust
Last synced: 7 months ago
JSON representation
Rust example app on Fly.io
- Host: GitHub
- URL: https://github.com/fly-apps/hello-rust
- Owner: fly-apps
- Created: 2021-04-07T11:45:07.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-01-18T23:42:02.000Z (over 2 years ago)
- Last Synced: 2025-01-17T18:54:39.665Z (over 1 year ago)
- Language: Dockerfile
- Size: 17.6 KB
- Stars: 69
- Watchers: 5
- Forks: 14
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Hello Rust!
This is an example app demonstrating how to deploy a Rust program on Fly.io
## Structure
### App
Warp-based "hello world" app, as simple as it can get.
#### Binding to all addresses
Noticed this line?
```rust
warp::serve(routes)
// ipv6 + ipv6 any addr
.run(([0, 0, 0, 0, 0, 0, 0, 0], 8080))
.await;
```
This listens to all addresses on both IPv4 and IPv6, on port 8080. It's important to do this because your app would otherwise need to know about the `172.19.0.0/16` IP it should bind to specifically. Binding to IPv6 is not required, but is likely a good idea going forward.
### fly.toml
A fairly standard `fly.toml` configuration, except for the `cmd` override:
```toml
[experimental]
cmd = "./hello" # should be the name of the binary you want to run
```
### Dockerfile
The most efficient way to create a Docker image for a Rust app is a simple Dockerfile.
Our `Dockerfile` is heavily commented, but here's a short rundown:
- Copy `Cargo.{toml,lock}` and build dependencies
- Copy whole project and `cargo install` it
-
#### .dockerignore
You definitely want to ignore `/target` since this can get pretty hefty, adding to the build context's size, and slow down builds significantly.
## Deploy
```
fly launch
```