Skip to content

Commit

Permalink
Lila image for CI environments (#62)
Browse files Browse the repository at this point in the history
* Build CI image

* update sbtscala image

* hardcode mongo/redis configs

* ci image to not require other services

* add pytest

* update action name

* Reduce image size with multi-stage build

3GB -> 2GB

* add curl and docs

* tweak docs formatting

* add version label

* test set package name

* CI image ui/build (#74)

* ui/build wip

* copy assets to where play framework sees as public root

* clone outside the dockerfile

* use lila-docker for package name after all since it can be used for more than ci

---------

Co-authored-by: tors42 <[email protected]>
  • Loading branch information
fitztrev and tors42 authored Mar 31, 2024
1 parent bd80f63 commit 3c3f1df
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/ci-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Publish CI image

on:
workflow_dispatch:
schedule:
- cron: '0 17 * * *'
push:
paths:
- '.github/workflows/ci-image.yml'
- 'conf/ci.conf'
- 'docker/ci.Dockerfile'

jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Checkout lila
uses: actions/checkout@v4
with:
repository: 'lichess-org/lila'
path: 'repos/lila'

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: docker/ci.Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
7 changes: 7 additions & 0 deletions conf/ci.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include "base"
include "version"

user.password.bpass.secret = "9qEYN0ThHer1KWLNekA76Q=="

net.site.name = "lila"
net.ratelimit = false
57 changes: 57 additions & 0 deletions docker/ci.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
##################################################################################
FROM node:lts-bookworm as node

RUN npm install --global pnpm
COPY repos/lila /lila
COPY conf/ci.conf /lila/conf/application.conf
RUN /lila/ui/build --clean --debug --split

##################################################################################
FROM mongo:7-jammy as dbbuilder

RUN apt update && apt install -y git python3-pip curl
RUN pip3 install pymongo requests
RUN curl -L https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.2%2B13/OpenJDK21U-jdk_x64_linux_hotspot_21.0.2_13.tar.gz | tar xzf - && mv jdk-21* /jdk-21
ENV PATH=/jdk-21/bin:$PATH

RUN git clone --depth 1 https://github.com/lichess-org/lila-db-seed /lila-db-seed
WORKDIR /lila-db-seed

RUN mkdir /seeded
RUN mongod --fork --logpath /var/log/mongodb/mongod.log --dbpath /seeded \
&& ./spamdb/spamdb.py \
--drop-db \
--password=password \
--su-password=password \
--streamers \
--coaches \
--tokens

##################################################################################
FROM sbtscala/scala-sbt:eclipse-temurin-alpine-21.0.2_13_1.9.9_3.4.1 as lilabuilder

COPY --from=node /lila /lila
WORKDIR /lila
RUN ./lila stage

##################################################################################
FROM mongo:7-jammy

RUN apt update && apt install -y curl redis python3-pip && apt clean
RUN pip3 install berserk pytest

COPY --from=dbbuilder /seeded /seeded
COPY --from=dbbuilder /jdk-21 /jdk-21
COPY --from=lilabuilder /lila/target /lila/target
COPY --from=lilabuilder /lila/public /lila/public
COPY --from=lilabuilder /lila/conf /lila/conf
COPY --from=node /lila/public /lila/target/universal/stage/public

ENV JAVA_HOME=/jdk-21
ENV PATH=/jdk-21/bin:$PATH
ENV LANG=C.utf8

WORKDIR /lila
CMD mongod --fork --logpath /var/log/mongodb/mongod.log --dbpath /seeded \
&& redis-server --daemonize yes \
&& JAVA_OPTS="-Xms4g -Xmx4g" ./target/universal/stage/bin/lila -Dconfig.file="/lila/conf/application.conf" -Dlogger.file="/lila/conf/logger.dev.xml"
18 changes: 18 additions & 0 deletions docs/ci-testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Testing the CI image build locally

```bash
docker build -t lila-ci -f docker/ci.Dockerfile .
docker run -it --rm -p 9663:9663 --name lichess lila-ci
```

Visit: <http://localhost:9663/>

```bash
curl localhost:9663/api/user/lichess
```

### Get a shell in the container for debugging:

```bash
docker exec -it lichess bash
```

0 comments on commit 3c3f1df

Please sign in to comment.