From 044e4c87d9364980c92543618ac03bf8c55d2856 Mon Sep 17 00:00:00 2001 From: Toastie Date: Tue, 18 Jun 2024 23:48:54 +1200 Subject: [PATCH] Added Core repo files --- .dockerignore | 13 ++++++++++++ Dockerfile | 46 +++++++++++++++++++++++++++++++++++++++++++ EllieBot.sln | 17 +++++++++------- NuGet.Config | 6 ++++++ README.md | 2 ++ docker-entrypoint.sh | 28 ++++++++++++++++++++++++++ migrate.ps1 | 9 +++++++++ remove-migrations.ps1 | 3 +++ 8 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 .dockerignore create mode 100644 NuGet.Config create mode 100644 docker-entrypoint.sh create mode 100644 migrate.ps1 create mode 100644 remove-migrations.ps1 diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c84eea1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +# Ignore all files +* + +# Don't ignore nugetconfig +!./NuGet.Config + +# Don't ignore src projects +!src/** +!docker-entrypoint.sh + +# ignore bin and obj folders in projects +src/**/bin/* +src/**/obj/* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e69de29..dcdedcf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -0,0 +1,46 @@ +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +WORKDIR /source + +COPY src/Ellie.Marmalade/*.csproj src/Ellie.Marmalade/ +COPY src/EllieBot/*.csproj src/EllieBot/ +COPY src/EllieBot.Coordinator/*.csproj src/EllieBot.Coordinator/ +COPY src/EllieBot.Generators/*.csproj src/EllieBot.Generators/ +COPY src/EllieBot.Voice/*.csproj src/EllieBot.Voice/ +COPY NuGet.Config ./ +RUN dotnet restore src/EllieBot/ + +COPY . . +WORKDIR /source/src/EllieBot +RUN set -xe; \ + dotnet --version; \ + dotnet publish -c Release -o /app --no-restore; \ + mv /app/data /app/data_init; \ + rm -Rf libopus* libsodium* opus.* runtimes/win* runtimes/osx* runtimes/linux-arm* runtimes/linux-mips*; \ + find /app -type f -exec chmod -x {} \; ;\ + chmod +x /app/EllieBot + +# final stage/image +FROM mcr.microsoft.com/dotnet/runtime:6.0 +WORKDIR /app + +RUN set -xe; \ + useradd -m ellie; \ + apt-get update; \ + apt-get install -y --no-install-recommends libopus0 libsodium23 libsqlite3-0 curl ffmpeg python3 sudo; \ + update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1; \ + echo 'Defaults>ellie env_keep+="ASPNETCORE_* DOTNET_* EllieBot_* shard_id total_shards TZ"' > /etc/sudoers.d/ellie; \ + curl -Lo /usr/local/bin/yt-dlp https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp; \ + chmod a+rx /usr/local/bin/yt-dlp; \ + apt-get autoremove -y; \ + apt-get autoclean -y + +COPY --from=build /app ./ +COPY docker-entrypoint.sh /usr/local/sbin + +ENV shard_id=0 +ENV total_shards=1 +ENV EllieBot__creds=/app/data/creds.yml + +VOLUME [" /app/data "] +ENTRYPOINT [ "/usr/local/sbin/docker-entrypoint.sh" ] +CMD dotnet EllieBot.dll "$shard_id" "$total_shards" diff --git a/EllieBot.sln b/EllieBot.sln index 5a74f26..be95d55 100644 --- a/EllieBot.sln +++ b/EllieBot.sln @@ -10,11 +10,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution CHANGELOG.md = CHANGELOG.md Dockerfile = Dockerfile LICENSE = LICENSE + migrate.ps1 = migrate.ps1 + NuGet.Config = NuGet.Config README.md = README.md + remove-migrations.ps1 = remove-migrations.ps1 TODO.md = TODO.md EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EllieBot", "src\EllieBot\EllieBot.csproj", "{BCB21472-84D2-4B63-B5DD-31E6A3EC9791}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EllieBot", "src\EllieBot\EllieBot.csproj", "{4D9001F7-B3E8-48FE-97AA-CFD36DA65A64}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EllieBot.Tests", "src\EllieBot.Tests\EllieBot.Tests.csproj", "{179DF3B3-AD32-4335-8231-9818338DF3A2}" EndProject @@ -26,7 +29,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EllieBot.VotesApi", "src\El EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ellie.Marmalade", "src\Ellie.Marmalade\Ellie.Marmalade.csproj", "{76AC715D-12FF-4CBE-9585-A861139A2D0C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EllieBot.Voice", "src\EllieBot.Voice\EllieBot.Voice.csproj", "{1D93CE3C-80B4-49C7-A9A2-99988920AAEC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EllieBot.Voice", "src\EllieBot.Voice\EllieBot.Voice.csproj", "{1D93CE3C-80B4-49C7-A9A2-99988920AAEC}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -34,10 +37,10 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {BCB21472-84D2-4B63-B5DD-31E6A3EC9791}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BCB21472-84D2-4B63-B5DD-31E6A3EC9791}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BCB21472-84D2-4B63-B5DD-31E6A3EC9791}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BCB21472-84D2-4B63-B5DD-31E6A3EC9791}.Release|Any CPU.Build.0 = Release|Any CPU + {4D9001F7-B3E8-48FE-97AA-CFD36DA65A64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4D9001F7-B3E8-48FE-97AA-CFD36DA65A64}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4D9001F7-B3E8-48FE-97AA-CFD36DA65A64}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4D9001F7-B3E8-48FE-97AA-CFD36DA65A64}.Release|Any CPU.Build.0 = Release|Any CPU {179DF3B3-AD32-4335-8231-9818338DF3A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {179DF3B3-AD32-4335-8231-9818338DF3A2}.Debug|Any CPU.Build.0 = Debug|Any CPU {179DF3B3-AD32-4335-8231-9818338DF3A2}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -67,7 +70,7 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {BCB21472-84D2-4B63-B5DD-31E6A3EC9791} = {B28FB883-9688-41EB-BF5A-945F4A4EB628} + {4D9001F7-B3E8-48FE-97AA-CFD36DA65A64} = {B28FB883-9688-41EB-BF5A-945F4A4EB628} {179DF3B3-AD32-4335-8231-9818338DF3A2} = {B28FB883-9688-41EB-BF5A-945F4A4EB628} {A631DDF0-3AD1-4CB9-8458-314B1320868A} = {B28FB883-9688-41EB-BF5A-945F4A4EB628} {CB1A5307-DD85-4795-8A8A-A25D36DADC51} = {B28FB883-9688-41EB-BF5A-945F4A4EB628} diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 0000000..7e64704 --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + diff --git a/README.md b/README.md index 0f9c1bd..452254f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Ellie +[![Please don't upload to GitHub](https://nogithub.codeberg.page/badge.svg)](https://nogithub.codeberg.page) + ## Small disclaimer All the code in this repo may not be production ready yet and if you want to try and run a version of this by yourself you are on your own. diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..3f3fbd3 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,28 @@ +#!/bin/sh +set -e; + +data_init=/app/data_init +data=/app/data + +# populate /app/data if empty +for i in $(ls $data_init) +do + if [ ! -e "$data/$i" ]; then + [ -f "$data_init/$i" ] && cp "$data_init/$i" "$data/$i" + [ -d "$data_init/$i" ] && cp -r "$data_init/$i" "$data/$i" + fi +done + +# creds.yml migration +if [ -f /app/creds.yml ]; then + echo "Default location for creds.yml is now /app/data/creds.yml." + echo "Please move your creds.yml and update your docker-compose.yml accordingly." + + export Ellie_creds=/app/creds.yml +fi + +# ensure ellie can write on /app/data +chown -R ellie:ellie "$data" + +# drop to regular user and launch command +exec sudo -u ellie "$@" \ No newline at end of file diff --git a/migrate.ps1 b/migrate.ps1 new file mode 100644 index 0000000..a5ff6c4 --- /dev/null +++ b/migrate.ps1 @@ -0,0 +1,9 @@ +if ($args.Length -eq 0) { + Write-Host "Please provide a migration name." -ForegroundColor Red +} +else { + $migrationName = $args[0] + dotnet ef migrations add $migrationName -c SqliteContext -p src/EllieBot/EllieBot.csproj + dotnet ef migrations add $migrationName -c PostgreSqlContext -p src/EllieBot/EllieBot.csproj + dotnet ef migrations add $migrationName -c MysqlContext -p src/EllieBot/EllieBot.csproj +} \ No newline at end of file diff --git a/remove-migrations.ps1 b/remove-migrations.ps1 new file mode 100644 index 0000000..5445dbb --- /dev/null +++ b/remove-migrations.ps1 @@ -0,0 +1,3 @@ +dotnet ef migrations remove -c SqliteContext -f -p src/EllieBot/EllieBot.csproj +dotnet ef migrations remove -c PostgreSqlContext -f -p src/EllieBot/EllieBot.csproj +dotnet ef migrations remove -c MysqlContext -f -p src/EllieBot/EllieBot.csproj \ No newline at end of file