Skip to content

Instantly share code, notes, and snippets.

@hi-ogawa
Last active April 19, 2022 19:09
Show Gist options
  • Save hi-ogawa/9bae1e8a809dc54a2371cbf849a6ac2d to your computer and use it in GitHub Desktop.
Save hi-ogawa/9bae1e8a809dc54a2371cbf849a6ac2d to your computer and use it in GitHub Desktop.
Lichess Development Setup

Lichess setup

# Clone repositories
git clone [email protected]:ornicar/lila.git
git clone [email protected]:ornicar/lila-ws.git
git clone [email protected]:ornicar/lila-fishnet.git

# Frontend initial build
(cd lila && ./ui/build)

# Run lila, lila-ws, redis, and mongo
yarn add foreman
yarn exec nf -- start lila,lila-ws,redis,mongo # It takes a while. Wait until you see "Listening for HTTP on /[0:0:0:0:0:0:0:0]:9663"

# Run more if you need computer analysis
yarn exec nf -- start fishnet1

# Run more if you need computer play
yarn exec nf -- start lila-fishnet,fishnet2

Build frontend separately

# Update from package.json
yarn --cwd lila install

# Incrementally compile `ui` module (e.g. ui/analyse)
yarn --cwd lila/ui/analyse run dev --watch

# Build css
yarn --cwd lila/ui run gulp css-dev

Setup data

docker-compose exec mongo mongo lichess /host_dir/createIndex.js
docker-compose exec mongo mongo lichess /host_dir/seed.js

Scala development on VS Code

# Bloop
sudo archlinux-java set java-11-openjdk # Bloop fails for latest java
(cd lila    && sbt bloopInstall)
(cd lila-ws && sbt bloopInstall)
yarn exec nf -- start lila--bloop
yarn exec nf -- start lila-ws--bloop

# Metals
# - Open VS Code with "lila" directory as root
# - Fix java version in .vscode/settings.json (e.g. "metals.javaHome": "/usr/lib/jvm/java-11-openjdk")

Accessing MongoDB

# Mongo cli
docker-compose exec mongo mongo lichess
> show collections

# Mongo-express Web UI
yarn exec nf -- start mongo-express

