fly.io stuff

This commit is contained in:
uh wot 2022-08-16 17:59:09 +02:00
parent e72779c338
commit ae75a24129
Signed by: uhwot
GPG Key ID: CB2454984587B781
4 changed files with 68 additions and 1 deletions

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
/target

31
Dockerfile Normal file
View File

@ -0,0 +1,31 @@
FROM rust:latest as builder
# Make a fake Rust app to keep a cached layer of compiled crates
RUN USER=root cargo new app
WORKDIR /usr/src/app
COPY Cargo.toml Cargo.lock ./
# Needs at least a main.rs file with a main function
RUN mkdir src && echo "fn main(){}" > src/main.rs
# Will build all dependent crates in release mode
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/src/app/target \
cargo build --release
# Copy the rest
COPY . .
# Build (install) the actual binaries
RUN cargo install --path .
# Runtime image
FROM debian:bullseye-slim
# Run as "app" user
RUN useradd -ms /bin/bash app
USER app
WORKDIR /app
# Get compiled binaries from builder's cargo install directory
COPY --from=builder /usr/local/cargo/bin/dzmedia /app/dzmedia
# No CMD or ENTRYPOINT, see fly.toml with `cmd` override.

35
fly.toml Normal file
View File

@ -0,0 +1,35 @@
app = "dzmedia"
kill_signal = "SIGINT"
kill_timeout = 5
[experimental]
# required because we can't infer your binary's name
cmd = "./dzmedia"
[env]
PORT = "8080"
RUST_LOG = "actix_web=info"
[[services]]
internal_port = 8080
protocol = "tcp"
[services.concurrency]
hard_limit = 25
soft_limit = 20
[[services.ports]]
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
port = "8080"
restart_limit = 6
timeout = "2s"

View File

@ -76,7 +76,7 @@ async fn main() -> std::io::Result<()> {
let port = std::env::var("PORT").unwrap_or("8000".to_string());
let port: u16 = port.parse().unwrap_or(8000);
let bind_addr = format!("0.0.0.0:{}", port);
let bind_addr = format!("[::]:{}", port);
println!("Listening on {bind_addr}");
let client = web::Data::new(