diff --git a/docs/ENV-VARS.md b/docs/ENV-VARS.md index e1037212..9206a40f 100644 --- a/docs/ENV-VARS.md +++ b/docs/ENV-VARS.md @@ -6,9 +6,7 @@ starting the app with `cargo run` or write them in a `.env` file to have automat Here are the variables that Plume uses: - `BASE_URL`: the domain name, or IP and port on which Plume is listening. It is used in all federation-related code. -- `DB_URL`: the URL of the PostgreSQL database, used by Plume (`postgres://plume:plume@localhost/plume` by default). -- `POSTGRES_USER`: if you just want to use a different PostgreSQL user name, and keep the rest of the default URL. -- `POSTGRES_PASSWORD`: same as `POSTGRES_USER`, but for the password. +- `DATABASE_URL`: the URL of the PostgreSQL database, used by Plume (`postgres://plume:plume@localhost/plume` by default with PostgreSQL, `plume.db` with SQlite). - `USE_HTTPS`: if it is `0`, federation and medias will be using HTTP by default (`1` by default). - `ROCKET_ADDRESS`: the adress on which Plume should listen (`0.0.0.0` by default). - `ROCKET_PORT`: the port on which Plume should listen ([`7878` by default](https://twitter.com/ag_dubs/status/852559264510070784)) diff --git a/docs/INSTALL.md b/docs/INSTALL.md index fcdd57d4..66a62534 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -133,6 +133,31 @@ export FEATURES=postgres export FEATURES=sqlite ``` +## Configuring Plume + +Before starting Plume, you'll need to create a configuration file, called `.env`. Here is a sample of what you should put inside. + +```bash +# The address of the database +# (replace USER, PASSWORD, PORT and DATABASE_NAME with your values) +# +# If you are using SQlite, use the path of the database file (`plume.db` for instance) +DATABASE_URL=postgres://USER:PASSWORD@IP:PORT/DATABASE_NAME + +# For PostgreSQL: migrations/postgres +# For SQlite: migrations/sqlite +MIGRATION_DIR=migrations/postgres + +# The domain on which your instance will be available +BASE_URL=plu.me + +# Secret key used for private cookies and CSRF protection +# You can generate one with `openssl rand -base64 32` +ROCKET_SECRET_KEY= +``` + +For more information about what you can put in your `.env`, see [the documentation about environment variables](ENV-VARS.md). + ## Running migrations Migrations are scripts used to update the database. They are run by a tool called Diesel, which can be installed with: @@ -144,11 +169,7 @@ cargo install diesel_cli --no-default-features --features $FEATURES --version '= To run the migrations, you can do: ```bash -# For a PostgreSQL database -diesel migration run --database-url postgres://USER:PASSWORD@IP:PORT/DATABASE_NAME - -# For a SQlite database -diesel migration run --database-url ./plume.sqlite3 +diesel migration run ``` Migrations should be run before using Plume or the `plm` CLI tool, and after each update. @@ -163,25 +184,6 @@ cargo install --no-default-features --features $FEATURES cargo install --no-default-features --features $FEATURES --path plume-cli ``` -Before starting Plume, you'll need to create a configuration file, called `.env`. Here is a sample of what you should put inside. - -```bash -# The address of the database -# (replace USER, PASSWORD, PORT and DATABASE_NAME with your values) -# -# If you are using SQlite, use the path of the database file -DB_URL=postgres://USER:PASSWORD@IP:PORT/DATABASE_NAME - -# The domain on which your instance will be available -BASE_URL=plu.me - -# Secret key used for private cookies and CSRF protection -# You can generate one with `openssl rand -base64 32` -ROCKET_SECRET_KEY= -``` - -For more information about what you can put in your `.env`, see [the documentation about environment variables](ENV-VARS.md). - After that, you'll need to setup your instance, and the admin's account. ``` @@ -224,8 +226,8 @@ docker-compose up -d postgres docker-compose run --rm plume diesel migration run # Setup your instance -docker-compose run --rm plume plume instance new -docker-compose run --rm plume plume users new --admin +docker-compose run --rm plume plm instance new +docker-compose run --rm plume plm users new --admin # Launch your instance for good docker-compose up -d @@ -489,8 +491,7 @@ exit 0 ## Caveats: - Pgbouncer is not supported yet (named transactions are used). -- Rust nightly is a moving target, dependancies can break and sometimes you need to check a few versions to find the one working (run `rustup override set nightly-2018-05-15` or `rustup override set nightly-2018-05-31` in the Plume directory if you have issues during the compilation) -- Rust nightly 2018-06-28 is known to be failing to compile diesel 1.3.2 +- Rust nightly is a moving target, dependancies can break and sometimes you need to check a few versions to find the one working (run `rustup override set nightly-2018-07-17` in the Plume directory if you have issues during the compilation) ## Acknowledgements diff --git a/docs/UPDATE.md b/docs/UPDATE.md index 7c387182..4826e8a6 100644 --- a/docs/UPDATE.md +++ b/docs/UPDATE.md @@ -7,7 +7,7 @@ git pull origin master cargo install --force && cargo install --path plume-cli --force # Run the migrations -diesel migration run --database-url 'YOUR_DB_URL' +diesel migration run # If you are using sysvinit sudo service plume restart diff --git a/docs/docker.sample.env b/docs/docker.sample.env index 33ae4f49..b9514150 100644 --- a/docs/docker.sample.env +++ b/docs/docker.sample.env @@ -3,10 +3,8 @@ BASE_URL=yourdomain.com ROCKET_SECRET_KEY=randomstringhere # you can safely leave those defaults -POSTGRES_USER=plume -POSTGRES_PASSWORD=plume -DB_URL=postgres://plume:plume@postgres:5432/plume DATABASE_URL=postgres://plume:plume@postgres:5432/plume +MIGRATION_DIR=postgres USE_HTTPS=1 ROCKET_ADDRESS=0.0.0.0 ROCKET_PORT=7878 diff --git a/plume-cli/src/main.rs b/plume-cli/src/main.rs index 8243f744..d44b4c13 100644 --- a/plume-cli/src/main.rs +++ b/plume-cli/src/main.rs @@ -7,7 +7,7 @@ extern crate rpassword; use clap::App; use diesel::Connection; use std::io::{self, prelude::*}; -use plume_models::{DB_URL, Connection as Conn}; +use plume_models::{DATABASE_URL, Connection as Conn}; mod instance; mod users; @@ -22,7 +22,7 @@ fn main() { let matches = app.clone().get_matches(); dotenv::dotenv().ok(); - let conn = Conn::establish(DB_URL.as_str()); + let conn = Conn::establish(DATABASE_URL.as_str()); match matches.subcommand() { ("instance", Some(args)) => instance::run(args, &conn.expect("Couldn't connect to the database.")), diff --git a/plume-models/src/lib.rs b/plume-models/src/lib.rs index 775c8edc..273674ff 100644 --- a/plume-models/src/lib.rs +++ b/plume-models/src/lib.rs @@ -191,12 +191,19 @@ lazy_static! { pub static ref BASE_URL: String = env::var("BASE_URL") .unwrap_or(format!("127.0.0.1:{}", env::var("ROCKET_PORT").unwrap_or(String::from("8000")))); - pub static ref DB_URL: String = env::var("DB_URL") - .unwrap_or(format!("postgres://plume:plume@localhost/{}", env::var("DB_NAME").unwrap_or(String::from("plume")))); - pub static ref USE_HTTPS: bool = env::var("USE_HTTPS").map(|val| val == "1").unwrap_or(true); } +#[cfg(all(feature = "postgres", not(feature = "sqlite")))] +lazy_static! { + pub static ref DATABASE_URL: String = env::var("DATABASE_URL").unwrap_or(String::from("postgres://plume:plume@localhost/plume")); +} + +#[cfg(all(feature = "sqlite", not(feature = "postgres")))] +lazy_static! { + pub static ref DATABASE_URL: String = env::var("DATABASE_URL").unwrap_or(String::from("plume.sqlite")); +} + pub fn ap_url(url: String) -> String { let scheme = if *USE_HTTPS { "https" diff --git a/src/main.rs b/src/main.rs index 802b7cf4..41b9a6cd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,7 @@ use diesel::r2d2::ConnectionManager; use rocket::State; use rocket_contrib::Template; use rocket_csrf::CsrfFairingBuilder; -use plume_models::{DB_URL, Connection, db_conn::DbPool}; +use plume_models::{DATABASE_URL, Connection, db_conn::DbPool}; use workerpool::{Pool, thunk::ThunkWorker}; mod api; @@ -51,7 +51,7 @@ type Worker<'a> = State<'a, Pool>>; fn init_pool() -> Option { dotenv::dotenv().ok(); - let manager = ConnectionManager::::new(DB_URL.as_str()); + let manager = ConnectionManager::::new(DATABASE_URL.as_str()); DbPool::new(manager).ok() }