From a7d0a19cabfd5e1ce132be0c1bd1f1409a720aca Mon Sep 17 00:00:00 2001 From: maddiebaka Date: Mon, 7 Aug 2023 22:50:26 -0400 Subject: [PATCH 1/5] Fix compiler warnings in src/lib.rs --- src/lib.rs | 81 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dd3b1eac..2eb6c6a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ use std::env; use anyhow::{Context, Result}; use clap::Parser; use clap_verbosity_flag::Verbosity; -use config::{Config, ConfigError, Environment}; +use config::{Config, Environment, File, FileFormat}; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] @@ -19,56 +19,69 @@ pub struct Args { pub fn configure(parsed_args: Args) -> Result { // Set defaults - let mut config = Config::default(); - config - .set_default::<&str>("cfg_file", concat!(env!("CARGO_PKG_NAME"), ".toml")) + let mut builder = Config::builder(); + builder = builder + .set_default("cfg_file", concat!(env!("CARGO_PKG_NAME"), ".toml")) .context(ErrorKind::ConfigImmutable)?; - config - .set_default::<&str>("Log.file", "_CONSOLE_") + builder = builder + .set_default("Log.file", "_CONSOLE_") .context(ErrorKind::ConfigImmutable)?; - config - .set_default::<&str>("Web.address", "127.0.0.1") + builder = builder + .set_default("Web.address", "127.0.0.1") .context(ErrorKind::ConfigImmutable)?; - config + builder = builder .set_default("Web.port", 7878) .context(ErrorKind::ConfigImmutable)?; // Determine config file - if let Ok(config_file) = env::var("AARDWOLF_CONFIG") { - config - .set("cfg_file", config_file) - .context(ErrorKind::ConfigImmutable)?; - } + let config_file = env::var("AARDWOLF_CONFIG").unwrap(); + builder = builder + .set_override("cfg_file", config_file.clone()) + .context(ErrorKind::ConfigImmutable)?; - if let Some(config_path) = parsed_args.config { - config - .set("cfg_file", config_path.to_str()) + builder = builder.add_source(File::new(&config_file, FileFormat::Json)); // Or whatever format + + let config_path = parsed_args.config.unwrap(); + builder = builder + .set_override("cfg_file", config_path.to_str()) .context(ErrorKind::ConfigImmutable)?; + //} + + // Apply environmenet variable overrides + let env_vars = Environment::with_prefix("AARDWOLF") + .separator("_") + .ignore_empty(true); + builder = builder.add_source(env_vars); +// + let log_path = parsed_args.log.unwrap(); + builder = builder + .set_override("Log.file", log_path.to_str()) + .context(ErrorKind::ConfigImmutable)?; + + //Err(ErrorKind::ConfigImmutable.into()) + + match builder.build() { + Ok(config) => { + env::set_var("DATABASE_URL", db_conn_string(&config)?); + return Ok(config) + }, + Err(e) => { + // Throw an error + return Err(e.into()); + } } // Merge config file and apply overrides - let config_file_string = config - .get_string("cfg_file") - .context(ErrorKind::ConfigMissingKeys)?; - let config_file = config::File::with_name(&config_file_string); - config.merge(config_file).context(ErrorKind::ConfigImmutable)?; + //let config_file_string = config + // .get_string("cfg_file") + // .context(ErrorKind::ConfigMissingKeys)?; + //let config_file = config::File::with_name(&config_file_string); + //config.merge(config_file).context(ErrorKind::ConfigImmutable)?; // Apply environment variable overrides - let env_vars = Environment::with_prefix("AARDWOLF") - .separator("_") - .ignore_empty(true); - config.merge(env_vars).context(ErrorKind::ConfigImmutable)?; // Remove the need for a .env file to avoid defining env vars twice. - env::set_var("DATABASE_URL", db_conn_string(&config)?); - - if let Some(log_path) = parsed_args.log { - config - .set("Log.file", log_path.to_str()) - .context(ErrorKind::ConfigImmutable)?; - } - Ok(config) } pub fn db_conn_string(config: &Config) -> Result { From a610b0820070f605383653cf30503b41dc00fa0a Mon Sep 17 00:00:00 2001 From: maddiebaka Date: Sat, 12 Aug 2023 17:45:07 -0400 Subject: [PATCH 2/5] Use parsed_args.config instead of env::var Set cfg_file configbuilder override from the parsed_args argument to configure() , instead of getting a reference from env::var("AARDWOLF_CONFIG") --- src/lib.rs | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2eb6c6a5..fbac2f19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,32 +34,30 @@ pub fn configure(parsed_args: Args) -> Result { .context(ErrorKind::ConfigImmutable)?; // Determine config file - let config_file = env::var("AARDWOLF_CONFIG").unwrap(); + let config_path = parsed_args.config.unwrap(); + let config_file = config_path.to_str().unwrap(); + builder = builder - .set_override("cfg_file", config_file.clone()) + .set_override("cfg_file", config_file) .context(ErrorKind::ConfigImmutable)?; - builder = builder.add_source(File::new(&config_file, FileFormat::Json)); // Or whatever format + builder = builder.add_source(File::new(config_file, FileFormat::Toml)); // Or whatever format - let config_path = parsed_args.config.unwrap(); builder = builder - .set_override("cfg_file", config_path.to_str()) + .set_override("cfg_file", config_file) .context(ErrorKind::ConfigImmutable)?; - //} // Apply environmenet variable overrides let env_vars = Environment::with_prefix("AARDWOLF") .separator("_") .ignore_empty(true); builder = builder.add_source(env_vars); -// + let log_path = parsed_args.log.unwrap(); builder = builder .set_override("Log.file", log_path.to_str()) .context(ErrorKind::ConfigImmutable)?; - //Err(ErrorKind::ConfigImmutable.into()) - match builder.build() { Ok(config) => { env::set_var("DATABASE_URL", db_conn_string(&config)?); @@ -70,18 +68,6 @@ pub fn configure(parsed_args: Args) -> Result { return Err(e.into()); } } - - // Merge config file and apply overrides - //let config_file_string = config - // .get_string("cfg_file") - // .context(ErrorKind::ConfigMissingKeys)?; - //let config_file = config::File::with_name(&config_file_string); - //config.merge(config_file).context(ErrorKind::ConfigImmutable)?; - - // Apply environment variable overrides - - // Remove the need for a .env file to avoid defining env vars twice. - } pub fn db_conn_string(config: &Config) -> Result { From 185dab6b79c45ebefe21c844fabc501d6df5463d Mon Sep 17 00:00:00 2001 From: Banjo Fox Date: Fri, 28 Jul 2023 11:39:46 -0400 Subject: [PATCH 3/5] Moving Docker files to their own folder. --- Dockerfile => Docker/Dockerfile | 0 Docker/Dockerfile.actix | 7 +++++++ Docker/Dockerfile.yew | 8 ++++++++ docker-compose.yml => Docker/docker-compose.yml | 0 docker-entrypoint.sh => Docker/docker-entrypoint.sh | 0 5 files changed, 15 insertions(+) rename Dockerfile => Docker/Dockerfile (100%) create mode 100644 Docker/Dockerfile.actix create mode 100644 Docker/Dockerfile.yew rename docker-compose.yml => Docker/docker-compose.yml (100%) rename docker-entrypoint.sh => Docker/docker-entrypoint.sh (100%) diff --git a/Dockerfile b/Docker/Dockerfile similarity index 100% rename from Dockerfile rename to Docker/Dockerfile diff --git a/Docker/Dockerfile.actix b/Docker/Dockerfile.actix new file mode 100644 index 00000000..80e9568e --- /dev/null +++ b/Docker/Dockerfile.actix @@ -0,0 +1,7 @@ +FROM rust:1.71-slim-bullseye + +RUN apt-get --yes update && apt-get --yes install curl git pkg-config libssl-dev +RUN curl https://github.com/amacneil/dbmate/releases/download/v2.4.0/dbmate-linux-amd64 -L -o /usr/bin/dbmate && chmod +x /usr/bin/dbmate +RUN cargo install cargo-watch +RUN rustup component add clippy-preview +RUN rustup component add rustfmt \ No newline at end of file diff --git a/Docker/Dockerfile.yew b/Docker/Dockerfile.yew new file mode 100644 index 00000000..67560aa1 --- /dev/null +++ b/Docker/Dockerfile.yew @@ -0,0 +1,8 @@ +FROM rust:1.71-slim-bullseye + +RUN apt-get --yes update && apt-get --yes install git pkg-config libssl-dev +RUN cargo install wasm-bindgen-cli +RUN cargo install trunk +RUN rustup target add wasm32-unknown-unknown +RUN rustup component add clippy-preview +RUN rustup component add rustfmt \ No newline at end of file diff --git a/docker-compose.yml b/Docker/docker-compose.yml similarity index 100% rename from docker-compose.yml rename to Docker/docker-compose.yml diff --git a/docker-entrypoint.sh b/Docker/docker-entrypoint.sh similarity index 100% rename from docker-entrypoint.sh rename to Docker/docker-entrypoint.sh From 7e03c54ecbb9f88cf14929a3f1645806ac57b9b4 Mon Sep 17 00:00:00 2001 From: Banjo Fox Date: Thu, 10 Aug 2023 15:35:31 -0400 Subject: [PATCH 4/5] Update dockerfiles to 'latest'. Add postgres. --- Docker/Dockerfile.actix | 3 +-- Docker/Dockerfile.postgresql | 5 +++++ Docker/Dockerfile.yew | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 Docker/Dockerfile.postgresql diff --git a/Docker/Dockerfile.actix b/Docker/Dockerfile.actix index 80e9568e..401f576c 100644 --- a/Docker/Dockerfile.actix +++ b/Docker/Dockerfile.actix @@ -1,7 +1,6 @@ -FROM rust:1.71-slim-bullseye +FROM rust:bookworm-slim RUN apt-get --yes update && apt-get --yes install curl git pkg-config libssl-dev -RUN curl https://github.com/amacneil/dbmate/releases/download/v2.4.0/dbmate-linux-amd64 -L -o /usr/bin/dbmate && chmod +x /usr/bin/dbmate RUN cargo install cargo-watch RUN rustup component add clippy-preview RUN rustup component add rustfmt \ No newline at end of file diff --git a/Docker/Dockerfile.postgresql b/Docker/Dockerfile.postgresql new file mode 100644 index 00000000..c1bf54f6 --- /dev/null +++ b/Docker/Dockerfile.postgresql @@ -0,0 +1,5 @@ +FROM postgres:latest + +RUN psql -c "CREATE DATABASE aardwolf;" +RUN psql -c "CREATE USER aardwolf WITH PASSWORD 'p4ssw0rd'" +RUN psql -c "GRANT ALL PRIVILEGES ON DATABASE aardwolf TO aardwolf;" \ No newline at end of file diff --git a/Docker/Dockerfile.yew b/Docker/Dockerfile.yew index 67560aa1..b4039db2 100644 --- a/Docker/Dockerfile.yew +++ b/Docker/Dockerfile.yew @@ -1,4 +1,4 @@ -FROM rust:1.71-slim-bullseye +FROM rust:bookworm-slim RUN apt-get --yes update && apt-get --yes install git pkg-config libssl-dev RUN cargo install wasm-bindgen-cli From ee3fab0cd701a621614aa159ea60edad22980007 Mon Sep 17 00:00:00 2001 From: Banjo Fox <4459812+BanjoFox@users.noreply.github.com> Date: Sun, 20 Aug 2023 17:01:57 -0400 Subject: [PATCH 5/5] Banjofox/fix posgres15 document (#305) --- .vscode/settings.json | 5 --- ...RES-15_WIP.MD => SETUP-POSTGRES-15_WIP.md} | 45 ++++++++++--------- 2 files changed, 25 insertions(+), 25 deletions(-) delete mode 100644 .vscode/settings.json rename doc/{SETUP-POSTGRES-15_WIP.MD => SETUP-POSTGRES-15_WIP.md} (59%) diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index f0c0ac4c..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "rust-analyzer.linkedProjects": [ - "./aardwolf-models/Cargo.toml", - ] -} \ No newline at end of file diff --git a/doc/SETUP-POSTGRES-15_WIP.MD b/doc/SETUP-POSTGRES-15_WIP.md similarity index 59% rename from doc/SETUP-POSTGRES-15_WIP.MD rename to doc/SETUP-POSTGRES-15_WIP.md index e35fb534..097a9e0c 100644 --- a/doc/SETUP-POSTGRES-15_WIP.MD +++ b/doc/SETUP-POSTGRES-15_WIP.md @@ -1,17 +1,17 @@ -# Ensure that lsb-release and wget are installed +### Ensure that lsb-release and wget are installed sudo apt-get install lsb-release wget -# Create the file repository configuration: +### Create the file repository configuration: sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' -# Import the repository signing key: +### Import the repository signing key: wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - -# Update the package lists: +### Update the package lists: sudo apt-get update -# Install the latest version of PostgreSQL. -# If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql': +### Install the latest version of PostgreSQL. +### If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql': sudo apt-get -y install postgresql libpq libpq-dev Switch to the postgresql command line @@ -20,15 +20,15 @@ Switch to the postgresql command line Create a superadmin role - postgres=# CREATE ROLE admin WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD 'Passw0rd'; + postgres=# CREATE ROLE admin WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD 'Passw0rd'; Create the database for Aardwolf - postgres=# CREATE DATABASE aardwolf; + postgres=# CREATE DATABASE aardwolf; Create the DB user - postgres=# CREATE USER aardwolf WITH PASSWORD 'p4ssw0rd'; + postgres=# CREATE USER aardwolf WITH PASSWORD 'p4ssw0rd'; Give `aardwolf user` all permissions to the `aardwolf-db` itself. @@ -37,32 +37,37 @@ Give `aardwolf user` all permissions to the `aardwolf-db` itself. Exit the postgresql command line \q -# Good to know commands (Upgrading cluster versions) +### Good to know commands (Upgrading cluster versions) Be sure you are still running on the old 14 cluster, Then backup your data with +`pg_dumpall -F t > ~/backup_postgres_all_dbs.tar` -pg_dumpall -F t > ~/backup_postgres_all_dbs.tar Stop the still empty default installed postgreSQL 15 cluster and drop it. +`pg_dropcluster 15 main --stop` -pg_dropcluster 15 main --stop Upgrade the 14 cluster to the latest version (which is 15 at the moment writing) +`pg_upgradecluster 14 main` -pg_upgradecluster 14 main This can take some hours. Once it is finished, check that the upgraded cluster works: - +``` service postgresql@14-main stop service postgresql@15-main start -Your 14 cluster should now be “down”. you can verify it running: +``` -pg_lsclusters +Your 14 cluster should now be “down”. you can verify it by running:`pg_lsclusters` +**Output:** +``` Ver Cluster Port Status Owner Data directory Log file 14 main 5433 down postgres /var/lib/postgresql/14/main /var/log/postgresql/postgresql-14-main.log 15 main 5432 online postgres /var/lib/postgresql/15/main /var/log/postgresql/postgresql-15-main.log +``` + Check if the applications, that use postgreSQL all work (eventually adapt the port in your psql-15 config). If everything is fin then remove the 14 cluster with -# !be really sure to call this! -# !DON'T BE TOO FAST!!! # pg_dropcluster 14 main -and remove the old packages. +### !be really sure to call this! ### !DON'T BE TOO FAST!!! ### +**This command will DROP YOUR VERSION 14 CLUSTER!**
+`pg_dropcluster 14 main` -apt-get purge postgresql-14 postgresql-client-14 \ No newline at end of file +**Finally, remove the old packages**
+`apt-get purge postgresql-14 postgresql-client-14`