# Run script
docker-compose exec mongo mongo lichess /host_dir/seed.js
// TODO: Grep by "coll hint" and find more necessary indices
db.challenge.createIndex({ seenAt: 1 })
# NOTE:
# bridge mode (with port mapping) should work, but on my machine it currently has some problems.
# So, for now we'll stick with "network_mode: host"
version: "3.9"
services:
# Redis (port 6379)
redis:
image: redis:6.2.1
network_mode: host
# network_mode: bridge
# ports:
# - 6379:6379
# MongoDB (port 27017)
mongo:
image: mongo:4.4.4
network_mode: host
volumes:
- mongo_data:/data/db # Persist mongo db locally
- ./:/host_dir # For mongodump/mongorestore
# MongoDB Web UI (port 8081)
mongo-express:
image: mongo-express:0.54.0
network_mode: host
environment:
ME_CONFIG_MONGODB_SERVER: localhost
# For analysis
fishnet1:
image: niklasf/fishnet:2
command: /fishnet --endpoint http://127.0.0.1:9663/fishnet/
network_mode: host
# For computer play
fishnet2:
image: niklasf/fishnet:2
command: /fishnet --endpoint http://127.0.0.1:9665/fishnet/
network_mode: host
volumes:
mongo_data:
# Basic feature
lila: cd lila && ./lila run
lila-ws: cd lila-ws && sbt run
redis: docker-compose up redis
mongo: docker-compose up mongo
# Computer analysis
fishnet1: docker-compose up fishnet1
# Computer play
lila-fishnet: cd lila-fishnet && sbt run -Dhttp.port=9665
fishnet2: docker-compose up fishnet2
# Run lila under bloop
lila--bloop: cd lila && bloop run lila -m play.core.server.ProdServerStart
lila-ws--bloop: cd lila-ws && bloop run lila-ws
# MongoDB Web UI
mongo-express: docker-compose up mongo-express
const makeUser = id => ({
_id: id,
username: id,
len: id.length,
email: `${id}@user.com`,
lang: "en-US",
perfs: {},
count: { "ai" : 0, "draw" : 0, "drawH" : 0, "game" : 0, "loss" : 0, "lossH" : 0, "rated" : 0, "win" : 0, "winH" : 0 },
time: { "total": 0, "tv": 0 },
enabled: true,
createdAt: ISODate("2021-01-01T00:00:00"),
seenAt: ISODate("2021-01-01T00:00:00"),
bpass: BinData(0,"5TSI+p3rOp8Yl6l2OsI8MXQiK/5XtmHJk79Qby9RVRQakiYE6Q52") // password is "asdfjkl;"
});
// White wins
const makeGame1 = (id, white, black) => ({
_id: id,
is: 'xxxxyyyy',
us: [white, black],
p0: { e: 1500, p: true, l: 100 },
p1: { e: 1500, p: true, l: 100 },
s: NumberInt(30),
t: 13,
ca: ISODate('2021-04-01T00:00:00'),
ua: ISODate('2021-04-01T00:00:00'),
so: 2,
hp: BinData(0, 'AlbtTYMA'),
mt: BinData(0, 'VXRkRVVUcA=='),
w: true,
wid: white
});
const makePuzzle1 = (id, gameId) => ({
_id: id,
gameId: gameId,
fen: 'r2qkbnr/ppp2ppp/2np4/4N3/2B1P1b1/2N5/PPPP1PPP/R1BQK2R b KQkq - 0 5',
line: 'g4d1 c4f7 e8e7 c3d5',
themes: ["mix"],
glicko: { r: 1500, d: 50, v: 0.1 },
plays: 0,
vote: 0,
});
// Black wins
const makeGame2 = (id, white, black) => ({
_id: id,
is: 'xxxxyyyy',
us: [white, black],
p0: { e: 1500, p: true, l: 76.0 },
p1: { e: 1500, p: true, l: 25.0 },
s: NumberInt(30),
t: 14,
ca: ISODate('2021-03-10T13:46:44.299Z'),
ua: ISODate('2021-03-10T13:47:32.954Z'),
so: 2,
hp: BinData(0, 'CGyq4pSUQA=='),
mt: BinData(0, 'hWhUVmdERA=='),
w: false,
wid: black,
});
const makePuzzle2 = (id, gameId) => ({
_id: id,
gameId: gameId,
fen: "r1bqk2r/pppp1ppp/2n5/2b1p1B1/4n3/2NP1P2/PPP3PP/R2QKBNR w KQkq - 0 6",
line: "g5d8 c5f2 e1e2 c6d4",
themes: ["mix"],
glicko: { r: 1500, d: 50, v: 0.1 },
plays: 0,
vote: 0,
});
const user1 = 'u000';
const user2 = 'u001';
const game1 = 'g0000000';
const game2 = 'g0000001';
const puzzles = Array(500).fill().map((_, i) => 'p' + String(i).padStart(4, '0'));
db.user4.insertMany([makeUser(user1), makeUser(user2)]);
db.game5.insertMany([makeGame1(game1, user1, user2), makeGame2(game2, user1, user2)]);
db.puzzle2_puzzle.insertMany(puzzles.slice( 0, 250).map(id => makePuzzle1(id, game1)));
db.puzzle2_puzzle.insertMany(puzzles.slice(250, 500).map(id => makePuzzle2(id, game2)));
db.puzzle2_path.insertMany(['all', 'good'].map(tier => ({
_id: `mix_${tier}_0100_9999_xxxx_0`,
min: `mix_${tier}_0100`,
max: `mix_${tier}_9999`,
ids: puzzles,
tier: tier,
theme: 'mix',
gen: 'xxxx'
})));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment