add deployment configuration
This commit is contained in:
parent
523d965c09
commit
56a0cc8838
5 changed files with 66 additions and 14 deletions
3
.dockerignore
Normal file
3
.dockerignore
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fly.toml
|
||||||
|
.git/
|
||||||
|
target/
|
21
Dockerfile
Normal file
21
Dockerfile
Normal file
|
@ -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"]
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
This is a small website providing a tracker for big fish in Final Fantasy XIV.
|
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).
|
The data for fish is based on the data used in [Carbuncle Plushy's Fish Tracker](https://ff14fish.carbuncleplushy.com).
|
||||||
|
|
||||||
## Todo
|
## Todo
|
||||||
|
|
25
fly.toml
Normal file
25
fly.toml
Normal file
|
@ -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
|
24
src/db.rs
24
src/db.rs
|
@ -1,11 +1,13 @@
|
||||||
use sqlx::{Pool, Postgres};
|
use sqlx::{prelude::FromRow, Pool, Postgres};
|
||||||
|
|
||||||
use crate::AppError;
|
use crate::AppError;
|
||||||
|
|
||||||
|
#[derive(FromRow)]
|
||||||
pub struct Account {
|
pub struct Account {
|
||||||
pub account_id: String,
|
pub account_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(FromRow)]
|
||||||
pub struct CaughtFish {
|
pub struct CaughtFish {
|
||||||
pub id: Option<i32>,
|
pub id: Option<i32>,
|
||||||
pub account_id: String,
|
pub account_id: String,
|
||||||
|
@ -13,14 +15,16 @@ pub struct CaughtFish {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn insert_account(id: &str, pool: &Pool<Postgres>) -> Result<(), AppError> {
|
pub async fn insert_account(id: &str, pool: &Pool<Postgres>) -> 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)
|
.execute(pool)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_account(id: &str, pool: &Pool<Postgres>) -> Result<bool, AppError> {
|
pub async fn get_account(id: &str, pool: &Pool<Postgres>) -> Result<bool, AppError> {
|
||||||
let results = sqlx::query_as!(Account, "SELECT * FROM accounts WHERE account_id = $1", id)
|
let results: Vec<Account> = sqlx::query_as("SELECT * FROM accounts WHERE account_id = $1")
|
||||||
|
.bind(id)
|
||||||
.fetch_all(pool)
|
.fetch_all(pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -36,13 +40,13 @@ pub async fn insert_caught_fish(
|
||||||
fish_id: &i32,
|
fish_id: &i32,
|
||||||
pool: &Pool<Postgres>,
|
pool: &Pool<Postgres>,
|
||||||
) -> Result<(), AppError> {
|
) -> Result<(), AppError> {
|
||||||
sqlx::query!(
|
sqlx::query(
|
||||||
"
|
"
|
||||||
INSERT INTO caught_fish (account_id, fish_id) VALUES ($1, $2)
|
INSERT INTO caught_fish (account_id, fish_id) VALUES ($1, $2)
|
||||||
",
|
",
|
||||||
acc_id,
|
|
||||||
fish_id
|
|
||||||
)
|
)
|
||||||
|
.bind(acc_id)
|
||||||
|
.bind(fish_id)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -50,11 +54,9 @@ pub async fn insert_caught_fish(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_caught_fish(acc_id: &str, pool: &Pool<Postgres>) -> Result<Vec<i32>, AppError> {
|
pub async fn get_caught_fish(acc_id: &str, pool: &Pool<Postgres>) -> Result<Vec<i32>, AppError> {
|
||||||
let results = sqlx::query_as!(
|
let results: Vec<CaughtFish> =
|
||||||
CaughtFish,
|
sqlx::query_as("SELECT * FROM caught_fish WHERE account_id = $1")
|
||||||
"SELECT * FROM caught_fish WHERE account_id = $1",
|
.bind(acc_id)
|
||||||
acc_id
|
|
||||||
)
|
|
||||||
.fetch_all(pool)
|
.fetch_all(pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue