Skip to content

Commit

Permalink
refactor: vitup now uses vit-ss without SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeRosa committed Jan 30, 2023
1 parent ab41cf3 commit 6829c77
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 90 deletions.
15 changes: 1 addition & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions src/vit-servicing-station/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#DATABASE_URL=./db/database.sqlite3
#MIGRATION_DIRECTORY=./vit-servicing-station-lib/migrations/sqlite
DATABASE_URL=postgres://catalyst-dev:CHANGE_ME@localhost/VitSSDev
MIGRATION_DIRECTORY=./vit-servicing-station-lib/migrations/postgres
MIGRATION_DIRECTORY=./vit-servicing-station-lib/migrations
8 changes: 4 additions & 4 deletions src/vit-servicing-station/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ VIT as a service (VaaS)

### Building tips and tricks

We use [`diesel`](http://diesel.rs/) for database (`sqlite3`) integration. Please refer to the [`diesel_cli` documentation](https://docs.rs/crate/diesel_cli/) to understand how to operate with migrations and setup.
We use [`diesel`](http://diesel.rs/) for database integration. Please refer to the [`diesel_cli` documentation](https://docs.rs/crate/diesel_cli/) to understand how to operate with migrations and setup.

Diesel generates rust code based on a *SQL* migration script (`/migrations/*/up.sql`) when running the migration with `diesel_cli`.
Diesel code generation is configured in the `diesel.toml` file. Right now it just contains the path on where the rust code should be generated.
Expand Down Expand Up @@ -45,7 +45,7 @@ The command line flags can be retrieved using the `--help` when running the serv
--address <address> Server binding address [default: 0.0.0.0:3030]
--allowed-origins <allowed-origins> If none provided, echos request origin [env: CORS_ALLOWED_ORIGINS=]
--block0-path <block0-path> block0 static file path [default: ./resources/v0/block0.bin]
--block0-paths <block0-paths> archive block0 static folder path. WARNING each file need to be named as 'fundX.bin'
--block0-paths <block0-paths> archive block0 static folder path. WARNING each file need to be named as 'fundX.bin'
--cert-file <cert-file>
Path to server X.509 certificate chain file, must be PEM-encoded and contain at least 1 item [env:
TLS_CERT_FILE=]
Expand Down Expand Up @@ -78,11 +78,11 @@ An example of the contents of the file would be like this:
"allowed_origins" : ["https://foo.test", "https://test.foo"],
"max_age_secs" : 60
},
"db_url": "./database.sqlite3",
"db_url": "postgres://postgres:password@localhost",
"block0_path": "./test/bin.test",
"log" : {
"log_output_path" : "./server.log",
"log_level" : "error"
"log_level" : "error"
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ thiserror = "1.0"
vit-servicing-station-lib = { path = "../vit-servicing-station-lib" }

[dev-dependencies]
diesel = { version = "1.4.5", features = ["sqlite", "r2d2"] }
diesel = { version = "1.4.5", features = ["postgres", "r2d2"] }
diesel_migrations = "1.4.0"
vit-servicing-station-tests = { path = "../vit-servicing-station-tests" }
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ mod test {
use vit_servicing_station_lib::db::{
migrations::initialize_db_with_migration, queries::api_tokens::query_token_data_by_token,
};
use vit_servicing_station_tests::common::startup::db::DbBuilder;

#[test]
fn generate_token() {
Expand All @@ -187,10 +188,10 @@ mod test {
#[test]
fn add_token() {
let tokens = ApiTokenCmd::generate(10, 10);
let pool = load_db_connection_pool(&init_test_db()).unwrap();

initialize_db_with_migration(&pool.get().unwrap()).unwrap();
let db_conn = pool.get().unwrap();
let db_url = DbBuilder::new().build().unwrap();
let connection_pool = load_db_connection_pool(&db_url).unwrap();
initialize_db_with_migration(&connection_pool.get().unwrap()).unwrap();
let db_conn = connection_pool.get().unwrap();
ApiTokenCmd::add_tokens(&tokens, &db_conn).unwrap();
for token in tokens
.iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0"
async-trait = "0.1.33"
base64 = "0.13"
time = { version = "0.3", features = ["parsing", "formatting"] }
diesel = { version = "1.4.5", features = ["postgres", "sqlite", "r2d2", "64-column-tables", "serde_json"] }
diesel = { version = "1.4.5", features = ["postgres", "r2d2", "64-column-tables", "serde_json"] }
diesel_migrations = "1.4.0"
dotenv = "0.15"
itertools = "0.10"
Expand All @@ -38,11 +38,6 @@ notify = "5"
url = { version = "2", features = ["serde"] }
tempfile = "3"

# This solves building on windows when sqlite3lib is not installed or missing in the `$PATH`
# as it happens with the github actions pipeline associated to this project.
[target.'cfg(windows)'.dependencies]
libsqlite3-sys = { version = "0.9.3", features = ["bundled"] }

[dev-dependencies]
tempfile = "3"
rand = "0.8"
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const CORS_ALLOWED_ORIGINS: &str = "CORS_ALLOWED_ORIGINS";
const VIT_SERVICE_VERSION_ENV_VARIABLE: &str = "SERVICE_VERSION";

pub(crate) const ADDRESS_DEFAULT: &str = "0.0.0.0:3030";
pub(crate) const DB_URL_DEFAULT: &str = "./db/database.sqlite3";
pub(crate) const DB_URL_DEFAULT: &str = "postgres://localhost";
pub(crate) const BLOCK0_PATH_DEFAULT: &str = "./resources/v0/block0.bin";

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Parser)]
Expand Down Expand Up @@ -452,7 +452,7 @@ mod test {
"--priv-key-file",
"bar.foo",
"--db-url",
"database.sqlite3",
"postgres://localhost",
"--max-age-secs",
"60",
"--allowed-origins",
Expand All @@ -475,7 +475,7 @@ mod test {
assert!(settings.enable_api_tokens);
assert_eq!(settings.tls.cert_file.unwrap(), "foo.bar");
assert_eq!(settings.tls.priv_key_file.unwrap(), "bar.foo");
assert_eq!(settings.db_url, "database.sqlite3");
assert_eq!(settings.db_url, "postgres://localhost");
assert_eq!(settings.cors.max_age_secs.unwrap(), 60);
assert_eq!(settings.service_version, "v0.2.0");
let allowed_origins = settings.cors.allowed_origins.unwrap();
Expand All @@ -494,7 +494,7 @@ mod test {
#[test]
fn load_settings_from_env() {
use std::env::set_var;
set_var(DATABASE_URL, "database.sqlite3");
set_var(DATABASE_URL, "postgres://localhost");
set_var(TLS_CERT_FILE, "foo.bar");
set_var(TLS_PRIVATE_KEY_FILE, "bar.foo");
set_var(
Expand All @@ -519,7 +519,7 @@ mod test {
assert!(settings.tls.is_loaded());
assert_eq!(settings.tls.cert_file.unwrap(), "foo.bar");
assert_eq!(settings.tls.priv_key_file.unwrap(), "bar.foo");
assert_eq!(settings.db_url, "database.sqlite3");
assert_eq!(settings.db_url, "postgres://localhost");
assert_eq!(settings.cors.max_age_secs.unwrap(), 60);
assert_eq!(settings.service_version, "v0.2.0");
let allowed_origins = settings.cors.allowed_origins.unwrap();
Expand All @@ -542,7 +542,7 @@ mod test {
"--priv-key-file",
"bar.foo",
"--db-url",
"database.sqlite3",
"postgres://localhost",
"--max-age-secs",
"60",
"--allowed-origins",
Expand Down
11 changes: 3 additions & 8 deletions src/vit-servicing-station/vit-servicing-station-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ hex = "0.4.2"
base64 = "0.13"
cfg-if = "0.1"
time = { version = "0.3", features = ["formatting", "parsing", "macros"] }
diesel = { version = "1.4.4", features = ["sqlite", "r2d2"] }
diesel = { version = "1.4.4", features = ["postgres", "r2d2"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.53"
clap = { workspace = true }
Expand All @@ -23,7 +23,7 @@ rand_core = "0.5"
assert_fs = "1.0.0"
assert_cmd = "2"
hyper = "0.14.2"
vit-servicing-station-lib = {path= "../vit-servicing-station-lib"}
vit-servicing-station-lib = { path= "../vit-servicing-station-lib" }
lazy_static = "1.4"
rand = "0.7"
url = "2.2"
Expand All @@ -36,7 +36,7 @@ chain-addr = { path = "../../chain-libs/chain-addr", features = [ "property
chain-crypto = { path = "../../chain-libs/chain-crypto", features = [ "property-test-api" ] }
snapshot-lib = { path = "../../catalyst-toolbox/snapshot-lib" }
jormungandr-lib = { path = "../../jormungandr/jormungandr-lib" }
fake = { version = "2.2", features=['http']}
fake = { version = "2.2", features=['http'] }
pretty_assertions = "0.6"
dyn-clone = "1.0.4"
itertools = "0.10.3"
Expand All @@ -46,11 +46,6 @@ version = "0.11"
default-features = false
features = ["blocking","native-tls"]

# This solves building on windows when sqlite3lib is not installed or missing in the `$PATH`
# as it happens with the github actions pipeline associated to this project.
[target.'cfg(windows)'.dependencies]
libsqlite3-sys = { version = "0.9.3", features = ["bundled"] }

[features]
test-api = []
# feature for excluding performance tests from standard cargo test run
Expand Down
4 changes: 0 additions & 4 deletions src/vit-testing/vitup/src/builders/utils/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ impl DeploymentTree {
self.root.clone()
}

pub fn database_path(&self) -> PathBuf {
self.root.join("database.sqlite3")
}

pub fn genesis_path(&self) -> PathBuf {
self.root.join("genesis.yaml")
}
Expand Down
6 changes: 4 additions & 2 deletions src/vit-testing/vitup/src/cli/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use valgrind::ValgrindClient;
use vit_servicing_station_tests::common::startup::db::DbBuilder;
use vit_servicing_station_tests::common::startup::server::ServerBootstrapper;

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -41,7 +42,6 @@ impl DiffCommand {
let remote = TempDir::new().unwrap();
let deployment_tree = DeploymentTree::new(&self.local);
let local_genesis_yaml = deployment_tree.genesis_path();
let local_vit_db = deployment_tree.database_path();
let remote_client = ValgrindClient::new(self.target.clone(), Default::default())?;

let remote_genesis_yaml = remote.path().join("genesis_remote.yaml");
Expand All @@ -51,8 +51,10 @@ impl DiffCommand {
let local_genesis_content = read_file(&local_genesis_yaml)?;
let remote_genesis_content = read_file(remote_genesis_yaml)?;

let db_url = DbBuilder::new().build().unwrap();

let server = ServerBootstrapper::new()
.with_db_path(local_vit_db.to_str().unwrap())
.with_db_path(db_url)
.start_with_exe(&remote, self.vit_station.clone())?;

let local_funds = server.rest_client().funds()?;
Expand Down
6 changes: 2 additions & 4 deletions src/vit-testing/vitup/src/cli/generate/data/external.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::builders::utils::{logger, DeploymentTree, SessionSettingsExtension};
use crate::builders::utils::{logger, SessionSettingsExtension};
use crate::builders::VitBackendSettingsBuilder;
use crate::config::read_config;
use crate::mode::standard::generate_database;
Expand Down Expand Up @@ -74,8 +74,6 @@ impl ExternalDataCommandArgs {
std::fs::create_dir_all(&self.output_directory)?;
}

let deployment_tree = DeploymentTree::new(&self.output_directory);

let (controller, vit_parameters) = quick_setup
.config(&config)
.session_settings(session_settings)
Expand All @@ -89,7 +87,7 @@ impl ExternalDataCommandArgs {
)
.unwrap();

generate_database(&deployment_tree, vit_parameters, template_generator)?;
generate_database(vit_parameters, template_generator)?;

config.print_report(Some(controller));
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/vit-testing/vitup/src/cli/generate/data/perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl PerfDataCommandArgs {
)
.unwrap();

generate_database(&deployment_tree, vit_parameters, template_generator)?;
generate_database(vit_parameters, template_generator)?;

self.move_single_user_secrets(
&deployment_tree,
Expand Down
6 changes: 2 additions & 4 deletions src/vit-testing/vitup/src/cli/generate/data/random/all.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::builders::utils::logger;
use crate::builders::utils::SessionSettingsExtension;
use crate::builders::utils::{logger, DeploymentTree};
use crate::builders::VitBackendSettingsBuilder;
use crate::config::read_config;
use crate::mode::standard::generate_random_database;
Expand Down Expand Up @@ -44,14 +44,12 @@ impl AllRandomDataCommandArgs {
std::fs::create_dir_all(&self.output_directory)?;
}

let deployment_tree = DeploymentTree::new(&self.output_directory);

let (controller, vit_parameters) = VitBackendSettingsBuilder::default()
.config(&config)
.session_settings(session_settings)
.build()?;

generate_random_database(&deployment_tree, vit_parameters)?;
generate_random_database(vit_parameters)?;

config.print_report(Some(controller));
Ok(())
Expand Down
6 changes: 1 addition & 5 deletions src/vit-testing/vitup/src/cli/validate/ideascale.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::builders::build_current_fund;
use crate::builders::utils::DeploymentTree;
use crate::config::Config;
use crate::mode::standard::DbGenerator;
use chain_impl_mockchain::testing::scenario::template::ProposalDefBuilder;
Expand Down Expand Up @@ -165,8 +164,6 @@ impl IdeascaleValidateCommand {
) -> Result<(), Error> {
std::fs::create_dir_all(&self.output)?;

let deployment_tree = DeploymentTree::new(&self.output);

let mut template_generator = ExternalValidVotingTemplateGenerator::new(
proposals_path,
challenges_path,
Expand All @@ -192,8 +189,7 @@ impl IdeascaleValidateCommand {
vec![],
));

DbGenerator::new(parameters)
.build(&deployment_tree.database_path(), &mut template_generator)?;
DbGenerator::new(parameters).build(&mut template_generator)?;

Ok(())
}
Expand Down
7 changes: 3 additions & 4 deletions src/vit-testing/vitup/src/mode/standard/controllers/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::{
vit_station::{
dump_settings_to_file, BootstrapCommandBuilder, DbGenerator,
Error as VitStationControllerError, RestClient, ValidVotePlanParameters,
ValidVotingTemplateGenerator, VitStationController, STORAGE, VIT_CONFIG,
ValidVotingTemplateGenerator, VitStationController, VIT_CONFIG,
},
wallet_proxy::{Error as WalletProxyError, WalletProxyController, WalletProxySpawnParams},
};
Expand Down Expand Up @@ -246,16 +246,15 @@ impl VitController {
std::fs::DirBuilder::new().recursive(true).create(&dir)?;

let config_file = dir.join(VIT_CONFIG);
let db_file = dir.join(STORAGE);
dump_settings_to_file(config_file.to_str().unwrap(), settings).unwrap();

DbGenerator::new(vote_plan_parameters).build(&db_file, template_generator)?;
let db_url = DbGenerator::new(vote_plan_parameters).build(template_generator)?;

let mut command_builder =
BootstrapCommandBuilder::new(PathBuf::from("vit-servicing-station-server"));
let mut command = command_builder
.in_settings_file(&config_file)
.db_url(db_file.to_str().unwrap())
.db_url(db_url)
.service_version(version)
.block0_path(Some(
self.hersir_controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub struct VitStationController {
}

pub const VIT_CONFIG: &str = "vit_config.yaml";
pub const STORAGE: &str = "storage.db";
pub const VIT_STATION_LOG: &str = "vit_station.log";

impl VitStationController {
Expand Down
Loading

0 comments on commit 6829c77

Please sign in to comment.