Skip to content

Commit

Permalink
Merge branch 'master' into four-column-relay-hack
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar authored May 6, 2024
2 parents 1e1867c + a28ab6b commit 909ae36
Show file tree
Hide file tree
Showing 2,522 changed files with 49,153 additions and 49,535 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ jobs:
id: ab
- run: pnpm link "$GITHUB_WORKSPACE/ab"
if: steps.ab.outcome == 'success'
- run: ./ui/build --no-install -ps
- run: ./ui/build --no-install -p
- run: cd ui && pnpm run test && cd -
- run: mkdir assets && mv public assets/ && cp bin/download-lifat LICENSE COPYING.md README.md assets/ && git log -n 1 --pretty=oneline > assets/commit.txt
- run: mkdir assets && mv public assets/ && cp -p bin/download-lifat LICENSE COPYING.md README.md assets/ && git log -n 1 --pretty=oneline > assets/commit.txt
- run: cd assets && tar --zstd -cvpf ../assets.tar.zst . && cd -
- uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
project/.bloop/
conf/application.conf
conf/version.conf
conf/manifest.*

logs
project/metals.sbt
Expand All @@ -21,6 +22,7 @@ data/
dist/
node_modules/
local/
gen/
ui/common/**/*.js
ui/common/**/*.d.ts
ui/chess/**/*.js
Expand Down
1 change: 0 additions & 1 deletion .ignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# search ignores
vendor
translation/dest
ui/*/css/build
public/font
public/sound
public/piece
Expand Down
6 changes: 2 additions & 4 deletions .sbtopts.default
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
-J-Xms256M
-J-Xmx3072M
-J-XX:MaxMetaspaceSize=1024M
-J-Xss1M
-J-Xms2G
-J-Xmx4G
12 changes: 1 addition & 11 deletions COPYING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copying Lila

Any file in this project that does not state otherwise and is not listed as an
exception below is part of lila and copyright (c) 2012-2023 the lila authors.
exception below is part of lila and copyright (c) 2012-2024 the lila authors.

For a list of the authors see the commit log or
https://github.com/lichess-org/lila/graphs/contributors.
Expand All @@ -18,16 +18,6 @@ details.

See the LICENSE file for a copy of the _GNU Affero General Public License_.

## Additional permission under GNU AGPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it
with Highcharts (or a modified version of that library), containing parts
covered by the terms of the _Creative Commons (CC) Attribution-NonCommercial_
license, the licensors of this Program grant you additional permission to
convey the resulting work. Corresponding Source for a non-source form of such a
combination shall include the source code for the parts of Highcharts used as
well as that of the covered work.

## Exceptions (free)

<!-- prettier-ignore -->
Expand Down
41 changes: 0 additions & 41 deletions FAQ.md

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ For your own sake, please upgrade. Security and performance, think about it!
## License

Lila is licensed under the GNU Affero General Public License 3 or any later
version at your choice with an exception for Highcharts. See [copying](https://github.com/lichess-org/lila/blob/master/COPYING.md) for
version at your choice. See [copying](https://github.com/lichess-org/lila/blob/master/COPYING.md) for
details.

## Production architecture (as of July 2022)
Expand Down
76 changes: 20 additions & 56 deletions app/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import lila.core.config.*
import lila.common.config.given
import lila.common.autoconfig.{ *, given }
import lila.core.data.{ Strings, UserIds }
import lila.memo.SettingStore.Strings.given
import lila.memo.SettingStore.UserIds.given
import lila.core.i18n.Translator

final class Env(
Expand All @@ -25,11 +23,13 @@ final class Env(
SessionCookieBaker
):
val net: NetConfig = config.get[NetConfig]("net")

export net.{ domain, baseUrl, assetBaseUrlInternal }

given Mode = environment.mode
given translator: Translator = lila.i18n.Translator
given scheduler: Scheduler = system.scheduler
given Mode = environment.mode
given translator: Translator = lila.i18n.Translator
given scheduler: Scheduler = system.scheduler
given lila.core.config.RateLimit = net.rateLimit

// wire all the lila modules in the right order
val i18n: lila.i18n.Env.type = lila.i18n.Env
Expand Down Expand Up @@ -62,14 +62,13 @@ final class Env(
val tournament: lila.tournament.Env = wire[lila.tournament.Env]
val swiss: lila.swiss.Env = wire[lila.swiss.Env]
val mod: lila.mod.Env = wire[lila.mod.Env]
val forum: lila.forum.Env = wire[lila.forum.Env]
val forumSearch: lila.forumSearch.Env = wire[lila.forumSearch.Env]
val team: lila.team.Env = wire[lila.team.Env]
val teamSearch: lila.teamSearch.Env = wire[lila.teamSearch.Env]
val forum: lila.forum.Env = wire[lila.forum.Env]
val forumSearch: lila.forumSearch.Env = wire[lila.forumSearch.Env]
val pool: lila.pool.Env = wire[lila.pool.Env]
val lobby: lila.lobby.Env = wire[lila.lobby.Env]
val setup: lila.setup.Env = wire[lila.setup.Env]
val importer: lila.importer.Env = wire[lila.importer.Env]
val simul: lila.simul.Env = wire[lila.simul.Env]
val appeal: lila.appeal.Env = wire[lila.appeal.Env]
val timeline: lila.timeline.Env = wire[lila.timeline.Env]
Expand Down Expand Up @@ -102,6 +101,7 @@ final class Env(
val opening: lila.opening.Env = wire[lila.opening.Env]
val tutor: lila.tutor.Env = wire[lila.tutor.Env]
val cms: lila.cms.Env = wire[lila.cms.Env]
val web: lila.web.Env = wire[lila.web.Env]
val api: lila.api.Env = wire[lila.api.Env]

val explorerEndpoint = config.get[String]("explorer.endpoint")
Expand All @@ -112,57 +112,19 @@ final class Env(
val appVersionCommit = config.getOptional[String]("app.version.commit")
val appVersionMessage = config.getOptional[String]("app.version.message")

val apiTimelineSetting = memo.settingStore[Int](
"apiTimelineEntries",
default = 10,
text = "API timeline entries to serve".some
)
val noDelaySecretSetting = memo.settingStore[Strings](
"noDelaySecrets",
default = Strings(Nil),
text =
"Secret tokens that allows fetching ongoing games without the 3-moves delay. Separated by commas.".some
)
val prizeTournamentMakers = memo.settingStore[UserIds](
"prizeTournamentMakers",
default = UserIds(Nil),
text =
"User IDs who can make prize tournaments (arena & swiss) without a warning. Separated by commas.".some
)
val apiExplorerGamesPerSecond = memo.settingStore[Int](
"apiExplorerGamesPerSecond",
default = 300,
text = "Opening explorer games per second".some
)
val pieceImageExternal = memo.settingStore[Boolean](
"pieceImageExternal",
default = false,
text = "Use external piece images".some
)

lazy val preloader = wire[mashup.Preload]
lazy val socialInfo = wire[mashup.UserInfo.SocialApi]
lazy val userNbGames = wire[mashup.UserInfo.NbGamesApi]
lazy val userInfo = wire[mashup.UserInfo.UserInfoApi]
lazy val teamInfo = wire[mashup.TeamInfoApi]
lazy val gamePaginator = wire[mashup.GameFilterMenu.PaginatorBuilder]
lazy val pageCache = wire[http.PageCache]

private val tryDailyPuzzle: lila.puzzle.DailyPuzzle.Try = () =>
Future {
puzzle.daily.get
}.flatMap(identity)
.withTimeoutDefault(50.millis, none)
.recover { case e: Exception =>
lila.log("preloader").warn("daily puzzle", e)
none
}
val preloader = wire[mashup.Preload]
val socialInfo = wire[mashup.UserInfo.SocialApi]
val userNbGames = wire[mashup.UserInfo.NbGamesApi]
val userInfo = wire[mashup.UserInfo.UserInfoApi]
val teamInfo = wire[mashup.TeamInfoApi]
val gamePaginator = wire[mashup.GameFilterMenu.PaginatorBuilder]
val pageCache = wire[http.PageCache]

lila.common.Bus.subscribeFun("renderer"):
case lila.tv.RenderFeaturedJs(game, promise) =>
promise.success(Html(views.html.game.mini.noCtx(lila.game.Pov.naturalOrientation(game), tv = true)))
promise.success(Html(views.game.mini.noCtx(Pov.naturalOrientation(game), tv = true)))
case lila.puzzle.DailyPuzzle.Render(puzzle, fen, lastMove, promise) =>
promise.success(Html(views.html.puzzle.bits.daily(puzzle, fen, lastMove)))
promise.success(Html(views.puzzle.bits.daily(puzzle, fen, lastMove)))

end Env

Expand All @@ -178,12 +140,14 @@ given ConfigLoader[NetConfig] = ConfigLoader(config =>
assetBaseUrl = get[AssetBaseUrl]("asset.base_url"),
assetBaseUrlInternal = get[AssetBaseUrlInternal]("asset.base_url_internal"),
minifiedAssets = get[Boolean]("asset.minified"),
externalManifest = get[Boolean]("asset.external_manifest"),
stageBanner = get[Boolean]("stage.banner"),
siteName = get[String]("site.name"),
socketDomains = get[List[String]]("socket.domains"),
socketAlts = get[List[String]]("socket.alts"),
crawlable = get[Boolean]("crawlable"),
rateLimit = get[RateLimit]("ratelimit"),
email = get[EmailAddress]("email")
email = get[EmailAddress]("email"),
logRequests = get[Boolean]("http.log")
)
)
101 changes: 5 additions & 96 deletions app/Lila.scala
Original file line number Diff line number Diff line change
@@ -1,108 +1,17 @@
package lila.app

import play.api.inject.DefaultApplicationLifecycle
import play.api.{ Application, Configuration, Environment, Mode, Play }
import play.core.server.{
NettyServer,
RealServerProcess,
Server,
ServerConfig,
ServerProcess,
ServerStartException
}

import java.io.*
import play.api.Configuration

// The program entry point.
// To run with bloop:
// /path/to/bloop run lila -m lila.app.Lila -c /path/to/lila/.bloop
object Lila:

def main(args: Array[String]): Unit = start(new RealServerProcess(args.toIndexedSeq))

/** Starts a Play server and application for the given process. The settings for the server are based on
* values passed on the command line and in various system properties. Crash out by exiting the given
* process if there are any problems.
*
* @param process
* The process (real or abstract) to use for starting the server.
*/
def start(process: ServerProcess): Server = try
// Configure logback early - before play invokes Logger
LoggerConfigurator.configure()

