Skip to content

Commit

Permalink
Merge branch 'dev' into bugfix/7-sign-up-page-design
Browse files Browse the repository at this point in the history
  • Loading branch information
pospyra committed Aug 30, 2023
2 parents 751d70a + bbc4bc8 commit fce79ee
Show file tree
Hide file tree
Showing 63 changed files with 1,225 additions and 46 deletions.
27 changes: 26 additions & 1 deletion .github/workflows/continuous-delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,31 @@ jobs:
build-args: PROJECT_PORT=5090
push: true

build_emailer_service:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push Emailer Service
uses: docker/build-push-action@v4
with:
tags: tatihutii/leetwars_emailer:latest
context: ./backend
file: ./backend/LeetWars.Emailer/Dockerfile
build-args: PROJECT_PORT=5080
push: true

build_frontend:
runs-on: ubuntu-latest
steps:
Expand All @@ -107,7 +132,7 @@ jobs:

deploy_images:
runs-on: ubuntu-latest
needs: [ build_core_service, build_notifier_service, build_builder_service, build_frontend ]
needs: [ build_core_service, build_notifier_service, build_builder_service, build_emailer_service, build_frontend ]
steps:
- uses: actions/checkout@v3
- name: Update PROD images
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ By default, apps run on the following ports:
| --------------------- | ---- |
| LeetWars.**Core** | 5050 |
| LeetWars.**Notifier** | 5070 |
| LeetWars.**Emailer** | 5080 |
| LeetWars.**Builder** | 5090 |
| RabbitMQ | 5672 |

