Skip to content

Commit

Permalink
Merge branch 'main' into jdk-21
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorbayless committed Oct 23, 2023
2 parents 2e88985 + 1706418 commit a439b8f
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 46 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.env
.pnpm-store

conf/lila.conf
conf/lila-ws.conf

command/.cargo
command/target

Expand Down
28 changes: 28 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down
61 changes: 33 additions & 28 deletions command/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <space> to toggle, <enter> 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 {
(
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions conf/lila.conf → conf/lila.original.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ services:
- 8089:8089
volumes:
- ./repos/api:/api
profiles:
- api-docs

pgn_viewer:
build:
Expand All @@ -70,6 +72,8 @@ services:
- 8090:8080
volumes:
- ./repos/pgn-viewer:/pgn-viewer
profiles:
- pgn-viewer

lila_engine:
build:
Expand Down
67 changes: 58 additions & 9 deletions lila-docker
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
#!/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"

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
setup_database
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
Expand All @@ -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
}

Expand All @@ -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
Expand All @@ -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
Expand Down
33 changes: 27 additions & 6 deletions nginx/errors/5xx.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="refresh" content="5">
<style>
html {
background: #161512;
Expand All @@ -21,6 +20,10 @@
margin: 4rem 0 3rem;
padding: 1rem;
}
pre {
background: #333;
padding: 1rem;
}
footer {
border-top: 1px solid #bababa;
margin-top: 3rem;
Expand All @@ -36,14 +39,32 @@
<div class="container">
<h2>lila-docker</h2>

<p class="error">The lila process is not currently running and/or port 9663 is not yet available.</p>
<p class="error">The lila process is not currently available.</p>

<h3>To Fix:</h3>
<p>If you're just starting your environment, wait until lila finishes compiling. It will automatically start within 5-10 minutes.</p>
<p>Check the status in the lila service within Docker. Restart it manually if necessary.</p>
<p>For the full documentation, see <a href="https://github.com/lichess-org/lila-docker">https://github.com/lichess-org/lila-docker</a></p>
<p>If you're just starting your environment, wait until lila finishes compiling. It will automatically start within 5-15 minutes.</p>
<p>You can monitor the logs to see the progress:</p>
<pre><code>docker compose logs lila --follow</code></pre>

<footer>Nginx Error: <!--# echo var="status" default="" --></footer>

<footer>
<p>For the full documentation, see <a href="https://github.com/lichess-org/lila-docker">https://github.com/lichess-org/lila-docker</a></p>
<p>Nginx Error: <!--# echo var="status" default="" --></p>
</footer>
</div>

<script>
// Check if lila is ready yet
setInterval(function() {
var xhr = new XMLHttpRequest();
xhr.open('GET', window.location.href);
xhr.onload = function() {
if (xhr.status < 500) {
window.location.reload();
}
};
xhr.send();
}, 5*1000);
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions scripts/mongodb/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
let users = db.user4
.find()
.toArray()
.filter((user) => user._id !== 'lichess') // `lichess` user login is disabled
.map((user) => {
return {
username: user._id,
Expand All @@ -20,3 +21,5 @@ console.table(users.filter((user) => user.marks))

console.log('Regular Accounts')
console.table(users.filter((user) => !user.roles && !user.marks))

console.log('You can log in with any of the above user accounts.')

0 comments on commit a439b8f

Please sign in to comment.