val config: ServerConfig = readServerConfigSettings(process)

// Start the application
val application: Application =
val environment = Environment(config.rootDir, process.classLoader, config.mode)
def main(args: Array[String]): Unit =
lila.web.PlayServer.start(args): env =>
LilaComponents(
environment,
env,
DefaultApplicationLifecycle(),
Configuration.load(environment)
Configuration.load(env)
).application

Play.start(application)

val server = NettyServer(
config,
application,
stopHook = () => funit,
application.actorSystem
)(application.materializer)

process.addShutdownHook:
// Only run server stop if the shutdown reason is not defined. That means the
// process received a SIGTERM (or other acceptable signal) instead of being
// stopped because of CoordinatedShutdown, for example when downing a cluster.
// The reason for that is we want to avoid calling coordinated shutdown from
// inside a JVM shutdown hook if the trigger of the JVM shutdown hook was
// coordinated shutdown.
if application.coordinatedShutdown.shutdownReason().isEmpty then server.stop()

lila.common.Lilakka.shutdown(
application.coordinatedShutdown,
_.PhaseBeforeActorSystemTerminate,
"Shut down logging"
): () =>
fuccess(LoggerConfigurator.shutdown())

server
catch
case ServerStartException(message, cause) => process.exit(message, cause)
case e: Throwable => process.exit("Oops, cannot start the server.", Some(e))

