Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade project #137

Merged
merged 11 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions .github/workflows/dev_build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build & run tests (dev)
on:
pull_request:
branches: [ dev ]

jobs:

dev-branch-check:
Expand All @@ -18,17 +18,18 @@ jobs:
steps:

- name: Checkout repository
uses: actions/checkout@v2.2.0
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Variable substitution appsettings file for Staging (NET Core)
uses: microsoft/variable-substitution@v1
- name: Variable substitution appsettings file for Development (NET Core)
uses: TomaszKandula/variable-substitution@v1.0.1
with:
files: ${{ github.workspace }}/EmailSender.WebApi/appsettings.Staging.json
files: ${{ github.workspace }}/EmailSender.Configuration/appsettings.Development.json
env:
ConnectionStrings.DbConnect: "${{ secrets.CONNECTIONSTRINGS__DBCONNECT_STAGE }}"
ConnectionStrings.DbConnectTest: "${{ secrets.CONNECTIONSTRINGS__DBCONNECT_TEST }}"
DbConnect: "${{ secrets.DBCONNECT_TEST }}"
AZ_Storage_ContainerName: "${{ secrets.STORAGE_CONTAINER_NAME_TEST }}"
AZ_Storage_ConnectionString: "${{ secrets.STORAGE_CONNECTION_STRING }}"

- name: Setup dotnet
uses: actions/setup-dotnet@v1
Expand All @@ -40,7 +41,7 @@ jobs:

- name: SonarQube begin scan dotnet
run: |
dotnet tool install --global dotnet-sonarscanner
dotnet tool install --global dotnet-sonarscanner --version 5.15.0
dotnet tool update dotnet-reportgenerator-globaltool -g
dotnet sonarscanner begin \
/k:${{ secrets.SONARQUBE_PROJECT_KEY_BE }} \
Expand All @@ -62,4 +63,4 @@ jobs:
- name: SonarQube end scan dotnet
run: dotnet sonarscanner end /d:sonar.login=${{ secrets.SONARQUBE_TOKEN_BE }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31 changes: 16 additions & 15 deletions .github/workflows/master_build_test_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ jobs:
steps:

- name: Checkout repository
uses: actions/checkout@v2.2.0
uses: actions/checkout@v4

- name: Semantic Release (install node.js)
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 14
node-version: 18

- name: Semantic Release (install dependencies)
run: |
npm install --global yarn
yarn install

- name: Semantic Release (process changes)
uses: cycjimmy/semantic-release-action@v2
uses: cycjimmy/semantic-release-action@v4.0.0
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_TOKEN }}

- name: Move results to outputs
id: versioning
run: |
Expand All @@ -50,18 +50,19 @@ jobs:
steps:

- name: Checkout repository
uses: actions/checkout@v2.2.0
uses: actions/checkout@v4

- name: Variable substitution appsettings file for Staging (NET Core)
- name: Variable substitution appsettings file for Production (NET Core)
uses: microsoft/variable-substitution@v1
with:
files: ${{ github.workspace }}/EmailSender.WebApi/appsettings.Staging.json
files: ${{ github.workspace }}/EmailSender.Configuration/appsettings.Production.json
env:
ConnectionStrings.DbConnect: "${{ secrets.CONNECTIONSTRINGS__DBCONNECT_STAGE }}"
ConnectionStrings.DbConnectTest: "${{ secrets.CONNECTIONSTRINGS__DBCONNECT_TEST }}"
DbConnect: "${{ secrets.DBCONNECT_PROD }}"
AZ_Storage_ContainerName: "${{ secrets.STORAGE_CONTAINER_NAME_PROD }}"
AZ_Storage_ConnectionString: "${{ secrets.STORAGE_CONNECTION_STRING }}"

- name: Production | Build Docker (prepare)
uses: azure/docker-login@v1
uses: azure/docker-login@v1.0.1
with:
login-server: ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}
username: ${{ secrets.DOCKER_REGISTRY_SERVER_USERNAME }}
Expand All @@ -73,7 +74,7 @@ jobs:
-t ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}/${{ secrets.DOCKER_REGISTRY_SERVER_USERNAME }}:backend-production-${{ github.sha }}

- name: Production | Push Docker image (prepare)
uses: azure/docker-login@v1
uses: azure/docker-login@v1.0.1
with:
login-server: ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}
username: ${{ secrets.DOCKER_REGISTRY_SERVER_USERNAME }}
Expand All @@ -84,10 +85,10 @@ jobs:
run: docker push ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}/${{ secrets.DOCKER_REGISTRY_SERVER_USERNAME }}:backend-production-${{ github.sha }}

