mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-29 00:42:19 +00:00
Merge pull request #1552 from LemmyNet/feature/1550-optional-config-values
Make some of the database config values optional (fixes #1550)
This commit is contained in:
commit
727fa610d4
|
@ -21,15 +21,20 @@ impl Default for Settings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(in crate::settings) static DEFAULT_DATABASE_USER: &str = "lemmy";
|
||||||
|
pub(in crate::settings) static DEFAULT_DATABASE_PORT: i32 = 5432;
|
||||||
|
pub(in crate::settings) static DEFAULT_DATABASE_DB: &str = "lemmy";
|
||||||
|
pub static DEFAULT_DATABASE_POOL_SIZE: u32 = 5;
|
||||||
|
|
||||||
impl Default for DatabaseConfig {
|
impl Default for DatabaseConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
user: "lemmy".into(),
|
user: Some(DEFAULT_DATABASE_USER.to_string()),
|
||||||
password: "password".into(),
|
password: "password".into(),
|
||||||
host: "localhost".into(),
|
host: "localhost".into(),
|
||||||
port: 5432,
|
port: Some(DEFAULT_DATABASE_PORT),
|
||||||
database: "lemmy".into(),
|
database: Some(DEFAULT_DATABASE_DB.to_string()),
|
||||||
pool_size: 5,
|
pool_size: Some(DEFAULT_DATABASE_POOL_SIZE),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
location_info,
|
location_info,
|
||||||
settings::structs::{
|
settings::{
|
||||||
|
defaults::{DEFAULT_DATABASE_DB, DEFAULT_DATABASE_PORT, DEFAULT_DATABASE_USER},
|
||||||
|
structs::{
|
||||||
CaptchaConfig,
|
CaptchaConfig,
|
||||||
DatabaseConfig,
|
DatabaseConfig,
|
||||||
EmailConfig,
|
EmailConfig,
|
||||||
|
@ -9,6 +11,7 @@ use crate::{
|
||||||
Settings,
|
Settings,
|
||||||
SetupConfig,
|
SetupConfig,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
LemmyError,
|
LemmyError,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Context};
|
use anyhow::{anyhow, Context};
|
||||||
|
@ -16,7 +19,7 @@ use deser_hjson::from_str;
|
||||||
use merge::Merge;
|
use merge::Merge;
|
||||||
use std::{env, fs, io::Error, net::IpAddr, sync::RwLock};
|
use std::{env, fs, io::Error, net::IpAddr, sync::RwLock};
|
||||||
|
|
||||||
pub(crate) mod defaults;
|
pub mod defaults;
|
||||||
pub mod structs;
|
pub mod structs;
|
||||||
|
|
||||||
static CONFIG_FILE: &str = "config/config.hjson";
|
static CONFIG_FILE: &str = "config/config.hjson";
|
||||||
|
@ -60,7 +63,15 @@ impl Settings {
|
||||||
let conf = self.database();
|
let conf = self.database();
|
||||||
format!(
|
format!(
|
||||||
"postgres://{}:{}@{}:{}/{}",
|
"postgres://{}:{}@{}:{}/{}",
|
||||||
conf.user, conf.password, conf.host, conf.port, conf.database,
|
conf
|
||||||
|
.user
|
||||||
|
.unwrap_or_else(|| DEFAULT_DATABASE_USER.to_string()),
|
||||||
|
conf.password,
|
||||||
|
conf.host,
|
||||||
|
conf.port.unwrap_or(DEFAULT_DATABASE_PORT),
|
||||||
|
conf
|
||||||
|
.database
|
||||||
|
.unwrap_or_else(|| DEFAULT_DATABASE_DB.to_string()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,12 @@ pub struct CaptchaConfig {
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
pub struct DatabaseConfig {
|
pub struct DatabaseConfig {
|
||||||
pub user: String,
|
pub user: Option<String>,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
pub host: String,
|
pub host: String,
|
||||||
pub port: i32,
|
pub port: Option<i32>,
|
||||||
pub database: String,
|
pub database: Option<String>,
|
||||||
pub pool_size: u32,
|
pub pool_size: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
|
|
|
@ -8,4 +8,4 @@ set -e
|
||||||
mkdir -p volumes/pictrs
|
mkdir -p volumes/pictrs
|
||||||
sudo chown -R 991:991 volumes/pictrs
|
sudo chown -R 991:991 volumes/pictrs
|
||||||
sudo docker build ../../ --file ../dev/volume_mount.dockerfile -t lemmy-dev:latest
|
sudo docker build ../../ --file ../dev/volume_mount.dockerfile -t lemmy-dev:latest
|
||||||
sudo docker-compose up -d
|
sudo docker-compose up
|
||||||
|
|
|
@ -24,7 +24,6 @@ RUN apt-get update -y
|
||||||
RUN apt-get install -y libpq-dev
|
RUN apt-get install -y libpq-dev
|
||||||
|
|
||||||
# Copy resources
|
# Copy resources
|
||||||
COPY config/defaults.hjson /config/defaults.hjson
|
|
||||||
COPY --from=rust /app/lemmy_server /app/lemmy
|
COPY --from=rust /app/lemmy_server /app/lemmy
|
||||||
|
|
||||||
EXPOSE 8536
|
EXPOSE 8536
|
||||||
|
|
|
@ -16,7 +16,7 @@ use lemmy_routes::{feeds, images, nodeinfo, webfinger};
|
||||||
use lemmy_server::{api_routes, code_migrations::run_advanced_migrations, scheduled_tasks};
|
use lemmy_server::{api_routes, code_migrations::run_advanced_migrations, scheduled_tasks};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
rate_limit::{rate_limiter::RateLimiter, RateLimit},
|
rate_limit::{rate_limiter::RateLimiter, RateLimit},
|
||||||
settings::structs::Settings,
|
settings::{defaults::DEFAULT_DATABASE_POOL_SIZE, structs::Settings},
|
||||||
LemmyError,
|
LemmyError,
|
||||||
};
|
};
|
||||||
use lemmy_websocket::{chat_server::ChatServer, LemmyContext};
|
use lemmy_websocket::{chat_server::ChatServer, LemmyContext};
|
||||||
|
@ -38,7 +38,12 @@ async fn main() -> Result<(), LemmyError> {
|
||||||
};
|
};
|
||||||
let manager = ConnectionManager::<PgConnection>::new(&db_url);
|
let manager = ConnectionManager::<PgConnection>::new(&db_url);
|
||||||
let pool = Pool::builder()
|
let pool = Pool::builder()
|
||||||
.max_size(settings.database().pool_size)
|
.max_size(
|
||||||
|
settings
|
||||||
|
.database()
|
||||||
|
.pool_size
|
||||||
|
.unwrap_or(DEFAULT_DATABASE_POOL_SIZE),
|
||||||
|
)
|
||||||
.build(manager)
|
.build(manager)
|
||||||
.unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
|
.unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue