This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
# Builds the LaDOSE.DiscordBot image. Context is LaDOSE.Src, same as LaDOSE.Src/Dockerfile,
|
||||
# so the two share LaDOSE.Src/.dockerignore — hence the LaDOSE.DiscordBot/ prefix on every
|
||||
# COPY below. docker-compose.yml passes `dockerfile: LaDOSE.DiscordBot/Dockerfile`.
|
||||
#
|
||||
# The context has to be the whole of LaDOSE.Src, not this directory: the bot pulls in
|
||||
# LaDOSE.REST -> LaDOSE.DTO by ProjectReference, and Libraries/ChallongeCSharpDriver.dll
|
||||
# by HintPath.
|
||||
ARG DOTNET_VERSION=9.0
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS build
|
||||
WORKDIR /src
|
||||
|
||||
# Release here, unlike the API image. Nothing in this project is gated on Debug — the
|
||||
# #if DEBUG / Condition="'$(Configuration)' == 'Debug'" pairs that force the API to build
|
||||
# Debug (OpenAPI, Scalar) have no equivalent in LaDOSE.DiscordBot.csproj.
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
|
||||
# Project files first so this layer survives every .cs edit. Restore under the same
|
||||
# Configuration as the publish below, matching LaDOSE.Src/Dockerfile.
|
||||
COPY global.json ./
|
||||
COPY LaDOSE.DiscordBot/LaDOSE.DiscordBot.csproj LaDOSE.DiscordBot/
|
||||
COPY LaDOSE.REST/LaDOSE.REST.csproj LaDOSE.REST/
|
||||
COPY LaDOSE.DTO/LaDOSE.DTO.csproj LaDOSE.DTO/
|
||||
RUN dotnet restore LaDOSE.DiscordBot/LaDOSE.DiscordBot.csproj -p:Configuration=${BUILD_CONFIGURATION}
|
||||
|
||||
COPY . .
|
||||
RUN dotnet publish LaDOSE.DiscordBot/LaDOSE.DiscordBot.csproj -c ${BUILD_CONFIGURATION} --no-restore -o /app/out
|
||||
|
||||
# The file on disk is Quotes.txt; Command/Public.cs:114 opens "quotes.txt". Windows does
|
||||
# not care, Linux does — without this the !Quote command throws FileNotFoundException
|
||||
# (LoadQuote, unlike LoadCards, does not catch it). A copy rather than a rename, so the
|
||||
# name the .csproj lists keeps working too.
|
||||
RUN if [ -f /app/out/Quotes.txt ] && [ ! -f /app/out/quotes.txt ]; then \
|
||||
cp /app/out/Quotes.txt /app/out/quotes.txt; \
|
||||
fi
|
||||
|
||||
# runtime, not aspnet: this is a console app with no Kestrel and no listening port.
|
||||
FROM mcr.microsoft.com/dotnet/runtime:${DOTNET_VERSION}
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=build /app/out/ ./
|
||||
COPY LaDOSE.DiscordBot/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
# WORKDIR is load-bearing, not cosmetic: Program.cs points its ConfigurationBuilder at
|
||||
# Directory.GetCurrentDirectory() for settings.json, and Public.cs reads questions.txt /
|
||||
# answers.txt / quotes.txt by bare relative path. All four sit in /app.
|
||||
#
|
||||
# The entrypoint renders settings.json from the environment before handing over; see the
|
||||
# script for why that indirection exists.
|
||||
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
||||
CMD ["dotnet", "LaDOSE.DiscordBot.dll"]
|
||||
@@ -13,7 +13,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
# LaDOSE.DiscordBot reads its configuration from ./settings.json and from nothing else:
|
||||
# Program.cs builds a ConfigurationBuilder with AddJsonFile("settings.json") and no
|
||||
# AddEnvironmentVariables(), so a LADOSE_* variable would be invisible to it. This script
|
||||
# renders that file at container start instead — the same indirection LaDOSE.WebApp's
|
||||
# entrypoint uses to turn LADOSE_API_BASE_URL into /config.js. One image, any token.
|
||||
#
|
||||
# It writes only when LADOSE_DISCORD_TOKEN is set. Left unset, whatever settings.json is
|
||||
# already at /app wins: the placeholder baked in by the build, or a file bind-mounted over
|
||||
# it. Doing both — mounting settings.json read-only *and* setting the variable — fails
|
||||
# here with EROFS rather than silently ignoring one of them.
|
||||
set -eu
|
||||
|
||||
settings_file=/app/settings.json
|
||||
|
||||
# Drop control characters (newlines included) so a value cannot break out of its string
|
||||
# literal, then escape backslashes before double quotes. A token containing " or \ stays
|
||||
# inert data.
|
||||
json_string() {
|
||||
printf '%s' "${1:-}" | tr -d '\001-\037' | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g'
|
||||
}
|
||||
|
||||
if [ -n "${LADOSE_DISCORD_TOKEN:-}" ]; then
|
||||
rest_url=${LADOSE_BOT_REST_URL:-http://api:5000}
|
||||
|
||||
# All five keys, always. Program.cs calls .ToString() on each of them at startup, so a
|
||||
# missing one is a NullReferenceException before the bot ever reaches Discord.
|
||||
cat >"$settings_file" <<EOF
|
||||
{
|
||||
"Discord": {
|
||||
"Token": "$(json_string "${LADOSE_DISCORD_TOKEN}")"
|
||||
},
|
||||
"Challonge": {
|
||||
"Token": "$(json_string "${LADOSE_CHALLONGE_API_KEY:-}")"
|
||||
},
|
||||
"REST": {
|
||||
"Url": "$(json_string "${rest_url}")",
|
||||
"User": "$(json_string "${LADOSE_BOT_REST_USER:-}")",
|
||||
"Password": "$(json_string "${LADOSE_BOT_REST_PASSWORD:-}")"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
# The token is deliberately not echoed.
|
||||
echo "settings.json: rendered from the environment (REST:Url=$rest_url)" >&2
|
||||
else
|
||||
echo "settings.json: LADOSE_DISCORD_TOKEN unset, using the file already at $settings_file" >&2
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
Reference in New Issue
Block a user