- name: Production | Deploy to Azure Web App
uses: azure/webapps-deploy@v2
uses: azure/webapps-deploy@v3
if: needs.versioning.outputs.outputs2 == 'true'
with:
app-name: emailsender-prod
app-name: emailsender-west-production
slot-name: production
publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE_BACKEND_PROD }}
images: ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}/${{ secrets.DOCKER_REGISTRY_SERVER_USERNAME }}:backend-production-${{ github.sha }}
images: ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}/${{ secrets.DOCKER_REGISTRY_SERVER_USERNAME }}:backend-production-${{ github.sha }}
21 changes: 11 additions & 10 deletions .github/workflows/stage_build_test_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ jobs:
steps:

- name: Checkout repository
uses: actions/checkout@v2.2.0
uses: actions/checkout@v4

- name: Variable substitution appsettings file for Staging (NET Core)
uses: microsoft/variable-substitution@v1
uses: TomaszKandula/variable-substitution@v1.0.1
with:
files: ${{ github.workspace }}/EmailSender.WebApi/appsettings.Staging.json
files: ${{ github.workspace }}/EmailSender.Configuration/appsettings.Staging.json
env:
ConnectionStrings.DbConnect: "${{ secrets.CONNECTIONSTRINGS__DBCONNECT_STAGE }}"
ConnectionStrings.DbConnectTest: "${{ secrets.CONNECTIONSTRINGS__DBCONNECT_TEST }}"
DbConnect: "${{ secrets.DBCONNECT_STAGE }}"
AZ_Storage_ContainerName: "${{ secrets.STORAGE_CONTAINER_NAME_STAGE }}"
AZ_Storage_ConnectionString: "${{ secrets.STORAGE_CONNECTION_STRING }}"

- name: Staging | Build Docker (prepare)
uses: azure/docker-login@v1
uses: azure/docker-login@v1.0.1
with:
login-server: ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}
username: ${{ secrets.DOCKER_REGISTRY_SERVER_USERNAME }}
Expand All @@ -34,7 +35,7 @@ jobs:
run: docker build . -t ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}/${{ secrets.DOCKER_REGISTRY_SERVER_USERNAME }}:backend-staging-${{ github.sha }}

- name: Staging | Push Docker image (prepare)
uses: azure/docker-login@v1
uses: azure/docker-login@v1.0.1
with:
login-server: ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}
username: ${{ secrets.DOCKER_REGISTRY_SERVER_USERNAME }}
Expand All @@ -46,9 +47,9 @@ jobs:
# Note: due to a budget constraints, we use separate Azure App Service for staging as the separate slots
# are unavailable for B1, B2 and B3 pricing tiers
- name: Staging | Deploy to Azure Web App
uses: azure/webapps-deploy@v2
uses: azure/webapps-deploy@v3
with:
app-name: emailsender-stage
app-name: emailsender-west-staging
slot-name: production
publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE_BACKEND_STAGE }}
images: ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}/${{ secrets.DOCKER_REGISTRY_SERVER_USERNAME }}:backend-staging-${{ github.sha }}
images: ${{ secrets.DOCKER_REGISTRY_SERVER_URL }}/${{ secrets.DOCKER_REGISTRY_SERVER_USERNAME }}:backend-staging-${{ github.sha }}
6 changes: 6 additions & 0 deletions EmailSender.Configuration/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"AllowedHosts": "*",
"DbConnect": "",
"AZ_Storage_ContainerName": "",
"AZ_Storage_ConnectionString": ""
}
6 changes: 6 additions & 0 deletions EmailSender.Configuration/appsettings.Production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"AllowedHosts": "*",
"DbConnect": "",
"AZ_Storage_ContainerName": "",
"AZ_Storage_ConnectionString": ""
}
6 changes: 6 additions & 0 deletions EmailSender.Configuration/appsettings.Staging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"AllowedHosts": "*",
"DbConnect": "",
"AZ_Storage_ContainerName": "",
"AZ_Storage_ConnectionString": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public DatabaseContext CreateDbContext(string[] args)
.AddEnvironmentVariables()
.Build();

var connectionString = builder.GetConnectionString("DbConnect");

var connectionString = builder.GetValue<string>("DbConnect");
var optionsBuilder = new DbContextOptionsBuilder<DatabaseContext>();
optionsBuilder.UseSqlServer(connectionString);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@
</PropertyGroup>

<ItemGroup>
<None Include="..\..\EmailSender.WebApi\appsettings.Development.json">
<Link>appsettings.Development.json</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<None Include="..\..\EmailSender.Configuration\appsettings.Development.json">
<Link>appsettings.Development.json</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="..\..\EmailSender.WebApi\appsettings.json">
<Link>appsettings.json</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<None Include="..\..\EmailSender.Configuration\appsettings.Staging.json">
<Link>appsettings.Staging.json</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="..\..\EmailSender.WebApi\appsettings.Production.json">
<Link>appsettings.Production.json</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\EmailSender.WebApi\appsettings.Staging.json">
<Link>appsettings.Staging.json</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<None Include="..\..\EmailSender.Configuration\appsettings.Production.json">
<Link>appsettings.Production.json</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

