Adding multiple projects & API
This commit is contained in:
parent
91e36a811d
commit
441bcc4e96
1
Docker/start.sh
Normal file
1
Docker/start.sh
Normal file
@ -0,0 +1 @@
|
|||||||
|
dotnet Kasbot.App.dll & ; dotnet Kasbot.API.dll & ; wait
|
@ -3,6 +3,7 @@ WORKDIR /App
|
|||||||
|
|
||||||
# Copy everything
|
# Copy everything
|
||||||
COPY ./Kasbot.APP ./Kasbot.APP
|
COPY ./Kasbot.APP ./Kasbot.APP
|
||||||
|
COPY ./Kasbot.API ./Kasbot.API
|
||||||
COPY ./Kasbot.sln ./Kasbot.sln
|
COPY ./Kasbot.sln ./Kasbot.sln
|
||||||
|
|
||||||
# Restore as distinct layers
|
# Restore as distinct layers
|
||||||
@ -13,7 +14,13 @@ RUN dotnet build -c Release -o out
|
|||||||
|
|
||||||
# Build runtime image
|
# Build runtime image
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:6.0
|
FROM mcr.microsoft.com/dotnet/aspnet:6.0
|
||||||
|
|
||||||
RUN apt update && apt install -y ffmpeg libopus-dev opus-tools libsodium-dev
|
RUN apt update && apt install -y ffmpeg libopus-dev opus-tools libsodium-dev
|
||||||
WORKDIR /App
|
WORKDIR /App
|
||||||
|
|
||||||
|
COPY Docker/start.sh .
|
||||||
|
RUN chmod +x start.sh
|
||||||
|
|
||||||
COPY --from=build-env /App/out .
|
COPY --from=build-env /App/out .
|
||||||
ENTRYPOINT ["dotnet", "Kasbot.App.dll"]
|
|
||||||
|
ENTRYPOINT ["./start.sh" ]
|
22
Kasbot.API/Controllers/ReadinessController.cs
Normal file
22
Kasbot.API/Controllers/ReadinessController.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Kasbot.API.Controllers
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class ReadinessController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ILogger<ReadinessController> logger;
|
||||||
|
|
||||||
|
public ReadinessController(ILogger<ReadinessController> logger)
|
||||||
|
{
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet(Name = "readiness")]
|
||||||
|
public IActionResult GetReadiness()
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
Kasbot.API/Controllers/StatusController.cs
Normal file
24
Kasbot.API/Controllers/StatusController.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using Kasbot.API.Services;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Kasbot.API.Controllers
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class StatusController : Controller
|
||||||
|
{
|
||||||
|
private readonly StatusService statusService;
|
||||||
|
|
||||||
|
public StatusController(StatusService statusService)
|
||||||
|
{
|
||||||
|
this.statusService = statusService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("ok")]
|
||||||
|
public async Task<IActionResult> IsOk()
|
||||||
|
{
|
||||||
|
var result = await statusService.IsOk();
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
Kasbot.API/Dockerfile
Normal file
22
Kasbot.API/Dockerfile
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
|
||||||
|
WORKDIR /app
|
||||||
|
EXPOSE 80
|
||||||
|
EXPOSE 443
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
||||||
|
WORKDIR /src
|
||||||
|
COPY ["Kasbot.API/Kasbot.API.csproj", "Kasbot.API/"]
|
||||||
|
RUN dotnet restore "Kasbot.API/Kasbot.API.csproj"
|
||||||
|
COPY . .
|
||||||
|
WORKDIR "/src/Kasbot.API"
|
||||||
|
RUN dotnet build "Kasbot.API.csproj" -c Release -o /app/build
|
||||||
|
|
||||||
|
FROM build AS publish
|
||||||
|
RUN dotnet publish "Kasbot.API.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||||
|
|
||||||
|
FROM base AS final
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=publish /app/publish .
|
||||||
|
ENTRYPOINT ["dotnet", "Kasbot.API.dll"]
|
30
Kasbot.API/Kasbot.API.csproj
Normal file
30
Kasbot.API/Kasbot.API.csproj
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<UserSecretsId>a8c1813f-fb5a-4771-868e-60e280ccaf77</UserSecretsId>
|
||||||
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Google.Protobuf" Version="3.25.1" />
|
||||||
|
<PackageReference Include="Grpc.Net.Client" Version="2.59.0" />
|
||||||
|
<PackageReference Include="Grpc.Tools" Version="2.59.0">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Kasbot.APP\Kasbot.App.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Protobuf Include="../Proto/status.proto" GrpcServices="Kasbot.API" Link="Protos\status.proto" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
11
Kasbot.API/Kasbot.API.csproj.user
Normal file
11
Kasbot.API/Kasbot.API.csproj.user
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<ActiveDebugProfile>Kasbot.API</ActiveDebugProfile>
|
||||||
|
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
|
||||||
|
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
34
Kasbot.API/Program.cs
Normal file
34
Kasbot.API/Program.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using Kasbot.API.Services;
|
||||||
|
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
private static void Main(string[] args)
|
||||||
|
{
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
// Add services to the container.
|
||||||
|
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
builder.Services.AddSwaggerGen();
|
||||||
|
builder.Services.AddScoped<StatusService>();
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
// Configure the HTTP request pipeline.
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
app.MapControllers();
|
||||||
|
|
||||||
|
app.Run();
|
||||||
|
}
|
||||||
|
}
|
38
Kasbot.API/Properties/launchSettings.json
Normal file
38
Kasbot.API/Properties/launchSettings.json
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"Kasbot.API": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
},
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"applicationUrl": "https://localhost:7174;http://localhost:5276"
|
||||||
|
},
|
||||||
|
"IIS Express": {
|
||||||
|
"commandName": "IISExpress",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Docker": {
|
||||||
|
"commandName": "Docker",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
|
||||||
|
"publishAllPorts": true,
|
||||||
|
"useSSL": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
|
"iisSettings": {
|
||||||
|
"windowsAuthentication": false,
|
||||||
|
"anonymousAuthentication": true,
|
||||||
|
"iisExpress": {
|
||||||
|
"applicationUrl": "http://localhost:47958",
|
||||||
|
"sslPort": 44359
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
Kasbot.API/Services/StatusService.cs
Normal file
19
Kasbot.API/Services/StatusService.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using Status;
|
||||||
|
using Grpc.Net.Client;
|
||||||
|
|
||||||
|
namespace Kasbot.API.Services
|
||||||
|
{
|
||||||
|
public class StatusService
|
||||||
|
{
|
||||||
|
public StatusService() { }
|
||||||
|
|
||||||
|
public async Task<bool> IsOk()
|
||||||
|
{
|
||||||
|
using var channel = GrpcChannel.ForAddress("https://localhost:7042");
|
||||||
|
var client = new StatusRequester.StatusRequesterClient(channel);
|
||||||
|
|
||||||
|
var reply = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });
|
||||||
|
return reply.Message == "Hello GreeterClient";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
Kasbot.API/appsettings.json
Normal file
9
Kasbot.API/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
22
Kasbot.APP/Internal/Services/StatusService.cs
Normal file
22
Kasbot.APP/Internal/Services/StatusService.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using Grpc.Core;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Status;
|
||||||
|
|
||||||
|
namespace Kasbot.App.Internal.Services
|
||||||
|
{
|
||||||
|
public class StatusService : StatusRequester.StatusRequesterBase
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
public StatusService(ILoggerFactory loggerFactory)
|
||||||
|
{
|
||||||
|
_logger = loggerFactory.CreateLogger<StatusService>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"Sending hello to {request.Name}");
|
||||||
|
return Task.FromResult(new HelloReply { Message = "Hello " + request.Name });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,8 +15,19 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Discord.Net" Version="3.12.0" />
|
<PackageReference Include="Discord.Net" Version="3.12.0" />
|
||||||
|
<PackageReference Include="Google.Protobuf" Version="3.25.1" />
|
||||||
|
<PackageReference Include="Grpc.AspNetCore" Version="2.59.0" />
|
||||||
|
<PackageReference Include="Grpc.Net.Client" Version="2.59.0" />
|
||||||
|
<PackageReference Include="Grpc.Tools" Version="2.59.0">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||||
<PackageReference Include="YoutubeExplode" Version="6.3.1" />
|
<PackageReference Include="YoutubeExplode" Version="6.3.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Protobuf Include="../Proto/status.proto" GrpcServices="Kasbot.App" Link="Protos\status.proto" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
using Google.Protobuf.WellKnownTypes;
|
||||||
|
using Kasbot.App.Internal.Services;
|
||||||
using Kasbot.Services;
|
using Kasbot.Services;
|
||||||
using Kasbot.Services.Internal;
|
using Kasbot.Services.Internal;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Kasbot
|
namespace Kasbot
|
||||||
{
|
{
|
||||||
class Program
|
public class Program
|
||||||
{
|
{
|
||||||
private static string TOKEN = Environment.GetEnvironmentVariable("TOKEN");
|
private static string TOKEN = Environment.GetEnvironmentVariable("TOKEN");
|
||||||
private static int SHARDS = int.Parse(Environment.GetEnvironmentVariable("SHARDS") ?? "0");
|
private static int SHARDS = int.Parse(Environment.GetEnvironmentVariable("SHARDS") ?? "0");
|
||||||
@ -24,17 +27,28 @@ namespace Kasbot
|
|||||||
SHARDS = 1;
|
SHARDS = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Task.Factory.StartNew(() => new Program().RunGrpc(args));
|
||||||
|
|
||||||
new Program()
|
new Program()
|
||||||
.MainAsync()
|
.MainAsync()
|
||||||
.GetAwaiter()
|
.GetAwaiter()
|
||||||
.GetResult();
|
.GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RunGrpc(string[] args)
|
||||||
|
{
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
builder.Services.AddGrpc();
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
app.MapGrpcService<StatusService>();
|
||||||
|
app.Run(url: "https://localhost:7042");
|
||||||
|
}
|
||||||
|
|
||||||
public async Task MainAsync()
|
public async Task MainAsync()
|
||||||
{
|
{
|
||||||
using (var services = ConfigureServices())
|
using (var services = ConfigureServices())
|
||||||
{
|
{
|
||||||
|
|
||||||
var client = services.GetRequiredService<DiscordShardedClient>();
|
var client = services.GetRequiredService<DiscordShardedClient>();
|
||||||
|
|
||||||
client.Log += LogAsync;
|
client.Log += LogAsync;
|
||||||
|
11
Kasbot.sln
11
Kasbot.sln
@ -5,6 +5,13 @@ VisualStudioVersion = 17.4.33213.308
|
|||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kasbot.App", "Kasbot.APP\Kasbot.App.csproj", "{BD715B63-0FC8-42F5-A449-9FF029B8E599}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kasbot.App", "Kasbot.APP\Kasbot.App.csproj", "{BD715B63-0FC8-42F5-A449-9FF029B8E599}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kasbot.API", "Kasbot.API\Kasbot.API.csproj", "{9FCC6B19-185A-4A50-912B-40C1C8530EC5}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Proto", "Proto", "{3A0D4589-E8B2-4485-BEF7-2A6237D6E5BA}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
status.proto = status.proto
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -15,6 +22,10 @@ Global
|
|||||||
{BD715B63-0FC8-42F5-A449-9FF029B8E599}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{BD715B63-0FC8-42F5-A449-9FF029B8E599}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{BD715B63-0FC8-42F5-A449-9FF029B8E599}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{BD715B63-0FC8-42F5-A449-9FF029B8E599}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{BD715B63-0FC8-42F5-A449-9FF029B8E599}.Release|Any CPU.Build.0 = Release|Any CPU
|
{BD715B63-0FC8-42F5-A449-9FF029B8E599}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{9FCC6B19-185A-4A50-912B-40C1C8530EC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{9FCC6B19-185A-4A50-912B-40C1C8530EC5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{9FCC6B19-185A-4A50-912B-40C1C8530EC5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{9FCC6B19-185A-4A50-912B-40C1C8530EC5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
19
Proto/status.proto
Normal file
19
Proto/status.proto
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package status;
|
||||||
|
|
||||||
|
// The greeting service definition.
|
||||||
|
service StatusRequester {
|
||||||
|
// Sends a greeting
|
||||||
|
rpc SayHello (HelloRequest) returns (HelloReply);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The request message containing the user's name.
|
||||||
|
message HelloRequest {
|
||||||
|
string name = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The response message containing the greetings
|
||||||
|
message HelloReply {
|
||||||
|
string message = 1;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user