Code Monkey home page Code Monkey logo

lila-docker's Introduction

lila-docker

Publish CI image

Lichess development environment using Docker Compose, for developing on Mac, Linux, or Windows (via WSL).

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.

image

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

Also, see gitpod-prebuilds.md for more information on how to use prebuilds to speed up your development.

Instructions

  1. Install Docker Desktop and have it running

  2. Clone this repo:

    git clone https://github.com/lichess-org/lila-docker
  3. Start the services

    cd lila-docker
    ./lila-docker start

    Starting new services may take 5-10 minutes. Some services will start before others and you may see errors in the logs until everything comes online.

    Lila will be the last service to complete, at which point you can visit http://localhost:8080/ to see the site.

Stopping

To stop the containers, for later resuming via ./lila-docker start:

./lila-docker stop

To remove the containers:

./lila-docker down

Adding a new service

To add a new optional service after the initial setup has already been done:

./lila-docker add-services

Select the service you want to add from the list of options.

NOTE: This will not affect the existing services, only the new ones among the selected services will be added.

URLs

Always available:

Service URL
Main lila instance http://localhost:8080/

Depending on which optional services you start:

Service URL
Mongodb manager http://localhost:8081/
Email inbox http://localhost:8025/
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:8092/
lila-search docs http://localhost:9673/docs/
API docs http://localhost:8089/
Chessground http://localhost:8090/demo.html
PGN Viewer http://localhost:8091/
InfluxDB http://localhost:8086/ (admin/password)

Usage

Scala development:

To restart lila (after making changes to any Scala code):

./lila-docker lila restart

UI (JS/CSS) development:

To watch for Typescript/SCSS changes and automatically recompile:

./lila-docker ui

Updating Routes

If you edit the conf/routes file, you'll need to update the route cache.

docker compose exec lila ./lila playRoutes

To add translation keys:

