initialising for ci-cd pipeline
CI/CD - ERP Core / scripts (pull_request) Failing after 12m21s
CI/CD - ERP Core / e2e-typecheck (pull_request) Failing after 13m13s
CI/CD - ERP Core / frontend (pull_request) Failing after 14m5s
CI/CD - ERP Core / backend (pull_request) Failing after 14m57s
CI/CD - ERP Core / detect (pull_request) Failing after 13m42s
CI/CD - ERP Core / Build & Deploy (pull_request) Failing after 12m47s
CI/CD - ERP Core / ci-ok (pull_request) Failing after 14m58s

This commit is contained in:
2026-09-16 11:53:55 +05:30
parent 666979cf22
commit 8e472ac996
48 changed files with 2224 additions and 62 deletions
@@ -18,6 +18,11 @@ public sealed class GeneralLedgerClient(HttpClient http, IConfiguration configur
public async Task<GeneralLedgerResponse> SendAsync(
HttpMethod method, string path, string? queryString, string? contentType, Stream? body, CancellationToken ct)
{
// The base appsettings.json ships the key blank; name it here rather than forward GL's 401
// for an empty X-Api-Key (deployed environments already refuse to start without it).
if (string.IsNullOrWhiteSpace(_apiKey))
throw new DomainException(ErrorCodes.GlServiceUnavailable, "GeneralLedgerService:ApiKey is not configured.", 503);
var relativeUri = path.TrimStart('/') + queryString;
using var request = new HttpRequestMessage(method, relativeUri);
request.Headers.TryAddWithoutValidation("X-Api-Key", _apiKey);
@@ -39,17 +39,29 @@ public static class DataSeeder
("PRD-REWORK-LOSS", "Production Rework Loss", ReasonContext.Production),
];
public static async Task SeedAsync(ErpDbContext db, CancellationToken ct = default)
/// <param name="includeDemoData">
/// Also seed demo rows — sample warehouses/UOMs/category/items, an on-hand stock layer,
/// customers, bundle and draft sales documents (<c>Seed:DemoData</c>). On for Development
/// and the test deployment (the E2E suite relies on MAIN/SHOP, PCS/BOX, General Goods);
/// never for release, which gets reference data only (docs/40-DEPLOYMENT.md).
/// </param>
public static async Task SeedAsync(ErpDbContext db, bool includeDemoData, CancellationToken ct = default)
{
// Reference data — every environment.
var dirty = await SeedReasonCodesAsync(db, ct);
dirty |= await SeedItemTypesAsync(db, ct);
// dirty |= await SeedCompanyProfileAsync(db, ct);
dirty |= await SeedProductConfigAsync(db, ct);
dirty |= await SeedBranchConfigAsync(db, ct);
dirty |= await SeedNotificationConfigAsync(db, ct);
dirty |= await SeedSalesMastersAsync(db, ct);
dirty |= await SeedSalesStockAsync(db, ct);
dirty |= await SeedSalesAsync(db, ct);
dirty |= await SeedSalesSequencesAsync(db, ct);
if (includeDemoData)
{
dirty |= await SeedSalesMastersAsync(db, ct);
dirty |= await SeedSalesStockAsync(db, ct);
dirty |= await SeedSalesAsync(db, ct);
}
if (dirty) await db.SaveChangesAsync(ct);
}
@@ -344,9 +356,9 @@ public static class DataSeeder
}
/// <summary>
/// Seeds the minimum sales bootstrap data needed for UI/backend development:
/// a couple of customer rows, current-year document counters, and a few draft
/// invoice/slip samples when the required master data already exists.
/// Seeds the demo sales data used for UI/backend development: a couple of customer
/// rows and a few draft invoice/slip samples when the required master data already
/// exists. (Current-year document counters are reference data, seeded in SeedAsync.)
/// This intentionally never clears or rewrites any existing rows.
/// </summary>
private static async Task<bool> SeedSalesAsync(ErpDbContext db, CancellationToken ct)
@@ -354,7 +366,6 @@ public static class DataSeeder
var dirty = false;
dirty |= await SeedSalesCustomersAsync(db, ct);
dirty |= await SeedSalesSequencesAsync(db, ct);
dirty |= await SeedSampleSalesDocsAsync(db, ct);
try
+46 -8
View File
@@ -15,6 +15,7 @@ using ERPCore.Services.Production;
using ERPCore.Services.Stock;
using ERPCore.System.Errors;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.OpenApi;
@@ -23,10 +24,32 @@ using Serilog;
var builder = WebApplication.CreateBuilder(args);
// Serilog (file sink) — reads levels from configuration, plus a rolling daily file.
// Fail fast on missing deployment config. Outside Development these arrive as environment
// variables (docs/40-DEPLOYMENT.md §5); a blank value would otherwise surface later as an
// unrelated crash (e.g. `new Uri("")` for AuthHex:BaseUrl) instead of naming the key.
if (!builder.Environment.IsDevelopment())
{
string[] requiredKeys =
[
"ConnectionStrings:DefaultConnection",
"AuthHex:BaseUrl",
"GeneralLedgerService:BaseUrl",
"GeneralLedgerService:ApiKey",
"Auth:RsaPublicKeyXml",
];
var missing = requiredKeys.Where(k => string.IsNullOrWhiteSpace(builder.Configuration[k])).ToArray();
if (missing.Length > 0)
throw new InvalidOperationException(
$"Missing required configuration for environment '{builder.Environment.EnvironmentName}': " +
$"{string.Join(", ", missing)}. Set them as environment variables (':' becomes '__', " +
"e.g. ConnectionStrings__DefaultConnection).");
}
// Serilog (file sink) — reads levels from configuration, plus a rolling daily file. The path is
// configurable so deployed instances log outside their release folder (LogFile:Path).
builder.Host.UseSerilog((ctx, cfg) => cfg
.ReadFrom.Configuration(ctx.Configuration)
.WriteTo.File("logs/erpcore-.log", rollingInterval: RollingInterval.Day));
.WriteTo.File(ctx.Configuration["LogFile:Path"] ?? "logs/erpcore-.log", rollingInterval: RollingInterval.Day));
// Controllers + JSON: serialize enums as their string names (docs/11 §8, camelCase).
builder.Services.AddControllers()
@@ -49,8 +72,10 @@ builder.Services.AddErpJwtAuth(builder.Configuration);
// AuthController proxy → AuthHex (docs/11 §2.0)
builder.Services.AddHttpClient<IAuthHexClient, AuthHexClient>(c =>
{
var baseUrl = builder.Configuration["AuthHex:BaseUrl"]
?? throw new InvalidOperationException("AuthHex:BaseUrl is not configured.");
// Blank counts as missing: the base appsettings.json ships these keys empty on purpose.
var baseUrl = builder.Configuration["AuthHex:BaseUrl"];
if (string.IsNullOrWhiteSpace(baseUrl))
throw new InvalidOperationException("AuthHex:BaseUrl is not configured (set it in appsettings.Development.json locally).");
c.BaseAddress = new Uri(baseUrl);
});
builder.Services.AddScoped<IAuthUserService, AuthUserService>();
@@ -60,8 +85,9 @@ builder.Services.AddScoped<IAuthAltService, AuthAltService>();
// General Ledger service proxy → external GL microservice (docs/12-GENERAL-LEDGER-INTEGRATION.md)
builder.Services.AddHttpClient<IGeneralLedgerClient, GeneralLedgerClient>(c =>
{
var baseUrl = builder.Configuration["GeneralLedgerService:BaseUrl"]
?? throw new InvalidOperationException("GeneralLedgerService:BaseUrl is not configured.");
var baseUrl = builder.Configuration["GeneralLedgerService:BaseUrl"];
if (string.IsNullOrWhiteSpace(baseUrl))
throw new InvalidOperationException("GeneralLedgerService:BaseUrl is not configured (set it in appsettings.Development.json locally).");
c.BaseAddress = new Uri(baseUrl);
});
builder.Services.AddScoped<IGeneralLedgerService, GeneralLedgerService>();
@@ -205,7 +231,10 @@ using (var scope = app.Services.CreateScope())
await db.Database.MigrateAsync();
try
{
await DataSeeder.SeedAsync(db);
// Demo rows (sample catalog, stock, customers, sales docs) default on only in Development;
// the test deployment opts in with Seed__DemoData=true, release never does.
var includeDemoData = app.Configuration.GetValue("Seed:DemoData", app.Environment.IsDevelopment());
await DataSeeder.SeedAsync(db, includeDemoData);
}
catch (Exception ex)
{
@@ -213,9 +242,18 @@ using (var scope = app.Services.CreateScope())
}
}
// Behind the co-located Apache reverse proxy (docs/40-DEPLOYMENT.md): take the client IP and
// scheme from X-Forwarded-*. Only loopback proxies are trusted by default, which is exactly it.
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseSerilogRequestLogging();
if (app.Environment.IsDevelopment())
// Off in Production only. The test deployment (Staging) keeps it; it is still not public there
// because Apache proxies only /api/ — reach it through an SSH tunnel to the backend port.
if (!app.Environment.IsProduction())
{
app.UseSwagger();
app.UseSwaggerUI();
@@ -0,0 +1,21 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"DefaultConnection": "Host=127.0.0.1;Port=5432;Database=ERPCore;Username=postgres;Password=CHANGE_ME"
},
"AuthHex": {
"BaseUrl": "http://localhost:5011"
},
"GeneralLedgerService": {
"BaseUrl": "https://localhost:7024/api/v1/",
"ApiKey": "ask-the-team-for-the-dev-key"
},
"Seed": {
"DemoData": true
}
}
+7 -4
View File
@@ -6,7 +6,7 @@
}
},
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Port=5432;Database=ERPCore;Username=root;Password=root"
"DefaultConnection": ""
},
"Auth": {
"Issuer": "AuthHex",
@@ -16,15 +16,18 @@
"RequiredRoleCode": ""
},
"AuthHex": {
"BaseUrl": "http://localhost:5602"
"BaseUrl": ""
},
"FileStorage": {
"RootPath": "App_Data/hr-documents",
"MaxSizeBytes": 10485760
},
"LogFile": {
"Path": "logs/erpcore-.log"
},
"GeneralLedgerService": {
"BaseUrl": "https://localhost:7024/api/v1/",
"ApiKey": "1A5FE0E389C029B1FBCD2A94650CEBF0656083BF06FF48E5E11987040ABA262D"
"BaseUrl": "",
"ApiKey": ""
},
"Grn": {
"GlInventoryAccountCode": "1100",