Compare commits

...
Sign in to create a new pull request.

2 commits

Author SHA1 Message Date
Álvaro Gómez Cuenca
a3c9481f3f Required push 2020-12-28 21:25:12 +01:00
Álvaro Gómez Cuenca
5e0939db3d Docker sync finished 2020-12-09 20:34:49 +01:00
78 changed files with 2450 additions and 53 deletions

1
.gitignore vendored
View file

@ -3,6 +3,7 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
config.json
launchSettings.json
# User-specific files
*.rsuser

View file

@ -1,18 +1,16 @@
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.EventArgs;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Bot_Discord_CSharp.Dto;
using Bot_Discord_CSharp.Commands;
using Microsoft.Extensions.Logging;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions;
using DSharpPlus.Entities;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using Bot_Discord_CSharp.Dto;
namespace Bot_Discord_CSharp
{
@ -25,22 +23,16 @@ namespace Bot_Discord_CSharp
public async Task RunAsync()
{
string token, prefix;
if (!Environment.GetEnvironmentVariables().Contains("TOKEN"))
{
var json = string.Empty;
using (var fs = File.OpenRead(@"E:\Proyectos Visual Studio\Bot_Discord_CSharp\Bot_Discord_CSharp\config.json"))
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
json = await sr.ReadToEndAsync().ConfigureAwait(false);
var configJson = JsonConvert.DeserializeObject<ConfigDto>(json);
token = configJson.Token;
prefix = configJson.Prefix;
}
else
if (Environment.GetEnvironmentVariable("TOKEN") != null)
{
token = Environment.GetEnvironmentVariable("TOKEN");
prefix = Environment.GetEnvironmentVariable("PREFIX");
} else
{
ProfilesDto profiles = JsonConvert.DeserializeObject<ProfilesDto>(System.IO.File.ReadAllText("./launchSettings.json"));
SecretsDto secrets = profiles.Bot_Discord_CSharp.EnvironmentVariables.Secrets;
token = secrets.Token;
prefix = secrets.Prefix;
}
var config = new DiscordConfiguration

View file

@ -1,19 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputType>exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<StartupObject>Bot_Discord_CSharp.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DSharpPlus" Version="4.0.0-nightly-00760" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.0.0-nightly-00760" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.0.0-nightly-00760" />
<PackageReference Include="DSharpPlus" Version="4.0.0-rc1" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.0.0-rc1" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.0.0-rc1" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.28" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties config_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<None Update="Properties\launchSettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions>
</Project>

View file

@ -0,0 +1,26 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.sln .
COPY Bot_Discord_CSharp/*.csproj ./aspnetapp/
#COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY Bot_Discord_CSharp/. ./aspnetapp/
WORKDIR /app/aspnetapp
#COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 as runtime
WORKDIR /app
COPY --from=build /app/aspnetapp/out ./
#COPY --from=build-env /app/out .
#COPY config.json ./
COPY Properties/launchSettings.json ./
ENTRYPOINT ["dotnet", "Bot_Discord_CSharp.dll"]

View file

@ -1,18 +0,0 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .
#COPY config.json ./
ENTRYPOINT ["dotnet", "Bot_Discord_CSharp.dll"]

View file

@ -5,11 +5,29 @@ using System.Text;
namespace Bot_Discord_CSharp.Dto
{
class ConfigDto
class ProfilesDto
{
[JsonProperty("token")]
[JsonProperty("profiles")]
public Bot_Discord_CSharpDto Bot_Discord_CSharp { get; private set; }
}
class Bot_Discord_CSharpDto
{
[JsonProperty("Bot_Discord_CSharp")]
public EnvironmentVariablesDto EnvironmentVariables { get; private set; }
}
class EnvironmentVariablesDto
{
[JsonProperty("environmentVariables")]
public SecretsDto Secrets { get; private set; }
}
class SecretsDto
{
[JsonProperty("TOKEN")]
public string Token { get; private set; }
[JsonProperty("Prefix")]
[JsonProperty("PREFIX")]
public string Prefix { get; private set; }
}
}

View file

@ -0,0 +1,6 @@
heroku container:login
docker build -t discord-bot-dsharp "E:\Proyectos Visual Studio\Bot_Discord_CSharp\Bot_Discord_CSharp\bin\Release\netcoreapp3.1\publish"
docker tag discord-bot-dsharp registry.heroku.com/discord-bot-dsharp/worker
docker push registry.heroku.com/discord-bot-dsharp/worker
heroku container:release worker --app discord-bot-dsharp
heroku container:push release --app discord-bot-dsharp

View file

@ -1,12 +1,8 @@
using Microsoft.AspNetCore.Hosting;
using System;
using System.IO;
namespace Bot_Discord_CSharp
namespace Bot_Discord_CSharp
{
class Program
public class Program
{
static void Main(string[] args)
public static void Main(string[] args)
{
Bot bot = new Bot();
bot.RunAsync().GetAwaiter().GetResult();

View file

@ -1,5 +1,8 @@
version: "3"
services:
bot:
build: .
image: mydiscordbot
image: mydiscordbot

26
Dockerfile Normal file
View file

@ -0,0 +1,26 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.sln .
COPY Bot_Discord_CSharp/*.csproj ./aspnetapp/
#COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY Bot_Discord_CSharp/. ./aspnetapp/
WORKDIR /app/aspnetapp
#COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 as runtime
WORKDIR /app
COPY --from=build /app/aspnetapp/out ./
#COPY --from=build-env /app/out .
#COPY config.json ./
COPY Properties/launchSettings.json ./
ENTRYPOINT ["dotnet", "Bot_Discord_CSharp.dll"]

File diff suppressed because it is too large Load diff

BIN
app/Bot_Discord_CSharp.dll Normal file

Binary file not shown.

BIN
app/Bot_Discord_CSharp.exe Normal file

Binary file not shown.

View file

@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "netcoreapp3.1",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "3.1.0"
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
app/DSharpPlus.dll Normal file

Binary file not shown.

28
app/Dockerfile Normal file
View file

@ -0,0 +1,28 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.sln .
WORKDIR /.
COPY Bot_Discord_CSharp/*.csproj ./aspnetapp/
WORKDIR /app
#COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY Bot_Discord_CSharp/. ./aspnetapp/
WORKDIR /app/aspnetapp
#COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 as runtime
WORKDIR /app
COPY --from=build /app/aspnetapp/out ./
#COPY --from=build-env /app/out .
#COPY config.json ./
COPY Properties/launchSettings.json ./
ENTRYPOINT ["dotnet", "Bot_Discord_CSharp.dll"]

BIN
app/Emzi0767.Common.dll Normal file

Binary file not shown.

BIN
app/HtmlAgilityPack.dll Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
app/Newtonsoft.Json.dll Normal file

Binary file not shown.

BIN
app/System.IO.Pipelines.dll Normal file

Binary file not shown.

Binary file not shown.

8
app/docker-compose.yml Normal file
View file

@ -0,0 +1,8 @@
version: "3"
services:
bot:
build: .
image: mydiscordbot

8
docker-compose.yml Normal file
View file

@ -0,0 +1,8 @@
version: "3"
services:
bot:
build: .
image: mydiscordbot