Skip to content

Commit

Permalink
Merge pull request #18 from sentemon/gateway-microservice
Browse files Browse the repository at this point in the history
  • Loading branch information
sentemon authored Jan 5, 2025
2 parents 1023925 + 38662e8 commit 5c61dd7
Show file tree
Hide file tree
Showing 32 changed files with 658 additions and 300 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/compose-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ jobs:
run: |
echo "Checking health..."
for i in {1..10}; do
curl --fail http://0.0.0.0:8082/health && break || sleep 5
curl --fail http://0.0.0.0:8000/auth/health && break || sleep 5
done
curl --fail http://0.0.0.0:8082/health || exit 1
curl --fail http://0.0.0.0:8000/auth/health || exit 1
- name: Health Check PostService
run: |
echo "Checking health..."
for i in {1..10}; do
curl --fail http://0.0.0.0:8081/health && break || sleep 5
curl --fail http://0.0.0.0:8000/post/health && break || sleep 5
done
curl --fail http://0.0.0.0:8081/health || exit 1
curl --fail http://0.0.0.0:8000/post/health || exit 1
13 changes: 13 additions & 0 deletions FitnessApp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build-and-test", "build-and
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared.DTO", "backend\src\Shared\Shared.DTO\Shared.DTO.csproj", "{334DF17C-BD69-47B9-B4D0-ACB5AD6223CF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Gateway", "backend\src\Gateway", "{DC9B9F00-24BF-4AD3-B45A-38BFCFC309D7}"
ProjectSection(SolutionItems) = preProject
backend\src\Gateway\Dockerfile = backend\src\Gateway\Dockerfile
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gateway", "backend\src\Gateway\Gateway\Gateway.csproj", "{830B4F05-7C89-4C0F-B27D-B1008B605E79}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -142,6 +149,10 @@ Global
{334DF17C-BD69-47B9-B4D0-ACB5AD6223CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{334DF17C-BD69-47B9-B4D0-ACB5AD6223CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{334DF17C-BD69-47B9-B4D0-ACB5AD6223CF}.Release|Any CPU.Build.0 = Release|Any CPU
{830B4F05-7C89-4C0F-B27D-B1008B605E79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{830B4F05-7C89-4C0F-B27D-B1008B605E79}.Debug|Any CPU.Build.0 = Debug|Any CPU
{830B4F05-7C89-4C0F-B27D-B1008B605E79}.Release|Any CPU.ActiveCfg = Release|Any CPU
{830B4F05-7C89-4C0F-B27D-B1008B605E79}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{2E44C019-ED30-4671-A878-D2F7B6071024} = {84AE3F00-9A59-4A8D-A737-67AB74E5D1FD}
Expand All @@ -167,5 +178,7 @@ Global
{499BA3B4-A81F-4079-B256-CC04927BB06D} = {D5A12D19-86E3-4E83-8BF0-D9AF8C2477F3}
{BC8EDBE4-B8BD-4934-B096-0C2E1C1E84C7} = {499BA3B4-A81F-4079-B256-CC04927BB06D}
{334DF17C-BD69-47B9-B4D0-ACB5AD6223CF} = {112E9C63-BF62-49C1-AD19-03855535225B}
{DC9B9F00-24BF-4AD3-B45A-38BFCFC309D7} = {B7E4E4CF-E7A9-4DAC-807E-DFF17553BAE8}
{830B4F05-7C89-4C0F-B27D-B1008B605E79} = {DC9B9F00-24BF-4AD3-B45A-38BFCFC309D7}
EndGlobalSection
EndGlobal
11 changes: 11 additions & 0 deletions backend/src/AuthService/AuthService.Api/GraphQL/Mutation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ public Mutation(IHttpContextAccessor httpContextAccessor)
_httpContextAccessor = httpContextAccessor;
}


/* ToDo: When all the services are running in the docker that's it
System.Net.Http.HttpClient.KeycloakClient.LogicalHandler[100]
2025-01-05 22:30:39 Start processing HTTP request POST http://keycloak:8080/realms/fitness-app-realm/protocol/openid-connect/token
2025-01-05 22:30:39 info: System.Net.Http.HttpClient.KeycloakClient.ClientHandler[100]
2025-01-05 22:30:39 Sending HTTP request POST http://keycloak:8080/realms/fitness-app-realm/protocol/openid-connect/token
2025-01-05 22:30:39 info: System.Net.Http.HttpClient.KeycloakClient.ClientHandler[101]
2025-01-05 22:30:39 Received HTTP response headers after 91.8503ms - 404
2025-01-05 22:30:39 info: System.Net.Http.HttpClient.KeycloakClient.LogicalHandler[101]
2025-01-05 22:30:39 End processing HTTP request after 100.8284ms - 404
*/
public async Task<KeycloakTokenResponse> Register(RegisterDto input, [Service] RegisterCommandHandler registerCommandHandler)
{
var command = new RegisterCommand(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "graphql",
"applicationUrl": "http://localhost:8082",
"applicationUrl": "http://localhost:8001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand All @@ -24,7 +24,7 @@
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "graphql",
"applicationUrl": "https://localhost:7165;http://localhost:8082",
"applicationUrl": "https://localhost:7165;http://localhost:8001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
6 changes: 3 additions & 3 deletions backend/src/AuthService/AuthService.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
"AllowedHosts": "*",
"AllowedOrigins": [ "http://localhost:4000", "http://localhost:4200", "http://localhost:8080" ],
"DatabaseConnectionString": "Host=localhost;Port=5432;Username=postgres;Password=mysecretpasswordfordevelopment;Database=AuthDb",
"WebHostUrl": "http://0.0.0.0:8082",
"WebHostUrl": "http://0.0.0.0:8001",
"Keycloak": {
"Url": "http://localhost:8080",
"Realm": "fitness-app-realm",
"ClientId": "fitness-app-client",
"ClientSecret": "4mTuelQIWNfLw3HGfE3xAD3Bmyb5OHWN",
"ClientSecret": "7lGtugT2Dmwgi6gYJQnGZf5aO0Y9tzlh",
"AdminUsername": "admin",
"AdminPassword": "admin",
"PublicKey": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1Q/E+u/w56fl1C67jv2glu/wjy50re4UbVqJHX+T84hN8lGjiHRxqmEgdsyArhiXK0XBbbolPJ+jLTXY7KAKXXtsCjNOV/WLCKFi9Gdn2vgrmD+g2BatpRvO33nytwlDZSkZSnFpTY3io6ZcMCB+YQK5i+2QOz1gahJt5Dac+bwZ96d3x+dEP+0lZ3+3VTe0bKWRMDked2f8E4K9mvywyUEf3Ihe/2YVhXZyUnshMrRmn6ZZ4DvpQcrHMtGMCBiB5N6pllxBu5XAcxYPRxZtx+q4GSU1bCA9es4RNgLTBGP8GQXVVqlq80j8oxR1SSigqLNbA7qcGi4+rmWg/ohdkQIDAQAB"
"PublicKey": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuQXYfCuREUGjALqZ/iPLvqPAEBcCP4Knbwixdbe+jwhrMjX7n/azi+htI3egSAjlSlVvc5olSU2ykydCD2BqBgxMpNGoTa8dp96vDdTeMBD/semyOiSmJq4tqeKw2n7cjpI7jvoDP/HvH5b90SIsmmmUEHnjie3fakb0VccQxJdQXolNlCZfBytD0L8bBmuvPlQdgSoOxCuRakVz2NBErjx0SRxn0EltHdu1dEA0Ya+I7jeX3ZgbKe+R/oIuggYnnlh//wNXsfHGKKYsxxp/FQjItS2oq29aGPjTA6t3nt0Rysg66IbNxdMFg1nfREFKV7Qpb2IsC01k0s/r/+2BlwIDAQAB"
},
"RabbitMq": {
"Host": "localhost",
Expand Down
2 changes: 1 addition & 1 deletion backend/src/AuthService/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8081
EXPOSE 8001

RUN apt-get update && apt-get install -y curl && apt-get clean

Expand Down
28 changes: 28 additions & 0 deletions backend/src/Gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8000

RUN apt-get update && apt-get install -y curl && apt-get clean

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

WORKDIR /src

COPY Gateway/Gateway/Gateway.csproj Gateway/Gateway/

RUN dotnet restore Gateway/Gateway/Gateway.csproj

COPY . .

WORKDIR /src/Gateway/Gateway

RUN dotnet build Gateway.csproj -c Release -o /app/build

FROM build AS publish
RUN dotnet publish Gateway.csproj -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

ENTRYPOINT ["dotnet", "Gateway.dll"]
8 changes: 8 additions & 0 deletions backend/src/Gateway/Gateway/Constants/AppSettingsConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Gateway.Constants;

public class AppSettingsConstants
{
public const string WebHostUrl = "WebHostUrl";
public const string AllowedOrigins = "AllowedOrigins";
public const string ReverseProxy = "ReverseProxy";
}
6 changes: 6 additions & 0 deletions backend/src/Gateway/Gateway/Constants/CorsConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Gateway.Constants;

public class CorsConstants
{
public const string CorsPolicy = "CorsPolicy";
}
13 changes: 13 additions & 0 deletions backend/src/Gateway/Gateway/Gateway.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Yarp.ReverseProxy" Version="2.2.0" />
</ItemGroup>

</Project>
42 changes: 42 additions & 0 deletions backend/src/Gateway/Gateway/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Gateway.Constants;

var builder = WebApplication.CreateBuilder(args);

var allowedOrigins = builder.Configuration.GetSection(AppSettingsConstants.AllowedOrigins).Get<string[]>();
var hostingUrl = builder.Configuration[AppSettingsConstants.WebHostUrl];
var reverseProxyConfig = builder.Configuration.GetSection(AppSettingsConstants.ReverseProxy);

builder.WebHost.UseUrls(hostingUrl ?? throw new ArgumentNullException(nameof(hostingUrl), "Hosting URL is not configured."));

builder.Services
.AddCors(options =>
{
options.AddPolicy(CorsConstants.CorsPolicy, policyBuilder =>
{
policyBuilder
.WithOrigins(allowedOrigins ?? throw new ArgumentNullException(nameof(allowedOrigins),
"Allowed Origin URLs are not configured."))
.AllowCredentials()
.AllowAnyHeader()
.AllowAnyMethod();
});
});

builder.Services
.AddReverseProxy()
.LoadFromConfig(reverseProxyConfig);

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
app.UseHttpsRedirection();
}

app.UseCors(CorsConstants.CorsPolicy);

app.MapReverseProxy();

app.MapGet("/health" ,() => Results.Ok("Healthy"));

app.Run();
41 changes: 41 additions & 0 deletions backend/src/Gateway/Gateway/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:37518",
"sslPort": 44340
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "",
"applicationUrl": "http://localhost:8000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "",
"applicationUrl": "https://localhost:7204;http://localhost:8000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
54 changes: 54 additions & 0 deletions backend/src/Gateway/Gateway/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"WebHostUrl": "http://0.0.0.0:8000",
"AllowedOrigins": [ "http://localhost:4200", "http://localhost:8080" ],
"ReverseProxy": {
"Routes": {
"AuthService": {
"ClusterId": "auth-service",
"Match": {
"Path": "/auth/{endpoint:regex(^graphql$|^health$)}"
},
"Transforms": [
{
"PathRemovePrefix": "/auth"
}
]
},
"PostService": {
"ClusterId": "post-service",
"Match": {
"Path": "/post/{endpoint:regex(^graphql$|^health$)}"
},
"Transforms": [
{
"PathRemovePrefix": "/post"
}
],
"WebSocket": true
}
},
"Clusters": {
"auth-service": {
"Destinations": {
"destination1": {
"Address": "http://localhost:8001"
}
}
},
"post-service": {
"Destinations": {
"destination1": {
"Address": "http://localhost:8002"
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion backend/src/PostService/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8081
EXPOSE 8002

RUN apt-get update && apt-get install -y curl && apt-get clean

Expand Down
Loading

0 comments on commit 5c61dd7

Please sign in to comment.