Expand Down
5 changes: 3 additions & 2 deletions EmailSender.WebApi/Configuration/Dependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ private static void SetupDatabase(IServiceCollection services, IConfiguration co
{
const int maxRetryCount = 10;
var maxRetryDelay = TimeSpan.FromSeconds(5);

services.AddDbContext<DatabaseContext>(options =>
{
options.UseSqlServer(configuration.GetConnectionString("DbConnect"), addOptions
var connectionString = configuration.GetValue<string>("DbConnect");
options.UseSqlServer(connectionString, addOptions
=> addOptions.EnableRetryOnFailure(maxRetryCount, maxRetryDelay, null));
});
}
Expand Down
31 changes: 31 additions & 0 deletions EmailSender.WebApi/Configuration/Logger/Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Serilog;
using Serilog.Events;
using ILogger = Serilog.ILogger;

namespace EmailSender.WebApi.Configuration.Logger;

public static class Configuration
{
private const string LogTemplate
= "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}";

public static ILogger GetLogger(IConfigurationRoot configuration, string storageFileName)
{
var connectionString = configuration.GetValue<string>("AZ_Storage_ConnectionString");
var containerName = configuration.GetValue<string>("AZ_Storage_ContainerName");

return new LoggerConfiguration()

Check warning on line 17 in EmailSender.WebApi/Configuration/Logger/Configuration.cs

View workflow job for this annotation

GitHub Actions / dev-branch-check

Make sure that this logger's configuration is safe.

Check warning on line 17 in EmailSender.WebApi/Configuration/Logger/Configuration.cs

View workflow job for this annotation

GitHub Actions / dev-branch-check

Make sure that this logger's configuration is safe.
.MinimumLevel.Information()
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.AzureBlobStorage(
connectionString: connectionString,
restrictedToMinimumLevel: LogEventLevel.Information,
storageContainerName: containerName,
storageFileName: storageFileName,
writeInBatches: true,
period: TimeSpan.FromSeconds(30),
outputTemplate: LogTemplate)
.CreateLogger();
}
}
48 changes: 32 additions & 16 deletions EmailSender.WebApi/EmailSender.WebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,41 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="10.3.6" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="10.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.2" />
<PackageReference Include="Polly" Version="7.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.2.3" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="10.3.6" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="10.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.2" />
<PackageReference Include="Polly" Version="7.2.3" />
<PackageReference Include="Serilog.Sinks.AzureBlobStorage" Version="3.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.2.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EmailSender.Backend\EmailSender.Backend.Core\EmailSender.Backend.Core.csproj" />
<ProjectReference Include="..\EmailSender.Backend\EmailSender.Backend.Application\EmailSender.Backend.Application.csproj" />
<ProjectReference Include="..\EmailSender.Backend\EmailSender.Backend.Shared\EmailSender.Backend.Shared.csproj" />
<ProjectReference Include="..\EmailSender.Services\EmailSender.Services.BehaviourService\EmailSender.Services.BehaviourService.csproj" />
<ProjectReference Include="..\EmailSender.Services\EmailSender.Services.SenderService\EmailSender.Services.SenderService.csproj" />
<ProjectReference Include="..\EmailSender.Services\EmailSender.Services.SmtpService\EmailSender.Services.SmtpService.csproj" />
<ProjectReference Include="..\EmailSender.Services\EmailSender.Services.UserService\EmailSender.Services.UserService.csproj" />
<ProjectReference Include="..\EmailSender.WebApi.Dto\EmailSender.WebApi.Dto.csproj" />
<ProjectReference Include="..\EmailSender.Backend\EmailSender.Backend.Core\EmailSender.Backend.Core.csproj" />
<ProjectReference Include="..\EmailSender.Backend\EmailSender.Backend.Application\EmailSender.Backend.Application.csproj" />
<ProjectReference Include="..\EmailSender.Backend\EmailSender.Backend.Shared\EmailSender.Backend.Shared.csproj" />
<ProjectReference Include="..\EmailSender.Services\EmailSender.Services.BehaviourService\EmailSender.Services.BehaviourService.csproj" />
<ProjectReference Include="..\EmailSender.Services\EmailSender.Services.SenderService\EmailSender.Services.SenderService.csproj" />
<ProjectReference Include="..\EmailSender.Services\EmailSender.Services.SmtpService\EmailSender.Services.SmtpService.csproj" />
<ProjectReference Include="..\EmailSender.Services\EmailSender.Services.UserService\EmailSender.Services.UserService.csproj" />
<ProjectReference Include="..\EmailSender.WebApi.Dto\EmailSender.WebApi.Dto.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\EmailSender.Configuration\appsettings.Development.json">
<Link>appsettings.Development.json</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="..\EmailSender.Configuration\appsettings.Staging.json">
<Link>appsettings.Staging.json</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="..\EmailSender.Configuration\appsettings.Production.json">
<Link>appsettings.Production.json</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Loading
Loading