diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0822575 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +fly.toml +.git/ +target/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5421087 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef +WORKDIR /app + +FROM chef AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef AS builder +COPY --from=planner /app/recipe.json recipe.json +# Build dependencies - this is the caching Docker layer! +RUN cargo chef cook --release --recipe-path recipe.json +# Build application +COPY . . +RUN cargo build --release --bin beacon + +# We do not need the Rust toolchain to run the binary! +FROM debian:bookworm-slim AS runtime +WORKDIR /app +COPY --from=builder /app/target/release/beacon /app +COPY --from=builder /app/static /app/static +ENTRYPOINT ["/app/beacon"] diff --git a/README.md b/README.md index ae3105f..f889efd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ This is a small website providing a tracker for big fish in Final Fantasy XIV. -It's built with [axum](https://lib.rs/axum), [maud](https://maud.lambda.xyz), and Postgres as a datastore. +It's built with [axum](https://lib.rs/axum), [maud](https://maud.lambda.xyz), and Postgres as a datastore, and a +little tasteful interactivity here and there using [htmx](https://htmx.org). The data for fish is based on the data used in [Carbuncle Plushy's Fish Tracker](https://ff14fish.carbuncleplushy.com). ## Todo diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..46d7e88 --- /dev/null +++ b/fly.toml @@ -0,0 +1,25 @@ +# fly.toml app configuration file generated for beacon-prod on 2025-02-06T15:36:51+01:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = 'beacon-prod' +primary_region = 'ams' + +[build] + +[env] +PORT = '8080' + +[http_service] +internal_port = 3000 +force_https = true +auto_stop_machines = 'stop' +auto_start_machines = true +min_machines_running = 1 +processes = ['app'] + +[[vm]] +memory = '1gb' +cpu_kind = 'shared' +cpus = 1 diff --git a/src/db.rs b/src/db.rs index af6a605..51bbe8b 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,11 +1,13 @@ -use sqlx::{Pool, Postgres}; +use sqlx::{prelude::FromRow, Pool, Postgres}; use crate::AppError; +#[derive(FromRow)] pub struct Account { pub account_id: String, } +#[derive(FromRow)] pub struct CaughtFish { pub id: Option, pub account_id: String, @@ -13,14 +15,16 @@ pub struct CaughtFish { } pub async fn insert_account(id: &str, pool: &Pool) -> Result<(), AppError> { - sqlx::query!("INSERT INTO accounts (account_id) VALUES ($1)", id) + sqlx::query("INSERT INTO accounts (account_id) VALUES ($1)") + .bind(id) .execute(pool) .await?; Ok(()) } pub async fn get_account(id: &str, pool: &Pool) -> Result { - let results = sqlx::query_as!(Account, "SELECT * FROM accounts WHERE account_id = $1", id) + let results: Vec = sqlx::query_as("SELECT * FROM accounts WHERE account_id = $1") + .bind(id) .fetch_all(pool) .await?; @@ -36,13 +40,13 @@ pub async fn insert_caught_fish( fish_id: &i32, pool: &Pool, ) -> Result<(), AppError> { - sqlx::query!( + sqlx::query( " INSERT INTO caught_fish (account_id, fish_id) VALUES ($1, $2) ", - acc_id, - fish_id ) + .bind(acc_id) + .bind(fish_id) .execute(pool) .await?; @@ -50,13 +54,11 @@ pub async fn insert_caught_fish( } pub async fn get_caught_fish(acc_id: &str, pool: &Pool) -> Result, AppError> { - let results = sqlx::query_as!( - CaughtFish, - "SELECT * FROM caught_fish WHERE account_id = $1", - acc_id - ) - .fetch_all(pool) - .await?; + let results: Vec = + sqlx::query_as("SELECT * FROM caught_fish WHERE account_id = $1") + .bind(acc_id) + .fetch_all(pool) + .await?; Ok(results.iter().map(|cf| cf.fish_id).collect()) }