Skip to content

Commit

Permalink
make chessground an optional service
Browse files Browse the repository at this point in the history
  • Loading branch information
fitztrev committed Oct 24, 2023
1 parent ce1a22e commit f5a107f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 43 deletions.
35 changes: 14 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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:

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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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/
12 changes: 10 additions & 2 deletions command/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() -> std::io::Result<()> {
intro(BANNER)?;

let services = multiselect(
"Select which optional services to install:\n (Use <space> to toggle, <enter> to confirm)",
"Select which optional services to run:\n (Use <space> to toggle, <enter> to confirm)",
)
.required(false)
.item(
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 0 additions & 4 deletions conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ server {
alias /lifat;
}

location /chessground {
alias /chessground;
}

location / {
try_files $uri @$http_upgrade;
}
Expand Down
14 changes: 12 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions docker/chessground.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
25 changes: 11 additions & 14 deletions lila-docker
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,20 +86,17 @@ 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"
}

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 \
Expand Down

0 comments on commit f5a107f

Please sign in to comment.