Skip to content

Commit

Permalink
Only clone repos necessary for selected services
Browse files Browse the repository at this point in the history
  • Loading branch information
fitztrev committed Oct 24, 2023
1 parent d99ba96 commit de933dc
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 13 deletions.
100 changes: 89 additions & 11 deletions command/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<&'static str>>,
}

fn main() -> std::io::Result<()> {
intro(BANNER)?;

let profiles = multiselect(
"Select which optional services to run:\n (Use <space> to toggle, <enter> to confirm)",
let services = multiselect(
"Select which optional services to install:\n (Use <space> to toggle, <enter> 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 =
Expand All @@ -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::<Vec<_>>(),
]
.concat();

let profiles = services
.iter()
.flat_map(|service| service.compose_profile.clone())
.collect::<Vec<_>>();

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,
Expand Down
4 changes: 2 additions & 2 deletions lila-docker
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit de933dc

Please sign in to comment.