From f5a107fc0f9704529a1c63dee932ed0c38da9069 Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Tue, 24 Oct 2023 17:14:10 -0400 Subject: [PATCH] make chessground an optional service --- README.md | 35 ++++++++++++++--------------------- command/src/main.rs | 12 ++++++++++-- conf/nginx.conf | 4 ---- docker-compose.yml | 14 ++++++++++++-- docker/chessground.Dockerfile | 7 +++++++ lila-docker | 25 +++++++++++-------------- 6 files changed, 54 insertions(+), 43 deletions(-) create mode 100644 docker/chessground.Dockerfile diff --git a/README.md b/README.md index 0ce9d43f..6ba23a30 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,10 @@ The only requirements for running on your local machine are `git` and Docker Des As an alternative to running it on your local machine, you can use Gitpod (a free, online, VS Code-like IDE) for contributing. With a single click, it will launch a workspace and automatically: -- Clone the necessary Lichess repositories -- Install all the dependencies -- Seed your database with test data -- Start your development site +- Clone the necessary Lichess repositories +- Install all the dependencies +- Seed your database with test data +- Start your development site Click here to create a workspace: @@ -56,12 +56,11 @@ To remove the containers: Always available: -| Service | URL | -| ------------------ | ------------------------------------------- | -| Main lila instance | http://localhost:8080/ | -| Chessground demo | http://localhost:8080/chessground/demo.html | -| Mongodb manager | http://localhost:8081/ (admin/pass) | -| Email inbox | http://localhost:8025/ | +| Service | URL | +| ------------------ | ----------------------------------- | +| Main lila instance | http://localhost:8080/ | +| Mongodb manager | http://localhost:8081/ (admin/pass) | +| Email inbox | http://localhost:8025/ | Depending on which optional services you start: @@ -71,7 +70,8 @@ Depending on which optional services you start: | Picfit | http://localhost:3001/healthcheck | | Elasticsearch manager | http://localhost:5601/ | | API docs | http://localhost:8089/ | -| PGN Viewer | http://localhost:8090/ | +| Chessground | http://localhost:8090/demo.html | +| PGN Viewer | http://localhost:8091/ | ## Usage @@ -102,14 +102,7 @@ docker compose run --rm ui bash -c "/lila/bin/trans-dump" ### Code formatting: ```bash -docker compose run --rm ui bash -c "cd /lila && pnpm install && pnpm run format" -docker compose run --rm ui bash -c "cd /chessground && pnpm install && pnpm run format" -docker compose run --rm ui bash -c "cd /pgn-viewer && pnpm install && pnpm run format" - -# sbt scalafmtAll -docker run --rm -v $(pwd)/repos/lila:/lila \ - sbtscala/scala-sbt:eclipse-temurin-jammy-21_35_1.9.7_3.3.1 \ - bash -c "cd /lila && sbt scalafmtAll" +./lila-docker format ``` ### Berserk (Python library): @@ -216,7 +209,7 @@ By default, your local lila instance will use the version of chessground that is docker compose run --rm ui bash -c "/lila/ui/build -w" ``` -Then you can see the updated chessground demo at http://localhost:8080/chessground/demo.html and when you refresh lila, it will use the local copy of chessground. +Then you can see the updated chessground demo at http://localhost:8090/demo.html and when you refresh lila, it will use the local copy of chessground. ### Developing PGN Viewer locally @@ -226,4 +219,4 @@ To re-compile the PGN Viewer after making changes: docker compose run --rm ui bash -c "cd /pgn-viewer && pnpm run sass-dev && pnpm run bundle-dev" ``` -See the changes on the PGN Viewer demo page: http://localhost:8090/ +See the changes on the PGN Viewer demo page: http://localhost:8091/ diff --git a/command/src/main.rs b/command/src/main.rs index 2d518356..b845b2c2 100644 --- a/command/src/main.rs +++ b/command/src/main.rs @@ -21,7 +21,7 @@ fn main() -> std::io::Result<()> { intro(BANNER)?; let services = multiselect( - "Select which optional services to install:\n (Use to toggle, to confirm)", + "Select which optional services to run:\n (Use to toggle, to confirm)", ) .required(false) .item( @@ -80,6 +80,14 @@ fn main() -> std::io::Result<()> { "API docs", "", ) + .item( + OptionalService { + compose_profile: Some("chessground"), + repositories: vec!["chessground"].into(), + }, + "Chessground board UI (Standalone)", + "", + ) .item( OptionalService { compose_profile: Some("pgn-viewer"), @@ -129,7 +137,7 @@ fn main() -> std::io::Result<()> { }; let repos = [ - vec!["lila", "lila-ws", "lila-db-seed", "lifat", "chessground"], + vec!["lila", "lila-ws", "lila-db-seed", "lifat"], services .iter() .flat_map(|service| service.repositories.clone()) diff --git a/conf/nginx.conf b/conf/nginx.conf index 02f22a90..3c617fd9 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -9,10 +9,6 @@ server { alias /lifat; } - location /chessground { - alias /chessground; - } - location / { try_files $uri @$http_upgrade; } diff --git a/docker-compose.yml b/docker-compose.yml index faaec740..3e2c4c76 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -47,7 +47,6 @@ services: - ./conf/nginx.conf:/etc/nginx/conf.d/default.conf - ./repos/lila/public:/lila/public - ./repos/lifat:/lifat - - ./repos/chessground:/chessground - ./nginx:/nginx depends_on: - lila @@ -64,12 +63,23 @@ services: profiles: - api-docs + chessground: + build: + context: docker + dockerfile: chessground.Dockerfile + ports: + - 8090:8080 + volumes: + - ./repos/chessground:/chessground + profiles: + - chessground + pgn_viewer: build: context: docker dockerfile: pgn-viewer.Dockerfile ports: - - 8090:8080 + - 8091:8080 volumes: - ./repos/pgn-viewer:/pgn-viewer profiles: diff --git a/docker/chessground.Dockerfile b/docker/chessground.Dockerfile new file mode 100644 index 00000000..ce1c3447 --- /dev/null +++ b/docker/chessground.Dockerfile @@ -0,0 +1,7 @@ +FROM node:20.8.1-bookworm-slim + +RUN npm install -g pnpm + +WORKDIR /chessground + +ENTRYPOINT pnpm install && pnpm run compile && pnpx http-server -p 8080 diff --git a/lila-docker b/lila-docker index 5575aaa9..b63cf1c7 100755 --- a/lila-docker +++ b/lila-docker @@ -9,22 +9,22 @@ run_setup() { repos=($(echo $REPOS | tr ',' ' ')) echo "Cloning repos... ${repos[@]}" for repo in "${repos[@]}"; do - [ ! -d repos/$repo ] && git clone --depth 1 --origin lichess-org https://github.com/lichess-org/$repo.git repos/$repo + [ ! -d repos/$repo/.git ] && git clone --depth 1 --origin lichess-org https://github.com/lichess-org/$repo repos/$repo done git -C repos/lila submodule update --init run_setup_config - echo "Compiling lila js/css..." - docker compose run --rm ui bash -c "/lila/ui/build" - - echo "Compiling chessground..." - docker compose run --rm ui bash -c "cd /chessground && pnpm install && pnpm run compile" - docker compose build + # separate build specifically for utils profile otherwise its Dockerfile changes won't be detected + docker compose --profile utils build + docker compose up -d + echo "Compiling js/css..." + docker compose run --rm ui bash -c "/lila/ui/build" + if [ "$SETUP_DB" = "true" ]; then setup_database fi @@ -86,7 +86,7 @@ setup_database() { "mongo --host mongodb lichess /lila/bin/mongodb/indexes.js" docker compose run --rm python bash -c \ - "pip install pymongo && python /lila-db-seed/spamdb/spamdb.py --uri=mongodb://mongodb/lichess --password=$PASSWORD --su-password=$SU_PASSWORD --es --es-host=elasticsearch:9200" + "python /lila-db-seed/spamdb/spamdb.py --uri=mongodb://mongodb/lichess --password=$PASSWORD --su-password=$SU_PASSWORD --es --es-host=elasticsearch:9200" docker compose run --rm -v $(pwd)/scripts:/scripts mongodb bash -c \ "mongosh --host mongodb lichess --file /scripts/mongodb/users.js" @@ -94,12 +94,9 @@ setup_database() { run_formatter() { docker compose run --rm ui bash -c "\ - cd /lila && \ - pnpm install && pnpm run format && \ - cd /chessground && \ - pnpm install && pnpm run format && \ - cd /pgn-viewer && \ - pnpm install && pnpm run format" + cd /lila && pnpm install && pnpm run format && \ + (test -f /chessground/package.json && cd /chessground && pnpm install && pnpm run format) || echo 'Skipping chessground' && \ + (test -f /pgn-viewer/package.json && cd /pgn-viewer && pnpm install && pnpm run format) || echo 'Skipping pgn-viewer'" docker run --rm -v $(pwd)/repos/lila:/lila \ sbtscala/scala-sbt:eclipse-temurin-jammy-21_35_1.9.7_3.3.1 \