diff --git a/.gitignore b/.gitignore index c1ad0f5a..039b7fd3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ .env .pnpm-store +conf/lila.conf +conf/lila-ws.conf + command/.cargo command/target diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 00000000..e86bafd4 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,28 @@ +tasks: + - command: | + ./lila-docker start + ./lila-docker gitpod-welcome + +ports: + - port: 8080 + name: lichess + description: Your Lichess development site + onOpen: open-preview + - port: 8025 + name: mailpit + description: For debugging emails + onOpen: ignore + - port: 8081 + name: mongo-express + description: "For exploring database schema and contents (u: admin / p: pass)" + onOpen: ignore + - port: 5601 + name: kibana + description: For debugging Elasticsearch + onOpen: ignore + +vscode: + extensions: + - esbenp.prettier-vscode + - ms-azuretools.vscode-docker + - scala-lang.scala diff --git a/README.md b/README.md index d64a1866..70b0b418 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,22 @@ # lila-docker -Lichess local development using Docker Compose, for developing on Mac or Linux. +Lichess development environment using Docker Compose, for developing on Mac or Linux. The only requirements for running on your local machine are `git` and Docker Desktop. All the other dependencies (Scala, MongoDB, Node.js, etc) are installed and run in Docker containers. +## Running in Gitpod + +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 + +Click here to create a workspace: + +[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/new/#https://github.com/lichess-org/lila-docker) + ## Instructions 1. Install [Docker Desktop](https://www.docker.com/products/docker-desktop/) and have it running @@ -48,8 +61,6 @@ Always available: | Main lila instance | http://localhost:8080/ | | Chessground demo | http://localhost:8080/chessground/demo.html | | Mongodb manager | http://localhost:8081/ (admin/pass) | -| API docs | http://localhost:8089/ | -| PGN Viewer | http://localhost:8090/ | | Email inbox | http://localhost:8025/ | Depending on which optional services you start: @@ -59,6 +70,8 @@ Depending on which optional services you start: | lila-gif | http://localhost:6175/image.gif?fen=4k3/6KP/8/8/8/8/7p/8 | | Picfit | http://localhost:3001/healthcheck | | Elasticsearch manager | http://localhost:5601/ | +| API docs | http://localhost:8089/ | +| PGN Viewer | http://localhost:8090/ | ## Usage diff --git a/command/src/main.rs b/command/src/main.rs index 679fa4ec..d59e27ee 100644 --- a/command/src/main.rs +++ b/command/src/main.rs @@ -14,35 +14,40 @@ const ENV_PATH: &str = "/.env"; fn main() -> std::io::Result<()> { intro(BANNER)?; - let profiles = multiselect("Select which optional services to run") - .required(false) - .item( - "stockfish-play", - "Stockfish (for playing against the computer)", - "", - ) - .item( - "stockfish-analysis", - "Stockfish (for requesting computer analysis of games)", - "", - ) - .item( - "external-engine", - "External Engine (for connecting a local chess engine to the analysis board)", - "", - ) - .item( - "search", - "Search (for searching games, forum posts, etc)", - "", - ) - .item("gifs", "GIFs (for generating animated GIFs of games)", "") - .item("thumbnails", "Thumbnailer (for resizing images)", "") - .interact()?; + let profiles = multiselect( + "Select which optional services to run:\n (Use to toggle, to confirm)", + ) + .required(false) + .item( + "stockfish-play", + "Stockfish (for playing against the computer)", + "", + ) + .item( + "stockfish-analysis", + "Stockfish (for requesting computer analysis of games)", + "", + ) + .item( + "external-engine", + "External Engine (for connecting a local chess engine to the analysis board)", + "", + ) + .item( + "search", + "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)", "") + .interact()?; - let setup_database = confirm("Do you want to seed the database with test users, games, etc?") - .initial_value(true) - .interact()?; + let setup_database = + confirm("Do you want to seed the database with test users, games, etc? (Recommended)") + .initial_value(true) + .interact()?; let (su_password, password) = if setup_database { ( diff --git a/conf/lila-ws.conf b/conf/lila-ws.original.conf similarity index 100% rename from conf/lila-ws.conf rename to conf/lila-ws.original.conf diff --git a/conf/lila.conf b/conf/lila.original.conf similarity index 91% rename from conf/lila.conf rename to conf/lila.original.conf index 9098044f..b5e3d637 100644 --- a/conf/lila.conf +++ b/conf/lila.original.conf @@ -6,6 +6,8 @@ user.password.bpass.secret = "9qEYN0ThHer1KWLNekA76Q==" net.site.name = "lila" net.domain = "localhost:8080" net.socket.domains = [ "localhost:8080" ] +net.asset.base_url = "http://localhost:8080" +net.base_url = "http://localhost:8080" mongodb.uri = "mongodb://mongodb?appName=lila" redis.uri = "redis://redis" diff --git a/docker-compose.yml b/docker-compose.yml index d4f8f23c..9e4ac1f4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -61,6 +61,8 @@ services: - 8089:8089 volumes: - ./repos/api:/api + profiles: + - api-docs pgn_viewer: build: @@ -70,6 +72,8 @@ services: - 8090:8080 volumes: - ./repos/pgn-viewer:/pgn-viewer + profiles: + - pgn-viewer lila_engine: build: diff --git a/lila-docker b/lila-docker index b816c453..aded6c7d 100755 --- a/lila-docker +++ b/lila-docker @@ -1,23 +1,20 @@ #!/bin/bash set -e -show_help() { - echo "Usage: $0 [start|stop|down|build]" -} - run_setup() { touch .env 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) for repo in "${repos[@]}"; do - [ ! -d repos/$repo ] && git clone https://github.com/lichess-org/$repo.git repos/$repo + [ ! -d repos/$repo ] && git clone --depth 1 https://github.com/lichess-org/$repo.git repos/$repo done git -C repos/lila submodule update --init - run_build + run_setup_config echo "Compiling lila js/css..." docker compose run --rm ui bash -c "/lila/ui/build" @@ -25,7 +22,7 @@ run_setup() { echo "Compiling chessground..." docker compose run --rm ui bash -c "cd /chessground && pnpm install && pnpm run compile" - export $(cat .env | xargs) + docker compose build docker compose up -d if [ "$SETUP_DB" = "true" ]; then @@ -33,6 +30,19 @@ run_setup() { fi } +run_setup_config() { + echo "Copying config files..." + cp conf/lila.original.conf conf/lila.conf + cp conf/lila-ws.original.conf conf/lila-ws.conf + + # if we're running on Gitpod, we need to replace the localhost URLs with the Gitpod URLs + if [ ! -z "$GITPOD_WORKSPACE_ID" ]; then + echo "Replacing localhost URLs with Gitpod URLs..." + find ./conf/lila.conf ./conf/lila-ws.conf -type f -exec sed -i "s/http:\/\/localhost:8080/$(gp url 8080 | sed 's/\//\\\//g')/g" {} \; + find ./conf/lila.conf ./conf/lila-ws.conf -type f -exec sed -i "s/localhost:8080/$(gp url 8080 | cut -c9-)/g" {} \; + fi +} + run_start() { if [ -z "$(docker compose ps -a --services | xargs)" ]; then run_setup @@ -58,7 +68,8 @@ all_profiles() { docker compose config --profiles | xargs | sed -e 's/ /,/g' } -run_build() { +build_all_profiles() { + COMPOSE_PROFILES=$(all_profiles) docker compose pull COMPOSE_PROFILES=$(all_profiles) docker compose build } @@ -81,6 +92,38 @@ setup_database() { "mongosh --host mongodb lichess --file /scripts/mongodb/users.js" } +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" + + docker run --rm -v $(pwd)/repos/lila:/lila \ + sbtscala/scala-sbt:eclipse-temurin-focal-17.0.8.1_1_1.9.6_3.3.1 \ + bash -c "cd /lila && sbt scalafmtAll" +} + +run_gitpod_welcome() { + GREEN="\e[32m" + BOLDGREEN="\e[1;32m" + ENDCOLOR="\e[0m" + + echo -e "${GREEN}################${ENDCOLOR}" + echo -e "${GREEN}Your Lichess development environment is starting!${ENDCOLOR}" + echo -e "${GREEN}When it's ready, you can access it at:${ENDCOLOR}" + echo -e "${BOLDGREEN} $(gp url 8080)${ENDCOLOR}" + echo -e "${GREEN}Monitor the progress in the 'lila' container with the command:${ENDCOLOR}" + echo -e "${BOLDGREEN} docker compose logs lila --follow${ENDCOLOR}" + echo -e "${GREEN}For full documentation, see: https://lichess-org.github.io/lila-gitpod/${ENDCOLOR}" +} + +show_help() { + echo "Usage: $0 [start|stop|down|build|format]" +} + case $1 in --help|-h) show_help @@ -96,7 +139,13 @@ case $1 in run_down ;; build) - run_build + build_all_profiles + ;; + format) + run_formatter + ;; + gitpod-welcome) + run_gitpod_welcome ;; *) show_help diff --git a/nginx/errors/5xx.html b/nginx/errors/5xx.html index 158fe667..b36ac566 100644 --- a/nginx/errors/5xx.html +++ b/nginx/errors/5xx.html @@ -4,7 +4,6 @@ -