After modifying a translation/source/*.xml file, run:

docker compose run --rm ui /lila/bin/trans-dump

Code formatting:

./lila-docker format

Optional: Make the database persistent

docker compose cp mongodb:/data/db ./database

Then in docker-compose.ymladd - ./database:/data/db to mongodb volumes

Berserk (Python library):

To install the development version of Berserk and run a sample script against your local development site:

docker compose run --rm -w /berserk python \
    bash -c "pip install -e . && python /scripts/berserk-example.py"

Scala Metals (IDE helper):

  1. In VS Code, open this lila-docker project and install the Dev Containers extension
  2. Cmd+Shift+P > "Dev Containers: Rebuild and Reopen in Container"
  3. A new VS Code window will open, attached to the container instead of your host machine
  4. File > Open Folder > "/workspaces/lila-docker/repos/lila" (or whichever Scala project you want to work on)
  5. Install + Enable the Scala Metals extension (Cmd+Shift+X > "Scala (Metals)")
  6. Cmd+Shift+P > "Metals: Import build"

Once the build has been imported, you should have code completion, go to definition, etc when you open a Scala file.

Scalachess:

If you're making changes to the Scalachess library, you can have lila use it instead of the published Maven version:

  1. Update the build.sbt file in the scalachess repo:

    -  ThisBuild / version           := "15.6.7"
    +  ThisBuild / version           := "my-test-1"  # give it a custom version
  2. Update the Dependencies.scala file in the lila repo:

    -  val chess = "org.lichess" %% "scalachess" % "15.6.7"
    +  val chess = "org.lichess" %% "scalachess" % "my-test-1"
  3. Publish the local scalachess changes and restart lila:

    docker compose exec -w /scalachess lila sbt publishLocal
    docker compose restart lila

Other Scalachess commands:

## formatting
docker compose run --rm -w /scalachess --entrypoint="sbt check" lila
docker compose run --rm -w /scalachess --entrypoint="sbt prepare" lila

## compile
docker compose run --rm -w /scalachess --entrypoint="sbt compile" lila

## test
docker compose run --rm -w /scalachess --entrypoint="sbt testKit/test" lila

## package
docker compose run --rm -w /scalachess --entrypoint="sbt package" lila

Dartchess:

## run formatter
docker compose run --rm -w /dartchess mobile dart format .

## analyze
docker compose run --rm -w /dartchess mobile bash -c "dart pub get && dart analyze"

## run tests
docker compose run --rm -w /dartchess mobile bash -c "dart pub get && dart test -x full_perft"

Developing Chessground locally

By default, your local lila instance will use the version of chessground that is published to npm. If you want to make changes to that library and see them reflected in your local lila instance, you can do the following:

  1. Have lila use the local version of chessground:

    docker compose run --rm -w /lila ui bash -c "pnpm link /chessground"
  2. Start the chessground compiler in watch mode:

    docker compose run --rm -w /chessground ui bash -c "pnpm install && pnpm run compile --watch"
  3. Start the lila ui build in watch mode:

    ./lila-docker ui

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

To re-compile the PGN Viewer after making changes:

docker compose run --rm -w /pgn-viewer ui bash -c "pnpm run sass-dev && pnpm run bundle-dev"

See the changes on the PGN Viewer demo page: http://localhost:8091/

InfluxDB Monitoring

To view the InfluxDB monitoring dashboard, start your environment with the Monitoring service enabled and then visit http://localhost:8086/ (admin/password)

You can also see all the metrics logged by running:

curl --get http://localhost:8086/query \
    --header "Authorization: Token secret" \
    --data-urlencode "db=kamon"  \
    --data-urlencode "q=show measurements;"

Mobile

Important

Requires Flutter and adb to be installed locally. Verify Flutter is configured correctly with flutter doctor.

  1. On your Android phone:

    1. Connect your phone to the same wifi network as your host machine
    2. Enable Developer Mode
    3. In Developer Options, toggle Wireless Debugging to ON
    4. Tap "Wireless Debugging" to enter its menu
  2. On your host machine:

    1. Have the lila-docker services running, with the Mobile optional service started

    2. Configure lila to run with your host's IP address or hostname instead of localhost

      ./lila-docker hostname
      • Then verify that your phone can access the site at http://[your-selection]:8080
    3. Connect to your phone

      ./lila-docker mobile
    4. Verify your phone is listed

      adb devices
    5. Install the app dependencies and run the app:

      cd repos/mobile
      
      flutter channel beta
      flutter upgrade
      
      flutter pub get
      dart run build_runner build
      
      flutter run

lila-docker's People

Contributors

amitdash291 avatar belluu avatar carbrex avatar fitztrev avatar juesto avatar kraktus avatar lenguyenthanh avatar purefan avatar tors42 avatar trevorbayless avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

lila-docker's Issues

docker start getting killed automatically on mac

No idea about scala and how it runs but I installed docker on my mac and cloned this repo
When I run this command
lila-docker git:(main) ./lila-docker start
it takes a while and seems to be going to good but after a bit I see this error

lila-1  | [info] done compiling
lila-1  | [info] compiling 7 Scala sources to /lila/modules/appeal/target/scala-3.4.1/classes ...
lila-1  | [info] done compiling
lila-1  | [info] compiling 6 Scala sources to /lila/modules/playban/target/scala-3.4.1/classes ...
lila-1  | Killed
lila-1 exited with code 0
image I have a decent machine image

Should I allocate more memory to docker or something on those lines?

Lila PR preview sites

Support a link that, when clicked, will start a gitpod instance but with a PR's branch checked out instead of master. Will allow others to test a PR easily.

You can setup environment variables on Gitpod in the url like this:

- https://gitpod.io/#https://github.com/lichess-org/lila-docker
+ https://gitpod.io/#lila-pr=12345/https://github.com/lichess-org/lila-docker

Then, if lila-pr is set, we can fetch and checkout during setup.

git fetch upstream pull/12345/head:preview
git checkout preview

Unable to build `Lila-docker` with VPN

For the record

[+] Building 0.0s (0/0)                                                              
[+] Building 0.0s (0/0)                                                              
[+] Building 0.1s (2/2)                                                              
 => [internal] load build definition from lila.Dockerfile                       0.0s
 => => transferring dockerfile: 148B                                            0.0s
 => [internal] load .dockerignore                                               0.0s
[+] Building 0.3s (2/3)                                                              
 => [internal] load build definition from lila.Dockerfile                       0.0s
 => => transferring dockerfile: 148B                                            0.0s 
[+] Building 0.2s (2/3)                                                              
 => [internal] load build definition from picfit.Dockerfile                     0.0s
 => => transferring dockerfile: 347B                                            0.0s
[+] Building 0.7s (3/3) FINISHED                                                     
 => [internal] load build definition from lila.Dockerfile                       0.0s
 => => transferring dockerfile: 148B                                            0.0s
 => [internal] load .dockerignore                                               0.0s
[+] Building 0.7s (3/3) FINISHED                                                     
 => [internal] load build definition from lila-ws.Dockerfile                    0.0s
 => => transferring dockerfile: 181B                                            0.0s
 => [internal] load .dockerignore                                               0.0s1[+] Building 0.6s (3/3) FINISHED                                                     
 => [internal] load build definition from picfit.Dockerfile                     0.0s
 => => transferring dockerfile: 347B                                            0.0s
 => [internal] load .dockerignore                                               0.0s1 => => transferring context: 2B                                                 0.0s
 => ERROR [internal] load metadata for docker.io/library/golang:1.21.4-alpine3  0.4s
------
 > [internal] load metadata for docker.io/library/golang:1.21.4-alpine3.18:
------
failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to authorize: rpc error: code = Unknown desc = failed to fetch anonymous token: Get "https://auth.docker.io/token?scope=repository%3Asbtscala%2Fscala-sbt%3Apull&service=registry.docker.io": write tcp [**[REDACTED IP v6]**]:55294->[**[REDACTED IP v6]**]:443: write: broken pipe

disabling the VPN fixed the issue

Allow custom ports

For each port that gets exposed to the host OS, allow it to be customized in case it's already in use.

ports:
-  - 8080:80
+  - ${LILA_PORT:-8080}:80

Development server on EC2 instance port 8080 causing problems

I deployed the development server on my EC2 instance. There is no issue accessing ports 8081 or 8025, but the main port 8080 is causing problems. Looking at the docker logs for this container this is the error.

24.4.198.26 - - [10/Feb/2024:00:42:31 +0000] "GET / HTTP/1.1" 301 0 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Mobile/15E148 Safari/604.1" "

Content Security Policy console errors

  1. Visit http://localhost:8080/forum

See console error:

Refused to load the font 'data:application/octet-stream;....'
because it violates the following Content Security Policy directive:
"font-src 'self' localhost:8080".
  1. Visit http://localhost:8080/patron

See console error:

Refused to execute inline script because it violates the following Content Security Policy directive:
"script-src https://*.paypal.com https://*.stripe.com 'nonce-nAz29QMpZzMbeetZjks5zcwp' 'self' localhost:8080".
Either the 'unsafe-inline' keyword, a hash ('sha256-b+mf6EIMFYxuAIdk6/2IF09zTUsJrlW6qZaw4opG6QU='), or a nonce ('nonce-...') is required to enable inline execution.

Update CMD syntax in CI Dockerfile

Get this warning during build:

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals (line 67)

See https://docs.docker.com/reference/build-checks/json-args-recommended/

CMD mongod --fork --logpath /var/log/mongodb/mongod.log --dbpath /seeded \
&& redis-server --daemonize yes \
&& wait-for localhost:27017 --timeout=15 \
&& wait-for localhost:6379 --timeout=15 \
&& /lila-ws/target/universal/stage/bin/lila-ws \
& wait-for localhost:9664 --timeout=15 \
&& JAVA_OPTS="-Xms4g -Xmx4g" ./target/universal/stage/bin/lila -Dconfig.file="/lila/conf/application.conf" -Dlogger.file="/lila/conf/logger.dev.xml"

Make token setup optional

--tokens is passed to lila-db-seed during database setup to auto create user tokens

If a password other than "password" is chosen, it should ask if tokens should be setup.

image

Workflow to reflect typescript changes?

Hi,

I love this initiative of having a gitpod environment to onboard on lichess dev.

In the doc it is stated that

UI (JS/CSS) development:
To watch for Typescript/SCSS changes and automatically recompile:
docker compose run --rm ui bash -c "/lila/ui/build -w"

Unfortunately, when I did execute this command, it seems not enough to fully reflect changes on the running website.
Basically, I have to restart lila with:

Scala development:
To restart lila (after making changes to any Scala code):

docker compose restart lila

despite my changes are not directly related to Scala code.

Did I misunderstand something?

The current dev workflow is not so satisfactory.
Basically, I was trying to debug the JS code with some console.log...
And I have to wait lots of time to see the actual effect.

I'm sure I'm missing something.

Thanks a lot!

Outbound emails

I was looking to have real outbound emails for registration. I'm not sure how to configure the docker image to do this.

Python error when trying to setup mobile

I am setting up local docker for flutter mobile app and seeing the following error

 => [python internal] load build definition from python.Dockerfile                                                              0.0s
 => => transferring dockerfile: 231B                                                                                            0.0s
 => [ui internal] load build definition from ui.Dockerfile                                                                      0.0s
 => => transferring dockerfile: 383B                                                                                            0.0s
 => ERROR [python internal] load metadata for docker.io/library/python:3.12.3-alpine3.19                                        0.1s
 => ERROR [ui internal] load metadata for docker.io/library/node:20.12.2-bookworm-slim                                          0.1s
 => ERROR [python internal] load metadata for docker.io/library/eclipse-temurin:22_36-jdk-alpine                                0.1s
------
 > [python internal] load metadata for docker.io/library/python:3.12.3-alpine3.19:
------
------
 > [ui internal] load metadata for docker.io/library/node:20.12.2-bookworm-slim:
------
------
 > [python internal] load metadata for docker.io/library/eclipse-temurin:22_36-jdk-alpine:
------
failed to solve: node:20.12.2-bookworm-slim: failed to resolve source metadata for docker.io/library/node:20.12.2-bookworm-slim: error getting credentials - err: exec: "docker-credential-desktop": executable file not found in $PATH, out: ``

Do i need specific version of python or node? I have node v22.0.0 not sure why the error is specifying other node version.

If on Gitpod environment, prompt if workspace should be public

By default, your gitpod-hosted lichess dev site is only accessible from the same browser you're logged into gitpod with. All other requests get a 401.

This causes problems for people trying to access it via code or the mobile app for instance if they're trying to use it that way.

  1. add prompt to setup cli
  2. conditionally call gitpod_public()

fix sbt image for docker engine people

The Dockerfile for scalacenter's sbt image has a variable that might just work around the root owned build artifact issue.

See Sol's message.

Haven't tested and I'm not sure how much it slows down the initial build, but maybe it's worth a try.

Status command to see if any repos are out-of-date

After the initial clone during setup, it may not be easy to fetch any upstream changes for the individual repos.

To start, maybe a ./lila-docker status command can show if any of the local repos need to be updated.

Running on Ubuntu 20.04 ./command/target/release/command: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by ./command/target/release/command)

I get this error when I try to start the service:
sudo ./lila-docker start

โœ“ Running on Docker Engine
Updating crates.io index
Downloading crates ...
Downloaded either v1.13.0
Downloaded equivalent v1.0.1
Downloaded number_prefix v0.4.0
Downloaded serde_spanned v0.6.6
Downloaded lazy_static v1.5.0
Downloaded zeroize_derive v1.4.2
Downloaded smawk v0.3.2
Downloaded zeroize v1.8.1
Downloaded unicode-linebreak v0.1.5
Downloaded thiserror-impl v1.0.63
Downloaded serde_derive v1.0.204
Downloaded ryu v1.0.18
Downloaded unicode-ident v1.0.12
Downloaded textwrap v0.16.1
Downloaded serde v1.0.204
Downloaded toml_edit v0.22.16
Downloaded serde_json v1.0.120
Downloaded winnow v0.6.14
Downloaded syn v2.0.71
Downloaded unicode-width v0.1.13
Downloaded libc v0.2.155
Downloaded syn v1.0.109
Downloaded portable-atomic v1.7.0
Downloaded cliclack v0.2.5
Downloaded memchr v2.7.4
Downloaded toml v0.8.15
Downloaded indicatif v0.17.8
Downloaded indexmap v2.2.6
Downloaded hashbrown v0.14.5
Downloaded proc-macro2 v1.0.86
Downloaded quote v1.0.36
Downloaded log v0.4.22
Downloaded local-ip-address v0.6.1
Downloaded neli v0.6.4
Downloaded console v0.15.8
Downloaded toml_datetime v0.6.6
Downloaded itoa v1.0.11
Downloaded thiserror v1.0.63
Downloaded once_cell v1.19.0
Downloaded neli-proc-macros v0.1.3
Downloaded byteorder v1.5.0
Finished release profile [optimized] target(s) in 0.85s
./command/target/release/command: /lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.33' not found (required by ./command/target/release/command) ./command/target/release/command: /lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.32' not found (required by ./command/target/release/command)
./command/target/release/command: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./command/target/release/command)

Image upload server error

When writing a blog post, the image upload doesn't work in the dev environment.

image

Possible picfit misconfiguration.

03:13:28.632 [error] p.c.s.n.PlayRequestHandler - Cannot invoke the action
lila.base.LilaException$$anon$1: Not Found 404 page not found
     at lila.base.LilaException$.apply(LilaException.scala:19)
     at lila.base.LilaTypes.fufail(LilaTypes.scala:21)
     at lila.base.LilaTypes.fufail$(LilaTypes.scala:8)
     at lila.Lila$.fufail(Lila.scala:3)
     at lila.memo.package$package$.fufail(package.scala:3)
     at lila.memo.PicfitApi.lila$memo$PicfitApi$picfitServer$$$_$store$$anonfun$1(Picfit.scala:95)
     at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:470)
     at scala.concurrent.BatchingExecutor$AbstractBatch.runN(BatchingExecutor.scala:134)
     at scala.concurrent.BatchingExecutor$AsyncBatch.apply(BatchingExecutor.scala:163)
     at scala.concurrent.BatchingExecutor$AsyncBatch.apply(BatchingExecutor.scala:146)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.