Skip to content

Commit

Permalink
Merge pull request #43 from KNPhilip/deployment
Browse files Browse the repository at this point in the history
Deployment
  • Loading branch information
KNPhilip authored Feb 23, 2024
2 parents 9227311 + 803b9d9 commit 2f1cec4
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 12 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/deploy-identity.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Deploy Identity Service

on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'src/IdentityService/**'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v3
- name: Build and push the Docker image
uses: knphilip/actions/dockerfile-push@main
with:
tags: knphilip/bidwheels-identity-svc:latest
file: src/IdentityService/Dockerfile
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
11 changes: 11 additions & 0 deletions K8S/local-pvc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-claim
spec:
resources:
requests:
storage: 200Mi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
28 changes: 28 additions & 0 deletions K8S/postgres-depl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
spec:
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres
env:
- name: POSTGRES_PASSWORD
value: postgrespw
ports:
- containerPort: 5432
volumeMounts:
- mountPath: /var/data/postgresql
name: postgresdata
volumes:
- name: postgresdata
persistentVolumeClaim:
claimName: postgres-claim
1 change: 1 addition & 0 deletions src/AuctionService/AuctionService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="Polly" Version="8.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 14 additions & 0 deletions src/AuctionService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using MassTransit;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.EntityFrameworkCore;
using Npgsql;
using Polly;
using Polly.Retry;

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

Expand Down Expand Up @@ -37,6 +40,11 @@
config.UsingRabbitMq((context, cfg) =>
{
cfg.UseMessageRetry(r => {
r.Handle<RabbitMqConnectionException>();
r.Interval(5, TimeSpan.FromSeconds(10));
});
cfg.Host(builder.Configuration["RabbitMQ:Host"], "/", host =>
{
host.Username(builder.Configuration.GetValue("RabbitMQ:Username", "guest"));
Expand Down Expand Up @@ -65,6 +73,12 @@

app.MapGrpcService<GrpcAuctionService>();

RetryPolicy retryPolicy = Policy
.Handle<NpgsqlException>()
.WaitAndRetry(5, retryAttempt => TimeSpan.FromSeconds(10));

retryPolicy.ExecuteAndCapture(() => DbInitializer.InitDb(app));

try
{
DbInitializer.InitDb(app);
Expand Down
1 change: 1 addition & 0 deletions src/BiddingService/BiddingService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PackageReference Include="MassTransit.RabbitMQ" Version="8.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.1" />
<PackageReference Include="MongoDB.Entities" Version="23.0.1" />
<PackageReference Include="Polly" Version="8.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 14 additions & 2 deletions src/BiddingService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using BiddingService.Consumers;
using BiddingService.Services;
using Polly;

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

Expand All @@ -16,6 +17,12 @@
config.UsingRabbitMq((context, cfg) =>
{
cfg.UseMessageRetry(r =>
{
r.Handle<RabbitMqConnectionException>();
r.Interval(5, TimeSpan.FromSeconds(10));
});
cfg.Host(builder.Configuration["RabbitMQ:Host"], "/", host =>
{
host.Username(builder.Configuration.GetValue("RabbitMQ:Username", "guest"));
Expand Down Expand Up @@ -46,7 +53,12 @@

app.MapControllers();

await DB.InitAsync("BidDb", MongoClientSettings
.FromConnectionString(builder.Configuration.GetConnectionString("BidDbConnection")));
await Policy.Handle<TimeoutException>()
.WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(10))
.ExecuteAndCaptureAsync(async () =>
{
await DB.InitAsync("BidDb", MongoClientSettings
.FromConnectionString(builder.Configuration.GetConnectionString("BidDbConnection")));
});

app.Run();
2 changes: 2 additions & 0 deletions src/IdentityService/IdentityService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.1" />

<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />

<PackageReference Include="Polly" Version="8.3.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />

<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.1" />
Expand Down
9 changes: 8 additions & 1 deletion src/IdentityService/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using IdentityService;
using Npgsql;
using Polly;
using Polly.Retry;
using Serilog;

Log.Logger = new LoggerConfiguration()
Expand All @@ -22,7 +25,11 @@

// this seeding is only for the template to bootstrap the DB and users.
// in production you will likely want a different approach.
SeedData.EnsureSeedData(app);
RetryPolicy retryPolicy = Policy
.Handle<NpgsqlException>()
.WaitAndRetry(5, retryAttempt => TimeSpan.FromSeconds(10));

retryPolicy.ExecuteAndCapture(() => SeedData.EnsureSeedData(app));

app.Run();
}
Expand Down
6 changes: 6 additions & 0 deletions src/NotificationService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
config.UsingRabbitMq((context, cfg) =>
{
cfg.UseMessageRetry(r =>
{
r.Handle<RabbitMqConnectionException>();
r.Interval(5, TimeSpan.FromSeconds(10));
});
cfg.Host(builder.Configuration["RabbitMQ:Host"], "/", host =>
{
host.Username(builder.Configuration.GetValue("RabbitMQ:Username", "guest"));
Expand Down
19 changes: 10 additions & 9 deletions src/SearchService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
config.UsingRabbitMq((context, cfg) =>
{
cfg.UseMessageRetry(r => {
r.Handle<RabbitMqConnectionException>();
r.Interval(5, TimeSpan.FromSeconds(10));
});
cfg.Host(builder.Configuration["RabbitMQ:Host"], "/", host =>
{
host.Username(builder.Configuration.GetValue("RabbitMQ:Username", "guest"));
Expand All @@ -44,15 +49,11 @@

app.MapControllers();

app.Lifetime.ApplicationStarted.Register(async () => {
try
{
await DbInitializer.InitDb(app);
}
catch (Exception ex)
{
Console.WriteLine($"--> Something went wrong: {ex}");
}
app.Lifetime.ApplicationStarted.Register(async () =>
{
await Policy.Handle<TimeoutException>()
.WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(5))
.ExecuteAndCaptureAsync(async () => await DbInitializer.InitDb(app));
});

app.Run();
Expand Down
1 change: 1 addition & 0 deletions src/SearchService/SearchService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="MassTransit.RabbitMQ" Version="8.1.3" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.1" />
<PackageReference Include="MongoDB.Entities" Version="23.0.1" />
<PackageReference Include="Polly" Version="8.3.0" />
</ItemGroup>

</Project>

0 comments on commit 2f1cec4

Please sign in to comment.