Expand Down
10 changes: 8 additions & 2 deletions backend/LeetWars.All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LeetWars.Core.Common", "Lee
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LeetWars.Core.BLL", "LeetWars.Core\LeetWars.Core.BLL\LeetWars.Core.BLL.csproj", "{0BF81DD6-4BFA-4047-AD37-3C9CAE8E1040}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LeetWars.RabbitMQ", "LeetWars.RabbitMQ\LeetWars.RabbitMQ.csproj", "{CD4A8632-3C4D-48BF-83C0-6C41C2A522D2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LeetWars.RabbitMQ", "LeetWars.RabbitMQ\LeetWars.RabbitMQ.csproj", "{CD4A8632-3C4D-48BF-83C0-6C41C2A522D2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LeetWars.Builder", "LeetWars.Builder\LeetWars.Builder.csproj", "{75EF42F7-2F18-449F-ADAD-D665992606E6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LeetWars.Builder", "LeetWars.Builder\LeetWars.Builder.csproj", "{75EF42F7-2F18-449F-ADAD-D665992606E6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LeetWars.Emailer", "LeetWars.Emailer\LeetWars.Emailer.csproj", "{C61186C3-19AC-4771-8047-DAA02B91A888}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -51,6 +53,10 @@ Global
{75EF42F7-2F18-449F-ADAD-D665992606E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75EF42F7-2F18-449F-ADAD-D665992606E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75EF42F7-2F18-449F-ADAD-D665992606E6}.Release|Any CPU.Build.0 = Release|Any CPU
{C61186C3-19AC-4771-8047-DAA02B91A888}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C61186C3-19AC-4771-8047-DAA02B91A888}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C61186C3-19AC-4771-8047-DAA02B91A888}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C61186C3-19AC-4771-8047-DAA02B91A888}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
24 changes: 24 additions & 0 deletions backend/LeetWars.Builder/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using LeetWars.RabbitMQ;
using Microsoft.Extensions.Options;
using RabbitMQ.Client;

namespace LeetWars.Builder.Extensions
{
public static class ServiceCollectionExtensions
{
public static void RegisterProduceMessagesServices(this IServiceCollection services, IConfiguration configuration)
{
services.Configure<ConsumerSettings>(configuration.GetSection("RabbitMQConsumer"));

services.AddSingleton(con => new ConnectionFactory()
{
Uri = new Uri(configuration["Rabbit"])
}
.CreateConnection());

services.AddSingleton(sp => sp.GetRequiredService<IOptions<ConsumerSettings>>().Value);
services.AddSingleton<IConsumerService, ConsumerService>();
}

}
}
4 changes: 4 additions & 0 deletions backend/LeetWars.Builder/LeetWars.Builder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\LeetWars.RabbitMQ\LeetWars.RabbitMQ.csproj" />
</ItemGroup>

</Project>
9 changes: 8 additions & 1 deletion backend/LeetWars.Builder/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
using LeetWars.Builder.Extensions;
using LeetWars.Builder.Services;

var builder = WebApplication.CreateBuilder(args);

builder.Services.RegisterProduceMessagesServices(builder.Configuration);
builder.Services.AddHostedService<ConsumeMessages>();

var app = builder.Build();

app.MapGet("/", () => "Hello World!");
app.MapGet("/", () => "Hello, world!");

app.Run();
32 changes: 32 additions & 0 deletions backend/LeetWars.Builder/Services/ConsumeMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using LeetWars.RabbitMQ;
using RabbitMQ.Client.Events;
using System.Text;

namespace LeetWars.Builder.Services
{
public class ConsumeMessages : BackgroundService
{
private readonly IConsumerService _consumerService;

public ConsumeMessages(IConsumerService consumerService)
{
_consumerService = consumerService;
}

protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
var handler = new EventHandler<BasicDeliverEventArgs>((model, args) =>
{
var body = args.Body.ToArray();
var message = Encoding.UTF8.GetString(body).Replace('"', '\0');
Console.WriteLine(message);
_consumerService.SetAcknowledge(args.DeliveryTag, true);
});

_consumerService.Listen(handler);
return Task.CompletedTask;
}
}
}
9 changes: 8 additions & 1 deletion backend/LeetWars.Builder/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"Rabbit": "amqp://guest:guest@localhost:5672",
"RabbitMQConsumer": {
"ExchangeName": "LeetWarsExchange",
"ExchangeType": "direct",
"RoutingKey": "LeetWars",
"QueueName": "LeetWarsQueue"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace LeetWars.Core.BLL.Interfaces
{
public interface IMessageSenderService
{
void SendMessageToRabbitMQ(object obj);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

<ItemGroup>
<PackageReference Include="AutoMapper" Version="11.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\LeetWars.RabbitMQ\LeetWars.RabbitMQ.csproj" />
<ProjectReference Include="..\LeetWars.Core.Common\LeetWars.Core.Common.csproj" />
<ProjectReference Include="..\LeetWars.Core.DAL\LeetWars.Core.DAL.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using LeetWars.Core.BLL.Interfaces;
using LeetWars.RabbitMQ;
using RabbitMQ.Client;

namespace LeetWars.Core.BLL.Services
{
public class MessageSenderService : IMessageSenderService
{
private readonly IProducerService _producerService;

public MessageSenderService(IProducerService producerService)
{
_producerService = producerService;
}

public void SendMessageToRabbitMQ(object obj)
{
_producerService.Send(obj, ExchangeType.Direct);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,40 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.IdentityModel.Tokens;
using LeetWars.RabbitMQ;
using RabbitMQ.Client;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace LeetWars.Core.WebAPI.Extentions
{
public static class ServiceCollectionExtensions
{
public static void RegisterCustomServices(this IServiceCollection services)
public static void RegisterCustomServices(this IServiceCollection services, IConfiguration configuration)
{
services
.AddControllers()
.AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

services.AddScoped<IMessageSenderService, MessageSenderService>();
services.AddTransient<IChallengeService, ChallengeService>();
services.AddTransient<ITagService, TagService>();
services.AddTransient<ILanguageService, LanguageService>();
services.AddScoped<IUserService, UserService>();
services.AddScoped<IUserService, UserService>();
}

public static void AddRabbitMqServices(this IServiceCollection services, IConfiguration configuration)
{
services.Configure<ProducerSettings>(configuration.GetSection("RabbitMQProducer"));
services.AddSingleton(sp =>
{
var rabbitUri = new Uri(configuration["Rabbit"]);
var factory = new ConnectionFactory { Uri = rabbitUri };
return factory.CreateConnection();
});
services.AddSingleton(sp => sp.GetRequiredService<IOptions<ProducerSettings>>().Value);
services.AddSingleton<IProducerService, ProducerService>();
}

public static void AddAutoMapper(this IServiceCollection services)
Expand Down Expand Up @@ -58,7 +75,7 @@ public static void AddFirebaseAuthentication(this IServiceCollection services, I
var tokenIssuerBaseUrl = firebaseSettings["TokenIssuerBaseUrl"] ?? "";
var appName = firebaseSettings["AppName"] ?? "";
var tokenIssuerUrl = $"{tokenIssuerBaseUrl}/{appName}";

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -22,6 +22,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\LeetWars.RabbitMQ\LeetWars.RabbitMQ.csproj" />
<ProjectReference Include="..\LeetWars.Core.BLL\LeetWars.Core.BLL.csproj" />
<ProjectReference Include="..\LeetWars.Core.Common\LeetWars.Core.Common.csproj" />
</ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions backend/LeetWars.Core/LeetWars.Core.WebAPI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
.Build();

builder.Services.AddControllers();
builder.Services.AddLeetWarsCoreContext(builder.Configuration);
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.RegisterCustomServices();
builder.Services.AddLeetWarsCoreContext(builder.Configuration);
builder.Services.AddRabbitMqServices(builder.Configuration);
builder.Services.RegisterCustomServices(builder.Configuration);
builder.Services.AddAutoMapper();
builder.Services.AddSwaggerGen();
builder.Services.AddValidation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dotnetRunMessages": true,
"launchBrowser": false,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5050",
"applicationUrl": "http://localhost:5050",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
11 changes: 9 additions & 2 deletions backend/LeetWars.Core/LeetWars.Core.WebAPI/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"LeetWarsCoreDBConnection": "Server=localhost;Database=LeetWarsCoreDB;Trusted_Connection=True;"
},
"Firebase": {
"TokenIssuerBaseUrl": "https://securetoken.google.com",
"TokenIssuerBaseUrl": "https://securetoken.google.com",
"AppName": "leetwars"
},
"Logging": {
Expand All @@ -12,5 +12,12 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"Rabbit": "amqp://guest:guest@localhost:5672",
"RabbitMQProducer": {
"ExchangeName": "LeetWarsExchange",
"ExchangeType": "direct",
"RoutingKey": "LeetWars",
"QueueName": "LeetWarsQueue"
}
}
21 changes: 21 additions & 0 deletions backend/LeetWars.Emailer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
ARG PROJECT_PORT
WORKDIR /app
EXPOSE $PROJECT_PORT

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["LeetWars.Emailer/LeetWars.Emailer.csproj", "LeetWars.Emailer/"]
RUN dotnet restore "LeetWars.Emailer/LeetWars.Emailer.csproj"
COPY ./LeetWars.Emailer ./LeetWars.Emailer
WORKDIR "/src/LeetWars.Emailer"
RUN dotnet build "LeetWars.Emailer.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "LeetWars.Emailer.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV ASPNETCORE_URLS http://*:5080
ENTRYPOINT ["dotnet", "LeetWars.Emailer.dll"]
15 changes: 15 additions & 0 deletions backend/LeetWars.Emailer/LeetWars.Emailer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>e0295497-f79f-4c7d-a0b3-0caebcd03f17</UserSecretsId>
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.2" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions backend/LeetWars.Emailer/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello World!");

app.Run();
Loading

0 comments on commit fce79ee

Please sign in to comment.