Compare commits

..

3 commits

Author SHA1 Message Date
alvaron14
bfd2dc4fc6 Update azure-pipelines.yml for Azure Pipelines 2020-12-29 02:36:40 +01:00
alvaron14
5dc16a2880 Update azure-pipelines.yml for Azure Pipelines 2020-12-28 21:58:24 +01:00
alvaron14
b21b1f87b8 Set up CI with Azure Pipelines
[skip ci]
2020-12-28 21:12:27 +01:00
79 changed files with 75 additions and 2450 deletions

1
.gitignore vendored
View file

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

View file

@ -1,16 +1,18 @@
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
{
@ -23,16 +25,22 @@ namespace Bot_Discord_CSharp
public async Task RunAsync()
{
string token, prefix;
if (Environment.GetEnvironmentVariable("TOKEN") != null)
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
{
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,31 +1,19 @@
<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-rc1" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.0.0-rc1" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.0.0-rc1" />
<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="HtmlAgilityPack" Version="1.11.28" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<None Update="Properties\launchSettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions>
<ProjectExtensions><VisualStudio><UserProperties config_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
</Project>

View file

@ -1,26 +0,0 @@
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

@ -0,0 +1,18 @@
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,29 +5,11 @@ using System.Text;
namespace Bot_Discord_CSharp.Dto
{
class ProfilesDto
class ConfigDto
{
[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")]
[JsonProperty("token")]
public string Token { get; private set; }
[JsonProperty("PREFIX")]
[JsonProperty("Prefix")]
public string Prefix { get; private set; }
}
}

View file

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

View file

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

View file

@ -1,26 +0,0 @@
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

Binary file not shown.

Binary file not shown.

View file

@ -1,9 +0,0 @@
{
"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.

Binary file not shown.

View file

@ -1,28 +0,0 @@
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"]

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.

View file

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

22
azure-pipelines.yml Normal file
View file

@ -0,0 +1,22 @@
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
publishWebProjects: false
projects: '**/*.csproj'

View file

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