Update env handling and docs.
This commit is contained in:
parent
eb3fe1a8a7
commit
fdb2e1587b
5 changed files with 49 additions and 7 deletions
|
@ -3,6 +3,7 @@ ADMIN_TOKEN=
|
||||||
STRIPE_TOKEN=
|
STRIPE_TOKEN=
|
||||||
FORGEJO_URL=http://localhost:3000
|
FORGEJO_URL=http://localhost:3000
|
||||||
DATABASE_URL=sqlite://queenie.db
|
DATABASE_URL=sqlite://queenie.db
|
||||||
|
DATABASE_FILE=file://queenie.db
|
||||||
MONTHLY_LINK=
|
MONTHLY_LINK=
|
||||||
ANNUAL_LINK=
|
ANNUAL_LINK=
|
||||||
LISTENING_ADDR=127.0.0.1
|
LISTENING_ADDR=127.0.0.1
|
||||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,4 +1,4 @@
|
||||||
/target
|
/target
|
||||||
.env
|
*.env
|
||||||
*.db
|
*.db
|
||||||
*.db-*
|
*.db-*
|
||||||
|
|
|
@ -19,9 +19,12 @@ sqlx db create ; sqlx migrate run
|
||||||
Run the server for development:
|
Run the server for development:
|
||||||
|
|
||||||
```
|
```
|
||||||
cargo run
|
cargo run -- -e .env
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The `-e` (or `--env`) option tells Queenie where to find its environment configuration file; the
|
||||||
|
default is `/etc/forgejo/queenie.env`.
|
||||||
|
|
||||||
The assets used in Queen come from forgejo,
|
The assets used in Queen come from forgejo,
|
||||||
so you can use a local Caddyfile to serve both forgejo and `queen`
|
so you can use a local Caddyfile to serve both forgejo and `queen`
|
||||||
(assuming that forgejo is running on localhost:3000):
|
(assuming that forgejo is running on localhost:3000):
|
||||||
|
@ -43,3 +46,7 @@ Run caddy with:
|
||||||
```
|
```
|
||||||
caddy run --config Caddyfile
|
caddy run --config Caddyfile
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Use in production
|
||||||
|
|
||||||
|
There's a sample systemd unit file, `queenie.service`.
|
||||||
|
|
16
queenie.service
Normal file
16
queenie.service
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Queenie guards the kitten den.
|
||||||
|
After=syslog.target
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=git
|
||||||
|
Group=git
|
||||||
|
WorkingDirectory=/var/lib/forgejo/
|
||||||
|
ExecStart=/var/lib/forgejo/bin/queenie --env /etc/forgejo/queenie.env
|
||||||
|
Restart=always
|
||||||
|
Environment=USER=git HOME=/home/git
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
28
src/main.rs
28
src/main.rs
|
@ -30,8 +30,6 @@ async fn main() {
|
||||||
|
|
||||||
let pool = db().await;
|
let pool = db().await;
|
||||||
|
|
||||||
sqlx::migrate!().run(&pool).await.unwrap();
|
|
||||||
|
|
||||||
// the core application, defining the routes and handlers
|
// the core application, defining the routes and handlers
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.stripped_clone("/signup/", get(get_signup).post(post_signup))
|
.stripped_clone("/signup/", get(get_signup).post(post_signup))
|
||||||
|
@ -52,8 +50,14 @@ async fn main() {
|
||||||
// li'l helpers
|
// li'l helpers
|
||||||
//-************************************************************************
|
//-************************************************************************
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
|
#[clap(version, about)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[clap(long, short)]
|
#[clap(
|
||||||
|
long,
|
||||||
|
short,
|
||||||
|
help = "Path to Queenie's environment config file",
|
||||||
|
default_value = "/etc/forgejo/queenie.env"
|
||||||
|
)]
|
||||||
pub env: OsString,
|
pub env: OsString,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,13 +73,27 @@ fn init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn db() -> SqlitePool {
|
async fn db() -> SqlitePool {
|
||||||
//let dbfile = std::env::var("DATABASE_URL").unwrap();
|
let dbfile = std::env::var("DATABASE_FILE").unwrap();
|
||||||
let opts = SqliteConnectOptions::new()
|
let opts = SqliteConnectOptions::new()
|
||||||
.foreign_keys(true)
|
.foreign_keys(true)
|
||||||
.create_if_missing(true)
|
.create_if_missing(true)
|
||||||
.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal)
|
.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal)
|
||||||
|
.filename(&dbfile)
|
||||||
.optimize_on_close(true, None);
|
.optimize_on_close(true, None);
|
||||||
SqlitePoolOptions::new().connect_with(opts).await.unwrap()
|
let pool = SqlitePoolOptions::new()
|
||||||
|
.connect_with(opts.clone())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
sqlx::migrate!().run(&pool).await.unwrap();
|
||||||
|
|
||||||
|
let count = sqlx::query_scalar!("select count(*) from customers")
|
||||||
|
.fetch_one(&pool)
|
||||||
|
.await
|
||||||
|
.expect("could not get customer count from DB");
|
||||||
|
log::info!("Connected to DB, found {count} customers.");
|
||||||
|
|
||||||
|
pool
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn mklistener() -> TcpListener {
|
async fn mklistener() -> TcpListener {
|
||||||
|
|
Loading…
Reference in a new issue