Skip to content

Commit

Permalink
daily backup 2
Browse files Browse the repository at this point in the history
  • Loading branch information
recepgunes1 committed Aug 31, 2023
1 parent 7459fbb commit 4e23e00
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 70 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,7 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

# Rider
.idea
38 changes: 25 additions & 13 deletions external-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@ services:
networks:
- backend

postgres_for_expiry_checker:
image: postgres:15
ports:
- 5433:5432
volumes:
- ./init-scripts/Quartz:/docker-entrypoint-initdb.d
environment:
POSTGRES_USER: Recep
POSTGRES_PASSWORD: Password123.
POSTGRES_DB: Quartz
networks:
- backend

rabbitmq:
image: rabbitmq:3.12-management
environment:
Expand All @@ -40,3 +27,28 @@ services:
retries: 3
networks:
- backend

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.9.2
ports:
- 9200:9200
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
environment:
- xpack.monitoring.enabled=true
- xpack.watcher.enabled=false
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- discovery.type=single-node
networks:
- backend

kibana:
image: docker.elastic.co/kibana/kibana:7.9.2
ports:
- 5601:5601
depends_on:
- elasticsearch
environment:
- ELASTICSEARCH_URL=http://localhost:9200
networks:
- backend
3 changes: 3 additions & 0 deletions internal-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ services:
- apigateway
networks:
- fronted
volumes:
- ./src/Fronted/webui:/app
- /app/node_modules
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Buffer.Infrastructure.Extensions
{
public static class InfrastructureLayerExtensions
{
public static IServiceCollection LoadInfrastructreLayer(this IServiceCollection service, IConfiguration configuration)
public static IServiceCollection LoadInfrastructureLayer(this IServiceCollection service, IConfiguration configuration)
{

service.AddMediatR(p => p.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
Expand Down
2 changes: 1 addition & 1 deletion src/Buffer/WebAPI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

builder.Logging.AddConsole();

builder.Services.LoadInfrastructreLayer(builder.Configuration);
builder.Services.LoadInfrastructureLayer(builder.Configuration);

builder.Services.AddControllers();

Expand Down
12 changes: 9 additions & 3 deletions src/Buffer/WebAPI/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"Logging": {
"LogLevel": {
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Override": {
"Microsoft": "Information",
"System": "Warning"
}
}
},
"ElasticConfiguration": {
"Uri": "http://localhost:9200"
},
"ConnectionStrings": {
"default": "User ID=Recep;Password=Password123.;Host=localhost;Port=5432;Database=UrlShortener;"
},
Expand Down
12 changes: 9 additions & 3 deletions src/Buffer/WebAPI/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"Logging": {
"LogLevel": {
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Override": {
"Microsoft": "Information",
"System": "Warning"
}
}
},
"ElasticConfiguration": {
"Uri": "http://elasticsearch:9200"
},
"AllowedHosts": "*",
"ConnectionStrings": {
"default": "User ID=Recep;Password=Password123.;Host=postgres;Port=5432;Database=UrlShortener;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,14 @@ namespace ExpiryChecker.Infrastructure.Extensions
{
public static class InfrastructureLayerExtensions
{
public static IServiceCollection LoadInfrastructreLayer(this IServiceCollection service, IConfiguration configuration)
public static IServiceCollection LoadInfrastructureLayer(this IServiceCollection service, IConfiguration configuration)
{
service.AddDbContext<AppDbContext>(p => p.UseNpgsql(configuration.GetConnectionString("defaultForUrlShortener")));
service.AddQuartz();
service.AddQuartzHostedService();

service.AddSingleton<IScheduler>(_ => new StdSchedulerFactory(new NameValueCollection
{
{ "quartz.serializer.type", "json" },
{ "quartz.jobStore.clustered", "true" },
{ "quartz.jobStore.type", "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" },
{ "quartz.jobStore.driverDelegateType", "Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz" },
{ "quartz.jobStore.tablePrefix", "QRTZ_" },
{ "quartz.jobStore.dataSource", "myDS" },
{ "quartz.dataSource.myDS.connectionString", configuration.GetConnectionString("defaultForUrlQuartz")},
{ "quartz.dataSource.myDS.provider", "Npgsql" },
{ "quartz.jobStore.useProperties", "true" },
{ "quartz.jobStore.performSchemaValidation", "false" }
}).GetScheduler().Result);
service.AddSingleton<IScheduler>(_ => new StdSchedulerFactory(new NameValueCollection()
).GetScheduler().Result);

service.AddMassTransit(config =>
{
Expand Down
2 changes: 1 addition & 1 deletion src/ExpiryChecker/WebAPI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

builder.Logging.AddConsole();

builder.Services.LoadInfrastructreLayer(builder.Configuration);
builder.Services.LoadInfrastructureLayer(builder.Configuration);

var app = builder.Build();

Expand Down
13 changes: 9 additions & 4 deletions src/ExpiryChecker/WebAPI/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{
"Logging": {
"LogLevel": {
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Override": {
"Microsoft": "Information",
"System": "Warning"
}
}
},
"ElasticConfiguration": {
"Uri": "http://localhost:9200"
},
"ConnectionStrings": {
"defaultForUrlQuartz": "User ID=Recep;Password=Password123.;Host=localhost;Port=5433;Database=Quartz;",
"defaultForUrlShortener": "User ID=Recep;Password=Password123.;Host=localhost;Port=5432;Database=UrlShortener;"
},
"RabbitMQ": {
Expand Down
13 changes: 9 additions & 4 deletions src/ExpiryChecker/WebAPI/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
{
"Logging": {
"LogLevel": {
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Override": {
"Microsoft": "Information",
"System": "Warning"
}
}
},
"ElasticConfiguration": {
"Uri": "http://elasticsearch:9200"
},
"AllowedHosts": "*",
"ConnectionStrings": {
"defaultForUrlQuartz": "User ID=Recep;Password=Password123.;Host=postgres_for_expiry_checker;Port=5433;Database=Quartz;",
"defaultForUrlShortener": "User ID=Recep;Password=Password123.;Host=postgres;Port=5432;Database=UrlShortener;"
},
"RabbitMQ": {
Expand Down
30 changes: 19 additions & 11 deletions src/Fronted/webui/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
FROM node:lts-alpine
# Use the official Node.js image as the base image
FROM node:14

# Set the working directory inside the container
WORKDIR /app
# install vite globally
RUN npm install -g @vue/cli
# copy all filtes
COPY . .
# install all deps
RUN yarn install

# vite default port
EXPOSE 8080
CMD ["vue", "serve"]

# Copy package.json and package-lock.json before other files
COPY package*.json ./

# Install dependencies including devDependencies
RUN npm install

# Copy the rest of the application to the container
COPY . .

# Expose the default Vue.js development server port
EXPOSE 8080

# Command to run the app in development mode
CMD ["npm", "run", "serve"]
12 changes: 9 additions & 3 deletions src/Gateway/Gateway.WebAPI/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"Logging": {
"LogLevel": {
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Override": {
"Microsoft": "Information",
"System": "Warning"
}
}
},
"ElasticConfiguration": {
"Uri": "http://localhost:9200"
}
}
12 changes: 9 additions & 3 deletions src/Gateway/Gateway.WebAPI/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
"Logging": {
"LogLevel": {
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Override": {
"Microsoft": "Information",
"System": "Warning"
}
}
},
"ElasticConfiguration": {
"Uri": "http://localhost:9200"
},
"AllowedHosts": "*"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Shortener.Infrastructure.Extensions
{
public static class InfrastructureLayerExtensions
{
public static IServiceCollection LoadInfrastructreLayer(this IServiceCollection service, IConfiguration configuration)
public static IServiceCollection LoadInfrastructureLayer(this IServiceCollection service, IConfiguration configuration)
{
service.AddMediatR(p =>
{
Expand Down
2 changes: 1 addition & 1 deletion src/Shortener/WebAPI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

builder.Logging.AddConsole();

builder.Services.LoadInfrastructreLayer(builder.Configuration);
builder.Services.LoadInfrastructureLayer(builder.Configuration);

builder.Services.AddControllers();

Expand Down
12 changes: 9 additions & 3 deletions src/Shortener/WebAPI/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"Logging": {
"LogLevel": {
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Override": {
"Microsoft": "Information",
"System": "Warning"
}
}
},
"ElasticConfiguration": {
"Uri": "http://localhost:9200"
},
"ConnectionStrings": {
"default": "User ID=Recep;Password=Password123.;Host=localhost;Port=5432;Database=UrlShortener;"
},
Expand Down
12 changes: 9 additions & 3 deletions src/Shortener/WebAPI/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"Logging": {
"LogLevel": {
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Override": {
"Microsoft": "Information",
"System": "Warning"
}
}
},
"ElasticConfiguration": {
"Uri": "http://elasticsearch:9200"
},
"AllowedHosts": "*",
"ConnectionStrings": {
"default": "User ID=Recep;Password=Password123.;Host=postgres;Port=5432;Database=UrlShortener;"
Expand Down
34 changes: 34 additions & 0 deletions src/Utils/Shared/Extensions/SharedExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System.Collections;
using System.Reflection;
using System.Text.Json;
using Microsoft.Extensions.Configuration;
using Serilog;
using Serilog.Sinks.Elasticsearch;

namespace Shared.Extensions
{
Expand All @@ -25,5 +29,35 @@ public static string ToJsonString(this Exception ex)
var jsonException = JsonSerializer.Serialize(exceptionDetails, new JsonSerializerOptions { WriteIndented = true });
return jsonException;
}

public static void ConfigureLogging()
{
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile(
$"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json",
optional: true)
.Build();

Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithMachineName()
.WriteTo.Debug()
.WriteTo.Console()
.WriteTo.Elasticsearch(ConfigureElasticSink(configuration, environment))

Check warning on line 48 in src/Utils/Shared/Extensions/SharedExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'environment' in 'ElasticsearchSinkOptions SharedExtensions.ConfigureElasticSink(IConfigurationRoot configuration, string environment)'.

Check warning on line 48 in src/Utils/Shared/Extensions/SharedExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'environment' in 'ElasticsearchSinkOptions SharedExtensions.ConfigureElasticSink(IConfigurationRoot configuration, string environment)'.
.Enrich.WithProperty("Environment", environment)
.ReadFrom.Configuration(configuration)
.CreateLogger();
}

private static ElasticsearchSinkOptions ConfigureElasticSink(IConfigurationRoot configuration, string environment)
{
return new ElasticsearchSinkOptions(new Uri(configuration["ElasticConfiguration:Uri"]))

Check warning on line 56 in src/Utils/Shared/Extensions/SharedExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'uriString' in 'Uri.Uri(string uriString)'.

Check warning on line 56 in src/Utils/Shared/Extensions/SharedExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'uriString' in 'Uri.Uri(string uriString)'.
{
AutoRegisterTemplate = true,
IndexFormat = $"{Assembly.GetExecutingAssembly().GetName().Name.ToLower().Replace(".", "-")}-{environment?.ToLower().Replace(".", "-")}-{DateTime.UtcNow:yyyy-MM}"

Check warning on line 59 in src/Utils/Shared/Extensions/SharedExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 59 in src/Utils/Shared/Extensions/SharedExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
};
}
}
}
7 changes: 7 additions & 0 deletions src/Utils/Shared/Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="9.0.3" />
</ItemGroup>

</Project>

0 comments on commit 4e23e00

Please sign in to comment.