def readServerConfigSettings(process: ServerProcess): ServerConfig =
val configuration: Configuration =
val rootDirArg = process.args.headOption.map(new File(_))
val rootDirConfig = rootDirArg.so(ServerConfig.rootDirConfig(_))
Configuration.load(process.classLoader, process.properties, rootDirConfig, true)

val rootDir: File =
val path = configuration
.getOptional[String]("play.server.dir")
.getOrElse(throw ServerStartException("No root server path supplied"))
val file = File(path)
if !file.isDirectory then throw ServerStartException(s"Bad root server path: $path")
file

def parsePort(portType: String): Option[Int] =
configuration
.getOptional[String](s"play.server.$portType.port")
.filter(_ != "disabled")
.map: str =>
try Integer.parseInt(str)
catch
case _: NumberFormatException =>
throw ServerStartException(s"Invalid ${portType.toUpperCase} port: $str")

parsePort("http") match
case None => throw ServerStartException("Must provide an HTTP port")
case Some(httpPort) =>
val address = configuration.getOptional[String]("play.server.http.address").getOrElse("0.0.0.0")

val mode =
if configuration.getOptional[String]("play.mode").contains("prod") then Mode.Prod
else Mode.Dev

ServerConfig(rootDir, httpPort, address, mode, process.properties, configuration)
Loading

0 comments on commit 909ae36

Please sign in to comment.