Skip to content

Commit

Permalink
Docker (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
snixtho authored Jul 26, 2024
1 parent a179d1b commit a07c9ef
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ EvoSC/ext_plugins/*

docker-compose.yml
global.json
.env
46 changes: 46 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Build EvoSC#
FROM mcr.microsoft.com/dotnet/sdk:8.0 as build

WORKDIR /source
COPY . .

RUN dotnet publish "src/EvoSC/EvoSC.csproj" -r linux-musl-x64 --self-contained true -c Release -o /publish

# Set user & permissions
FROM alpine:latest as run-chown

WORKDIR /app
COPY --from=build /publish .
RUN true \
&& chown 9999:9999 -R /app \
&& true

# Create the image
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine3.20 as create-image

ARG VERSION \
BUILD_DATE \
REVISION

# Disable invariant mode which is enabled on alpine to make localization work
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

LABEL org.opencontainers.image.title="EvoSC#" \
org.opencontainers.image.description="Next-generation server controller for Trackmania." \
org.opencontainers.image.authors="Evo" \
org.opencontainers.image.vendor="Evo eSports e.V." \
org.opencontainers.image.licenses="GPL-3.0 License " \
org.opencontainers.image.version=${VERSION} \
org.opencontainers.image.created=${BUILD_DATE} \
org.opencontainers.image.revision=${REVISION}

WORKDIR /app
COPY --from=run-chown /app .

RUN true \
&& apk add --no-cache icu-libs \
&& adduser --disabled-password --home /app -u 9999 evosc \
&& true \

USER evosc
ENTRYPOINT ["./EvoSC", "run"]
38 changes: 0 additions & 38 deletions docker-compose.yml

This file was deleted.

40 changes: 40 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
services:
trackmania:
image: evotm/trackmania
restart: always
ports:
- 2350:2350/udp
- 2350:2350/tcp
environment:
- MASTER_LOGIN=
- MASTER_PASSWORD=
- XMLRPC_ALLOWREMOTE=True
volumes:
- UserData:/server/UserData

postgres:
image: postgres:latest
restart: always
environment:
- POSTGRES_PASSWORD=evosc_sharp
- POSTGRES_USER=evosc_sharp
- POSTGRES_DB=evosc_sharp

evosc_sharp:
image: evoscsharp:latest
restart: always
depends_on:
- trackmania
- postgres
environment:
- EVOSC_DATABASE_HOST=postgres
- EVOSC_DATABASE_NAME=evosc_sharp
- EVOSC_DATABASE_USERNAME=evosc_sharp
- EVOSC_DATABASE_PASSWORD=evosc_sharp
- EVOSC_SERVER_HOST=trackmania
volumes:
- UserData:/server/UserData

volumes:
PostgresData: null
UserData: null
167 changes: 167 additions & 0 deletions docker/evosc.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#
# EvoSC# Base Config
#

# The type of database to use. Available types: PostgreSql, MySql, SQLite
#EVOSC_DATABASE_TYPE=PostgreSql

# Address to the database
#EVOSC_DATABASE_HOST=127.0.0.1

# Port of the database
#EVOSC_DATABASE_PORT=5432

# The name of the database
#EVOSC_DATABASE_NAME=postgres

# Name of the user to access the database
#EVOSC_DATABASE_USERNAME=evosc

# Password of the user to access the database
#EVOSC_DATABASE_PASSWORD=evosc

# A string prefix to add to all table names
#EVOSC_DATABASE_TABLEPREFIX=

# Possible values lowest to highest verbosity: none, critical, error, warning, information, debug, trace
#EVOSC_LOGGING_LOGLEVEL=debug

# Whether to output logs to the console in JSON.
#EVOSC_LOGGING_USEJSON=False

# Address to the Trackmania server
#EVOSC_SERVER_HOST=127.0.0.1

# Port that the XMLRPC is listening to
#EVOSC_SERVER_PORT=5000

# Username of the super admin account
#EVOSC_SERVER_USERNAME=SuperAdmin

# Password of the super admin account
#EVOSC_SERVER_PASSWORD=SuperAdmin

# If enabled, the client will try to reconnect with the server every 1 second until a connection is established
#EVOSC_SERVER_RETRYCONNECTION=True

# Path to the maps folder
#EVOSC_PATH_MAPS=

# Default match settings file
#EVOSC_PATH_DEFAULTMATCHSETTINGS=example.txt

# Signature verification of module's files. If enabled and verification fails, the module will not load.
#EVOSC_MODULES_REQUIRESIGNATUREVERIFICATION=True

# Directories to scan for external modules.
#EVOSC_MODULES_MODULEDIRECTORIES=System.String[]

# Modules that will not load on startup. Note that if a module depend on a disabled module, it will load anyways.
#EVOSC_MODULES_DISABLEDMODULES=

# The default display language of the controller. Must be a "language tag" as found here: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c
#EVOSC_LOCALE_DEFAULTLANGUAGE=en

#EVOSC_THEME=



#
# Module Config Options
#


## Module "ExampleModule" v1.0.0 ##

#EVOSC_EXAMPLEMODULE_MYOPTION=default value



## Module "RecordsModule" v1.0.0 ##

# How to send a message about a new PB.
#EVOSC_RECORDSMODULE_ECHOPB=None



## Module "MotdModule" v1.0.0 ##

# The URL from which the controller fetches the motd.
#EVOSC_MOTDMODULE_MOTDURL=

# The interval in which the motd gets fetched from the server.
#EVOSC_MOTDMODULE_MOTDFETCHINTERVAL=600000

# The locally stored Motd text if it should not be fetched from a server.
#EVOSC_MOTDMODULE_MOTDLOCALTEXT=This is the Motd!

# Indicator if the locally stored motd should be used.
#EVOSC_MOTDMODULE_USELOCALMOTD=True



## Module "OpenPlanetModule" v1.0.0 ##

# Allowed signature types: Regular, DevMode, Official, Competition
#EVOSC_OPENPLANETMODULE_ALLOWEDSIGNATUREMODES=Regular, Official, TMGL

# Time to wait before kicking the player.
#EVOSC_OPENPLANETMODULE_KICKTIMEOUT=30

# Enable continous check of the signature mode of the player while they are on the server.
#EVOSC_OPENPLANETMODULE_CONTINUOUSCHECKSENABLED=False

# Number of milliseconds to wait between the continous checks.
#EVOSC_OPENPLANETMODULE_CHECKINTERVAL=5000

# Enable checking of the signature mode of a player when they join.
#EVOSC_OPENPLANETMODULE_SIGNATUREMODECHECKENABLED=True

# Allow the use of openplanet. If false, no signature mode is allowed.
#EVOSC_OPENPLANETMODULE_ALLOWOPENPLANET=True

# The minimum required OpenPlanet version to play on this server.
#EVOSC_OPENPLANETMODULE_MINIMUMREQUIREDVERSION=1.25.45



## Module "MatchTrackerModule" v1.0.0 ##

# Whether to start tracking matches automatically.
#EVOSC_MATCHTRACKERMODULE_AUTOMATICTRACKING=False

# Whether to automatically end a match when the EndMatch section is detected.
#EVOSC_MATCHTRACKERMODULE_AUTOMATICMATCHEND=True

# Whether to store match state changes immediately instead of waiting until the match ends.
#EVOSC_MATCHTRACKERMODULE_IMMEDIATESTORING=True

# Record end of map states.
#EVOSC_MATCHTRACKERMODULE_RECORDENDMAP=True

# Record end of match states.
#EVOSC_MATCHTRACKERMODULE_RECORDENDMATCH=True

# Record end of round states.
#EVOSC_MATCHTRACKERMODULE_RECORDENDROUND=True

# Record pre end of match states.
#EVOSC_MATCHTRACKERMODULE_RECORDENDMATCHEARLY=False

# Keep pre end of round states.
#EVOSC_MATCHTRACKERMODULE_RECORDPREENDROUND=False



## Module "LocalRecordsModule" v1.0.0 ##

# Max of rows to show in the local records widget.
#EVOSC_LOCALRECORDSMODULE_MAXWIDGETROWS=10

# Always show top N players in the widget.
#EVOSC_LOCALRECORDSMODULE_WIDGETSHOWTOP=3

# Maximum number of local records to keep track of per map.
#EVOSC_LOCALRECORDSMODULE_MAXRECORDSPERMAP=100


5 changes: 4 additions & 1 deletion src/EvoSC.CLI/CliStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using EvoSC.Common.Permissions;
using EvoSC.Common.Remote;
using EvoSC.Common.Services;
using EvoSC.Common.Themes;
using EvoSC.Manialinks;
using EvoSC.Manialinks.Interfaces;
using EvoSC.Modules.Extensions;
Expand Down Expand Up @@ -43,7 +44,7 @@ public static void SetupBasePipeline(this IStartupPipeline pipeline, IEvoScBaseC

.Services(AppFeature.GbxRemoteClient, s => s
.AddGbxRemoteClient()
, "Logging", "Config", "Events", "ActionPipelines", "InitializeGbxRemoteConnection")
, "Logging", "Config", "Events", "ActionPipelines", "InitializeGbxRemoteConnection", "Themes")

.Services(AppFeature.Modules, s => s
.AddEvoScModules()
Expand Down Expand Up @@ -94,6 +95,8 @@ public static void SetupBasePipeline(this IStartupPipeline pipeline, IEvoScBaseC
.AddEvoScManialinks()
, "Logging", "Events", "PlayerManager", "ControllerManager", "ActionPipelines", "GbxRemoteClient", "ActionInitializeTemplates")

.Services(AppFeature.Themes, s => s.AddEvoScThemes())

// initialization of features
.Action("ActionMigrateDatabase", MigrateDatabase)

Expand Down
2 changes: 1 addition & 1 deletion src/EvoSC.Common/Config/Stores/TomlConfigStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public TomlConfigStore(string path)

_document = CreateDefaultConfig();
File.WriteAllText(path, _document.SerializedValue);

}
else
{
Expand All @@ -41,6 +40,7 @@ private TomlDocument CreateDefaultConfig()
{
var rootType = typeof(TConfig);
var document = BuildSubDocument(TomlDocument.CreateEmpty(), rootType, "");
document.Put("Theme", new TomlTable());

// avoid inline writing which is more human readable
document.ForceNoInline = false;
Expand Down
2 changes: 1 addition & 1 deletion src/EvoSC/ApplicationSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static void SetupPipeline(this IStartupPipeline pipeline, IEvoScBaseConfi

.Services(AppFeature.Manialinks, s => s.AddEvoScManialinks())

.Services(AppFeature.Themes, s => s.AddEvoScThemes())
.Services(AppFeature.Themes, s => s.AddEvoScThemes())

// initialize the application
.Action("ActionMigrateDatabase", MigrateDatabase)
Expand Down
4 changes: 4 additions & 0 deletions src/EvoSC/EvoSC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,9 @@
<ItemGroup>
<Content Include="bin\Debug\net8.0\config\main.toml" />
</ItemGroup>

<ItemGroup>
<Folder Include="bin\Debug\net8.0\config\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
using EvoSC.Common.Interfaces;
using EvoSC.Common.Interfaces.Services;
using EvoSC.Common.Remote.EventArgsModels;
using EvoSC.Common.Services.Attributes;
using EvoSC.Common.Services.Models;
using EvoSC.Common.Util;
using EvoSC.Manialinks.Interfaces;
using SpectatorTargetInfo.Interfaces;

namespace EvoSC.Modules.Official.SpectatorTargetInfoModule.Services;

[Service(LifeStyle = ServiceLifeStyle.Singleton)]
public class SpectatorTargetInfoService
(IManialinkManager manialinks, IServerClient server) : ISpectatorTargetInfoService
(IManialinkManager manialinks, IServerClient server, IPlayerManagerService playerManagerService) : ISpectatorTargetInfoService
{
private const string WidgetTemplate = "SpectatorTargetInfoModule.SpectatorTargetInfo";

public async Task SendManiaLinkAsync() =>
await manialinks.SendManialinkAsync(WidgetTemplate);


public async Task SendManiaLinkAsync(string playerLogin) =>
await manialinks.SendManialinkAsync(playerLogin, WidgetTemplate);
public async Task SendManiaLinkAsync(string playerLogin)
{
var player = await playerManagerService.GetOnlinePlayerAsync(PlayerUtils.ConvertLoginToAccountId(playerLogin));
await manialinks.SendManialinkAsync(player, WidgetTemplate);
}

public async Task HideManiaLinkAsync() =>
await manialinks.HideManialinkAsync(WidgetTemplate);
Expand Down

0 comments on commit a07c9ef

Please sign in to comment.