diff --git a/command/src/main.rs b/command/src/main.rs index d59e27ee..2d518356 100644 --- a/command/src/main.rs +++ b/command/src/main.rs @@ -11,37 +11,99 @@ const BANNER: &str = r#" const ENV_PATH: &str = "/.env"; +#[derive(Default, Clone, Eq, PartialEq, Debug)] +struct OptionalService { + compose_profile: Option<&'static str>, + repositories: Option>, +} + fn main() -> std::io::Result<()> { intro(BANNER)?; - let profiles = multiselect( - "Select which optional services to run:\n (Use to toggle, to confirm)", + let services = multiselect( + "Select which optional services to install:\n (Use to toggle, to confirm)", ) .required(false) .item( - "stockfish-play", + OptionalService { + compose_profile: Some("stockfish-play"), + repositories: vec!["lila-fishnet"].into(), + }, "Stockfish (for playing against the computer)", "", ) .item( - "stockfish-analysis", + OptionalService { + compose_profile: Some("stockfish-analysis"), + repositories: None, + }, "Stockfish (for requesting computer analysis of games)", "", ) .item( - "external-engine", + OptionalService { + compose_profile: Some("external-engine"), + repositories: vec!["lila-engine"].into(), + }, "External Engine (for connecting a local chess engine to the analysis board)", "", ) .item( - "search", + OptionalService { + compose_profile: Some("search"), + repositories: vec!["lila-search"].into(), + }, "Search (for searching games, forum posts, etc)", "", ) - .item("gifs", "GIFs (for generating animated GIFs of games)", "") - .item("thumbnails", "Thumbnailer (for resizing images)", "") - .item("api-docs", "API docs", "") - .item("pgn-viewer", "PGN Viewer (Standalone)", "") + .item( + OptionalService { + compose_profile: Some("gifs"), + repositories: vec!["lila-gif"].into(), + }, + "GIFs (for generating animated GIFs of games)", + "", + ) + .item( + OptionalService { + compose_profile: Some("thumbnails"), + repositories: None + }, + "Thumbnailer (for resizing images)", + "", + ) + .item( + OptionalService { + compose_profile: Some("api-docs"), + repositories: vec!["api"].into(), + }, + "API docs", + "", + ) + .item( + OptionalService { + compose_profile: Some("pgn-viewer"), + repositories: vec!["pgn-viewer"].into(), + }, + "PGN Viewer (Standalone)", + "", + ) + .item( + OptionalService { + compose_profile: None, + repositories: vec!["scalachess"].into(), + }, + "Scalachess library", + "", + ) + .item( + OptionalService { + compose_profile: None, + repositories: vec!["berserk"].into(), + }, + "Berserk (Python API client)", + "", + ) .interact()?; let setup_database = @@ -66,8 +128,24 @@ fn main() -> std::io::Result<()> { (String::from(""), String::from("")) }; + let repos = [ + vec!["lila", "lila-ws", "lila-db-seed", "lifat", "chessground"], + services + .iter() + .flat_map(|service| service.repositories.clone()) + .flatten() + .collect::>(), + ] + .concat(); + + let profiles = services + .iter() + .flat_map(|service| service.compose_profile.clone()) + .collect::>(); + let env_contents = format!( - "COMPOSE_PROFILES={}\nSETUP_DB={}\nSU_PASSWORD={}\nPASSWORD={}\n", + "REPOS={}\nCOMPOSE_PROFILES={}\nSETUP_DB={}\nSU_PASSWORD={}\nPASSWORD={}\n", + repos.join(","), profiles.join(","), setup_database, su_password, diff --git a/lila-docker b/lila-docker index 06ecef9d..7f94faea 100755 --- a/lila-docker +++ b/lila-docker @@ -6,8 +6,8 @@ run_setup() { docker compose run --rm -it lila_docker_rs bash -c "cargo run --manifest-path /mnt/Cargo.toml" export $(cat .env | xargs) - echo "Cloning repos..." - repos=(lila lila-ws lila-db-seed lila-engine lila-fishnet lila-gif lila-search lifat scalachess api pgn-viewer chessground berserk) + repos=($(echo $REPOS | tr ',' ' ')) + echo "Cloning repos... ${repos[@]}" for repo in "${repos[@]}"; do [ ! -d repos/$repo ] && git clone --depth 1 https://github.com/lichess-org/$repo.git repos/$repo done