Compare commits
2 Commits
de5b8fbe16
...
140ece8080
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
140ece8080 | ||
|
|
b24aaab679 |
63
.dockerignore
Normal file
63
.dockerignore
Normal file
@@ -0,0 +1,63 @@
|
||||
# Build artifacts
|
||||
**/bin/
|
||||
**/obj/
|
||||
**/out/
|
||||
**/publish/
|
||||
|
||||
# IDE and editor files
|
||||
**/.vs/
|
||||
**/.vscode/
|
||||
**/.idea/
|
||||
**/.DS_Store
|
||||
**/*.user
|
||||
**/*.suo
|
||||
**/*.userosscache
|
||||
**/*.sln.docstates
|
||||
**/*.userprefs
|
||||
**/.fleet/
|
||||
|
||||
# Database files
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/*.mdf
|
||||
**/*.ldf
|
||||
|
||||
# Temp and swap files
|
||||
**/*.swp
|
||||
**/*.swo
|
||||
**/*~
|
||||
**/*.tmp
|
||||
**/*.temp
|
||||
|
||||
# Logs
|
||||
**/*.log
|
||||
|
||||
# Node modules (if any frontend dependencies)
|
||||
**/node_modules/
|
||||
|
||||
# Git files
|
||||
.git/
|
||||
.gitignore
|
||||
.gitattributes
|
||||
.git-crypt/
|
||||
|
||||
# Documentation
|
||||
README.md
|
||||
**/*.md
|
||||
LICENSE
|
||||
|
||||
# Docker files
|
||||
docker-compose.yml
|
||||
docker-compose.*.yml
|
||||
**/Dockerfile
|
||||
**/.dockerignore
|
||||
|
||||
# Development databases
|
||||
docker/
|
||||
|
||||
# Test results
|
||||
**/TestResults/
|
||||
**/*.trx
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
53
.gitea/workflows/build.yml
Normal file
53
.gitea/workflows/build.yml
Normal file
@@ -0,0 +1,53 @@
|
||||
name: Build Docker Images
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
concurrency:
|
||||
group: build-${{ github.ref }}
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: https://github.com/docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to Gitea Container Registry
|
||||
run: |
|
||||
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login code.bim-it.pl -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
||||
|
||||
- name: Build and push API image (build artifacts)
|
||||
run: |
|
||||
docker buildx build \
|
||||
--platform linux/amd64 \
|
||||
-f BimAI.API/Dockerfile \
|
||||
-t code.bim-it.pl/bimai/bimai-api:build-${{ github.run_id }} \
|
||||
--push \
|
||||
.
|
||||
|
||||
- name: Build and push UI image (build artifacts)
|
||||
run: |
|
||||
docker buildx build \
|
||||
--platform linux/amd64 \
|
||||
-f BimAI.UI.Web/Dockerfile \
|
||||
-t code.bim-it.pl/bimai/bimai-ui:build-${{ github.run_id }} \
|
||||
--push \
|
||||
.
|
||||
|
||||
- name: Output build info
|
||||
run: |
|
||||
echo "## 🏗️ Docker Images Built" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "**Build ID:** ${{ github.run_id }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "Images pushed with tag: \`build-${{ github.run_id }}\`" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "Use **Release** workflow to tokenize and tag as \`:prod\`" >> $GITHUB_STEP_SUMMARY
|
||||
53
.github/workflows/build.yml
vendored
53
.github/workflows/build.yml
vendored
@@ -1,53 +0,0 @@
|
||||
name: Build Bimix
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build WebAPI and WebUI
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
env:
|
||||
DOTNET_VERSION: '8.0.x'
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: ${{ env.DOTNET_VERSION }}
|
||||
|
||||
- name: Restore WebAPI
|
||||
run: dotnet restore Bimix.API/Bimix.API.csproj
|
||||
|
||||
- name: Restore WebUI
|
||||
run: dotnet restore Bimix.UI.Web/Bimix.UI.Web.csproj
|
||||
|
||||
- name: Build WebAPI
|
||||
run: dotnet build Bimix.API/Bimix.API.csproj --configuration Release --no-restore
|
||||
|
||||
- name: Build WebUI
|
||||
run: dotnet build Bimix.UI.Web/Bimix.UI.Web.csproj --configuration Release --no-restore
|
||||
|
||||
- name: Publish WebAPI
|
||||
run: |
|
||||
dotnet publish Bimix.API/Bimix.API.csproj \
|
||||
--configuration Release \
|
||||
--output ./publish/Bimix-WebAPI
|
||||
|
||||
- name: Publish Web (Blazor Server)
|
||||
run: |
|
||||
dotnet publish Bimix.UI.Web/Bimix.UI.Web.csproj \
|
||||
--configuration Release \
|
||||
--output ./publish/Bimix-Web
|
||||
|
||||
- name: Upload publish artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: bimix-artifacts
|
||||
path: ./publish
|
||||
@@ -8,6 +8,9 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.Apis.Auth" Version="1.70.0" />
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.21" />
|
||||
<PackageReference Include="Hangfire.Core" Version="1.8.21" />
|
||||
<PackageReference Include="Hangfire.SqlServer" Version="1.8.21" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.17">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
45
BimAI.API/Dockerfile
Normal file
45
BimAI.API/Dockerfile
Normal file
@@ -0,0 +1,45 @@
|
||||
# Stage 1: Build
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
WORKDIR /src
|
||||
|
||||
# Copy solution and all project files for restore
|
||||
COPY BimAI.sln ./
|
||||
COPY BimAI.API/BimAI.API.csproj BimAI.API/
|
||||
COPY BimAI.Domain/BimAI.Domain.csproj BimAI.Domain/
|
||||
COPY BimAI.Application/BimAI.Application.csproj BimAI.Application/
|
||||
COPY BimAI.Infrastructure/BimAI.Infrastructure.csproj BimAI.Infrastructure/
|
||||
|
||||
# Restore dependencies
|
||||
RUN dotnet restore BimAI.API/BimAI.API.csproj
|
||||
|
||||
# Copy all source code
|
||||
COPY . .
|
||||
|
||||
# Build and publish
|
||||
WORKDIR /src/BimAI.API
|
||||
RUN dotnet publish -c Release -o /app/publish --no-restore
|
||||
|
||||
# Stage 2: Runtime
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
|
||||
WORKDIR /app
|
||||
|
||||
# Set timezone
|
||||
ENV TZ=Europe/Warsaw
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
# Copy published files
|
||||
COPY --from=build /app/publish .
|
||||
|
||||
# Set environment variables
|
||||
ENV ASPNETCORE_ENVIRONMENT=Production
|
||||
ENV ASPNETCORE_URLS=http://0.0.0.0:7142
|
||||
|
||||
# Expose port
|
||||
EXPOSE 7142
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
|
||||
CMD wget --no-verbose --tries=1 --spider http://localhost:7142/health || exit 1
|
||||
|
||||
# Run the application
|
||||
ENTRYPOINT ["dotnet", "BimAI.API.dll"]
|
||||
@@ -1,7 +1,10 @@
|
||||
using System.Text;
|
||||
using BimAI.API.Services;
|
||||
using BimAI.Infrastructure.Data;
|
||||
using BimAI.Infrastructure.Jobs;
|
||||
using BimAI.Infrastructure.Sync;
|
||||
using Hangfire;
|
||||
using Hangfire.SqlServer;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
@@ -18,6 +21,29 @@ builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
// Start Hangfire section
|
||||
builder.Services.AddHangfire(configuration => configuration
|
||||
.SetDataCompatibilityLevel(CompatibilityLevel.Version_180)
|
||||
.UseSimpleAssemblyNameTypeSerializer()
|
||||
.UseRecommendedSerializerSettings()
|
||||
.UseSqlServerStorage(builder.Configuration.GetConnectionString("HangfireConnection"),
|
||||
new SqlServerStorageOptions
|
||||
{
|
||||
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
|
||||
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
|
||||
QueuePollInterval = TimeSpan.Zero,
|
||||
UseRecommendedIsolationLevel = true,
|
||||
DisableGlobalLocks = true,
|
||||
SchemaName = "Hangfire"
|
||||
}
|
||||
)
|
||||
);
|
||||
builder.Services.AddHangfireServer(options =>
|
||||
{
|
||||
options.ServerName = builder.Configuration["Hangfire:ServerName"];
|
||||
options.WorkerCount = builder.Configuration.GetValue<int>("Hangfire:WorkerCount", 5);
|
||||
});
|
||||
// End Hangfire section
|
||||
// Start auth section
|
||||
var jwtSettings = builder.Configuration.GetSection("JwtSettings");
|
||||
var secretKey = jwtSettings["SecretKey"];
|
||||
@@ -65,7 +91,28 @@ if (app.Environment.IsDevelopment())
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseCors("AllowAll");
|
||||
app.UseHangfireDashboard(builder.Configuration["Hangfire:DashboardPath"] ?? "/hangfire", new DashboardOptions
|
||||
{
|
||||
AsyncAuthorization = new[] { new HangfireAuthorizationFilter() },
|
||||
DashboardTitle = "BimAI - Job Dashboard"
|
||||
});
|
||||
app.UseAuthorization();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
|
||||
app.MapGet("/health", () => Results.Ok(new { status = "OK", timestamp = DateTime.UtcNow }))
|
||||
.AllowAnonymous();
|
||||
|
||||
RecurringJob.AddOrUpdate<ProductSyncJob>(
|
||||
"product-sync",
|
||||
job => job.ExecuteAsync(),
|
||||
Cron.Daily(2, 0), // Every day at 2:00 AM
|
||||
new RecurringJobOptions
|
||||
{
|
||||
TimeZone = TimeZoneInfo.Local,
|
||||
MisfireHandling = app.Environment.IsDevelopment()
|
||||
? MisfireHandlingMode.Relaxed
|
||||
: MisfireHandlingMode.Strict
|
||||
});
|
||||
|
||||
app.Run();
|
||||
20
BimAI.API/Services/HangfireAuthorizationFilter.cs
Normal file
20
BimAI.API/Services/HangfireAuthorizationFilter.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Hangfire.Dashboard;
|
||||
|
||||
namespace BimAI.API.Services;
|
||||
|
||||
public class HangfireAuthorizationFilter: IDashboardAsyncAuthorizationFilter
|
||||
{
|
||||
public Task<bool> AuthorizeAsync(DashboardContext context)
|
||||
{
|
||||
var httpContext = context.GetHttpContext();
|
||||
|
||||
var env = httpContext.RequestServices.GetService<IWebHostEnvironment>();
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
var isAuthenticated = httpContext.User.Identity?.IsAuthenticated ?? false;
|
||||
return Task.FromResult(isAuthenticated);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
38
BimAI.API/appsettings.Production.json
Normal file
38
BimAI.API/appsettings.Production.json
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.EntityFrameworkCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "#{db-connection-string}#",
|
||||
"HangfireConnection": "#{hangfire-connection-string}#"
|
||||
},
|
||||
"E5_CRM": {
|
||||
"ApiKey": "#{e5-crm-api-key}#"
|
||||
},
|
||||
"GoogleAuth": {
|
||||
"ClientId": "#{google-auth-client-id}#"
|
||||
},
|
||||
"JwtSettings": {
|
||||
"SecretKey": "#{jwt-secret-key}#",
|
||||
"Issuer": "#{jwt-issuer}#",
|
||||
"Audience": "#{jwt-audience}#",
|
||||
"ExpiryDays": 7
|
||||
},
|
||||
"Hangfire": {
|
||||
"ServerName": "#{hangfire-server-name}#",
|
||||
"WorkerCount": 5,
|
||||
"DashboardPath": "/hangfire"
|
||||
},
|
||||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
"Http": {
|
||||
"Url": "http://0.0.0.0:7142"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
31
BimAI.Infrastructure/Jobs/ProductSyncJob.cs
Normal file
31
BimAI.Infrastructure/Jobs/ProductSyncJob.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using BimAI.Infrastructure.Sync;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BimAI.Infrastructure.Jobs;
|
||||
|
||||
public class ProductSyncJob
|
||||
{
|
||||
private readonly ProductSyncService _productSyncService;
|
||||
private readonly ILogger<ProductSyncJob> _logger;
|
||||
|
||||
public ProductSyncJob(ProductSyncService productSyncService, ILogger<ProductSyncJob> logger)
|
||||
{
|
||||
_productSyncService = productSyncService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task ExecuteAsync()
|
||||
{
|
||||
_logger.LogInformation("Starting product sync...");
|
||||
|
||||
try
|
||||
{
|
||||
await _productSyncService.RunAsync();
|
||||
_logger.LogInformation("Product sync finished.");
|
||||
} catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during product sync.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
45
BimAI.UI.Web/Dockerfile
Normal file
45
BimAI.UI.Web/Dockerfile
Normal file
@@ -0,0 +1,45 @@
|
||||
# Stage 1: Build
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
WORKDIR /src
|
||||
|
||||
# Copy solution and all project files for restore
|
||||
COPY BimAI.sln ./
|
||||
COPY BimAI.UI.Web/BimAI.UI.Web.csproj BimAI.UI.Web/
|
||||
COPY BimAI.UI.Shared/BimAI.UI.Shared.csproj BimAI.UI.Shared/
|
||||
COPY BimAI.Domain/BimAI.Domain.csproj BimAI.Domain/
|
||||
COPY BimAI.Application/BimAI.Application.csproj BimAI.Application/
|
||||
|
||||
# Restore dependencies
|
||||
RUN dotnet restore BimAI.UI.Web/BimAI.UI.Web.csproj
|
||||
|
||||
# Copy all source code
|
||||
COPY . .
|
||||
|
||||
# Build and publish
|
||||
WORKDIR /src/BimAI.UI.Web
|
||||
RUN dotnet publish -c Release -o /app/publish --no-restore
|
||||
|
||||
# Stage 2: Runtime
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
|
||||
WORKDIR /app
|
||||
|
||||
# Set timezone
|
||||
ENV TZ=Europe/Warsaw
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
# Copy published files
|
||||
COPY --from=build /app/publish .
|
||||
|
||||
# Set environment variables
|
||||
ENV ASPNETCORE_ENVIRONMENT=Production
|
||||
ENV ASPNETCORE_URLS=http://0.0.0.0:7143
|
||||
|
||||
# Expose port
|
||||
EXPOSE 7143
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
|
||||
CMD wget --no-verbose --tries=1 --spider http://localhost:7143/health || exit 1
|
||||
|
||||
# Run the application
|
||||
ENTRYPOINT ["dotnet", "BimAI.UI.Web.dll"]
|
||||
@@ -30,6 +30,8 @@ app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
app.UseAntiforgery();
|
||||
|
||||
app.MapGet("/health", () => Results.Ok(new { status = "OK", timestamp = DateTime.UtcNow }));
|
||||
|
||||
app.MapRazorComponents<App>()
|
||||
.AddInteractiveServerRenderMode()
|
||||
.AddAdditionalAssemblies(typeof(MainLayout).Assembly);
|
||||
|
||||
22
BimAI.UI.Web/appsettings.Production.json
Normal file
22
BimAI.UI.Web/appsettings.Production.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ApiSettings": {
|
||||
"BaseUrl": "#{api-base-url}#"
|
||||
},
|
||||
"GoogleAuth": {
|
||||
"ClientId": "#{google-auth-client-id}#"
|
||||
},
|
||||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
"Http": {
|
||||
"Url": "http://0.0.0.0:7143"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
57
docker-compose.yml
Normal file
57
docker-compose.yml
Normal file
@@ -0,0 +1,57 @@
|
||||
services:
|
||||
mssql:
|
||||
image: mcr.microsoft.com/mssql/server:2022-latest
|
||||
container_name: bimai-mssql
|
||||
hostname: bimai-mssql
|
||||
environment:
|
||||
- ACCEPT_EULA=Y
|
||||
- SA_PASSWORD=BimAI_Dev_Pass_2024!
|
||||
- MSSQL_PID=Developer
|
||||
ports:
|
||||
- "1433:1433"
|
||||
volumes:
|
||||
- mssql-data:/var/opt/mssql
|
||||
- ./docker/mssql/init:/docker-entrypoint-initdb.d
|
||||
networks:
|
||||
- bimai-network
|
||||
healthcheck:
|
||||
test: /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "BimAI_Dev_Pass_2024!" -Q "SELECT 1" || exit 1
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
start_period: 10s
|
||||
|
||||
mongodb:
|
||||
image: mongo:7.0
|
||||
container_name: bimai-mongodb
|
||||
hostname: bimai-mongodb
|
||||
environment:
|
||||
- MONGO_INITDB_ROOT_USERNAME=admin
|
||||
- MONGO_INITDB_ROOT_PASSWORD=BimAI_Mongo_2024!
|
||||
- MONGO_INITDB_DATABASE=bimai
|
||||
ports:
|
||||
- "27017:27017"
|
||||
volumes:
|
||||
- mongodb-data:/data/db
|
||||
- mongodb-config:/data/configdb
|
||||
- ./docker/mongodb/init:/docker-entrypoint-initdb.d
|
||||
networks:
|
||||
- bimai-network
|
||||
healthcheck:
|
||||
test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/test --quiet
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 10s
|
||||
|
||||
networks:
|
||||
bimai-network:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
mssql-data:
|
||||
name: bimai-mssql-data
|
||||
mongodb-data:
|
||||
name: bimai-mongodb-data
|
||||
mongodb-config:
|
||||
name: bimai-mongodb-config
|
||||
Reference in New Issue
Block a user