WIP: refactoring pour déploiement
Non testé en conditions réelles. À valider avant de pousser.
This commit is contained in:
parent
2564d9938e
commit
9415521bcb
14 changed files with 125 additions and 28 deletions
|
|
@ -1,8 +1,9 @@
|
|||
# Yavsc parameters
|
||||
|
||||
ANTHROPIC_API_KEY=<votre-clé-api-anthropic>
|
||||
MODERATION_AUTO_REJECT_THRESHOLD=0.9
|
||||
MODERATION_AUTO_APPROVE_THRESHOLD=0.7
|
||||
# Limite par appel
|
||||
|
||||
ANTHROPIC_API_KEY=<votre-clé-api-anthropic>
|
||||
ANTHROPIC_MAX_TOKENS=256 # la modération n'a pas besoin de plus
|
||||
|
||||
POSTGRES_HOST=localhost
|
||||
|
|
@ -20,3 +21,5 @@ ASPNETCORE_Smtp__SenderName"="You Name here"
|
|||
ASPNETCORE_Smtp__SenderEmail"="your@email"
|
||||
ASPNETCORE_Smtp__UserName"="your-smtp-user-name"
|
||||
ASPNETCORE_Smtp__Password="Your pass"
|
||||
|
||||
ASPNETCORE_Kyc__HmacSecret=
|
||||
|
|
|
|||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -12,6 +12,8 @@ test/*/obj/
|
|||
.vs/
|
||||
|
||||
.env
|
||||
.*.env
|
||||
|
||||
*.csproj.lscache
|
||||
data/
|
||||
appsettings.Development.json
|
||||
|
|
|
|||
|
|
@ -2,11 +2,12 @@ APP_PROJECT_NAMES=Api Org Blogs
|
|||
APP_PROJECTS=src/Yavsc.Org/Yavsc.Org.csproj src/Yavsc.Api/Yavsc.Api.csproj
|
||||
SLNDIR=..
|
||||
DESTDIR=/srv/www/yavsc
|
||||
USER_AND_GROUP=www-data:www-data
|
||||
USER_AND_GROUP=yavsc:yavsc
|
||||
CONFIGURATION=Release
|
||||
DOTNET_FRAMEWORK=net10.0
|
||||
|
||||
include $(SLNDIR)/.env
|
||||
include .env
|
||||
|
||||
generated/:
|
||||
@mkdir -p $@
|
||||
|
|
@ -17,6 +18,8 @@ generated/Blogs.service:
|
|||
|
||||
generated/yavsc%.service: generated/ template.service $(SLNDIR)/.env
|
||||
@cat template.service | APP_NAME="$*" \
|
||||
HTTP_HOST="$(HTTP_HOST)" \
|
||||
HTTP_PORT="$*_$(HTTP_PORT)" \
|
||||
DESTDIR="$(DESTDIR)" \
|
||||
APP_SYSLOG_ID="yavsc$*" \
|
||||
POSTGRES_HOST="$(POSTGRES_HOST)" \
|
||||
|
|
@ -38,6 +41,9 @@ copy-service-Blogs: /etc/systemd/system/yavscBlogs.service
|
|||
copy-binaries: build_publish_Org build_publish_Api build_publish_Blogs
|
||||
for project in $(APP_PROJECT_NAMES); \
|
||||
do \
|
||||
LCAPI=$$(echo $${project}|tr [:upper:] [:lower:]) ; \
|
||||
mv $(SLNDIR)/src/Yavsc.$${project}/bin/$(CONFIGURATION)/$(DOTNET_FRAMEWORK)/publish/appsettings-$$LCAPI.json \
|
||||
$(SLNDIR)/src/Yavsc.$${project}/bin/$(CONFIGURATION)/$(DOTNET_FRAMEWORK)/publish/appsettings-$$LCAPI-dist.json ;\
|
||||
sudo cp -a $(SLNDIR)/src/Yavsc.$${project}/bin/$(CONFIGURATION)/$(DOTNET_FRAMEWORK)/publish/* $(DESTDIR) ; \
|
||||
done
|
||||
sudo chown -R $(USER_AND_GROUP) $(DESTDIR)
|
||||
|
|
@ -46,7 +52,6 @@ copy-binaries: build_publish_Org build_publish_Api build_publish_Blogs
|
|||
sudo cp $^ $@
|
||||
sudo chown root:root $@
|
||||
|
||||
|
||||
build_publish_%:
|
||||
ASPNETCORE_ENV=$(CONFIGURATION) dotnet publish $(SLNDIR)/src/Yavsc.$*/Yavsc.$*.csproj
|
||||
|
||||
|
|
@ -58,15 +63,17 @@ install: build_publish copy-binaries copy-services
|
|||
sudo systemctl start yavsc$${project} ; \
|
||||
done
|
||||
|
||||
reinstall: build_publish copy-services copy-binaries
|
||||
reinstall: build_publish stop-services copy-binaries
|
||||
sudo systemctl daemon-reload
|
||||
for project in $(APP_PROJECT_NAMES); \
|
||||
do \
|
||||
sudo systemctl stop yavsc$${project} ; \
|
||||
sudo systemctl start yavsc$${project} ; \
|
||||
done
|
||||
|
||||
stop-services:
|
||||
for project in $(APP_PROJECT_NAMES); \
|
||||
do \
|
||||
sudo systemctl start yavsc$${project} ; \
|
||||
sudo systemctl stop yavsc$${project} ; \
|
||||
done
|
||||
|
||||
$(SLNDIR)/src/Yavsc.Org/bin/$(CONFIGURATION)/$(DOTNET_FRAMEWORK)/publish: build_publish
|
||||
|
|
|
|||
|
|
@ -16,7 +16,17 @@ Restart=always
|
|||
Environment="HOME=$DESTDIR"
|
||||
Environment="ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY"
|
||||
Environment="ANTHROPIC_MAX_TOKENS=$ANTHROPIC_MAX_TOKENS"
|
||||
Environment="ASPNETCORE_Environment=$ENV"
|
||||
Environment="ASPNETCORE_Kestrel__Endpoints__Http=http://$HTTP_HOST:$HTTP_PORT"
|
||||
Environment="ASPNETCORE_ConnectionStrings__YavscConnection=Server=$POSTGRES_HOST;Port=$POSTGRES_PORT;Database=$POSTGRES_DB;Username=$POSTGRES_USER;Password=$POSTGRES_PASSWORD;"
|
||||
|
||||
Environment="ASPNETCORE_Smtp__Host=$ASPNETCORE_Smtp__Host",
|
||||
Environment="ASPNETCORE_Smtp__Port=$ASPNETCORE_Smtp__Port"
|
||||
Environment="ASPNETCORE_Smtp__SenderName=\"$ASPNETCORE_Smtp__SenderName\""
|
||||
Environment="ASPNETCORE_Smtp__SenderEmail=\"$ASPNETCORE_Smtp__SenderEmail\""
|
||||
Environment="ASPNETCORE_Smtp__UserName=$ASPNETCORE_Smtp__UserName"
|
||||
Environment="ASPNETCORE_Smtp__Password=$ASPNETCORE_Smtp__Password"
|
||||
|
||||
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
|
||||
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||
StandardOutput=syslog
|
||||
|
|
|
|||
54
contrib/yavsc-org
Normal file
54
contrib/yavsc-org
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
|
||||
|
||||
server {
|
||||
if ($host = yavsc.pschneider.fr) {
|
||||
return 301 https://$host$request_uri;
|
||||
} # managed by Certbot
|
||||
|
||||
|
||||
|
||||
listen 80;
|
||||
server_name yavsc.pschneider.fr;
|
||||
location / {
|
||||
root /srv/www/yavsc/wwwroot;
|
||||
dav_methods PUT;
|
||||
|
||||
proxy_pass http://127.0.0.1:3003;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection keep-alive;
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name yavsc.pschneider.fr;
|
||||
ssl_certificate /etc/letsencrypt/live/yavsc.pschneider.fr-0001/fullchain.pem; # managed by Certbot
|
||||
ssl_certificate_key /etc/letsencrypt/live/yavsc.pschneider.fr-0001/privkey.pem; # managed by Certbot
|
||||
# Configure the SignalR Endpoint
|
||||
location / {
|
||||
# App server url
|
||||
proxy_pass http://localhost:3003;
|
||||
|
||||
proxy_cache off;
|
||||
# WebSockets were implemented after http/1.0
|
||||
proxy_http_version 1.1;
|
||||
|
||||
# Configuration for ServerSentEvents
|
||||
proxy_buffering off;
|
||||
|
||||
# Configuration for LongPolling or if your KeepAliveInterval is longer than 60 seconds
|
||||
proxy_read_timeout 100s;
|
||||
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -19,6 +19,7 @@ using Yavsc.Abstract.Interfaces;
|
|||
using Yavsc.Helpers;
|
||||
using Yavsc.Interface;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Server.Helpers;
|
||||
using Yavsc.Services;
|
||||
|
||||
internal class Program
|
||||
|
|
@ -29,10 +30,8 @@ internal class Program
|
|||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Configuration
|
||||
.AddJsonFile("appsettings-api.json", optional: false, reloadOnChange: false)
|
||||
.AddJsonFile($"appsettings-api.{builder.Environment.EnvironmentName}.json", optional: false, reloadOnChange: false)
|
||||
.AddEnvironmentVariables();
|
||||
builder.AddConfiguration("api");
|
||||
|
||||
var services = builder.Services;
|
||||
|
||||
// Anthropic client
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
"Https":{
|
||||
"Url": "https://localhost:6001"
|
||||
"Url": "https://localhost:3004"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,10 +29,8 @@ internal class Program
|
|||
Console.Title = "Yavsc.Blogs";
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Configuration
|
||||
.AddJsonFile("appsettings-blogs.json", optional: false, reloadOnChange: false)
|
||||
.AddJsonFile($"appsettings-blogs.{builder.Environment.EnvironmentName}.json", optional: false, reloadOnChange: false)
|
||||
.AddEnvironmentVariables();
|
||||
|
||||
builder.AddConfiguration("blogs");
|
||||
|
||||
var services = builder.Services;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
"Https": {
|
||||
"Url": "https://localhost:5005"
|
||||
"Url": "https://localhost:3003"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using Anthropic.SDK;
|
||||
using Yavsc.Abstract.Interfaces;
|
||||
using Yavsc.Extensions;
|
||||
using Yavsc.Server.Helpers;
|
||||
|
||||
namespace Yavsc
|
||||
{
|
||||
|
|
@ -9,15 +10,14 @@ namespace Yavsc
|
|||
public static async Task Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Configuration
|
||||
.AddJsonFile("appsettings-org.json", optional: false, reloadOnChange: false)
|
||||
.AddJsonFile($"appsettings-org.{builder.Environment.EnvironmentName}.json", optional: false, reloadOnChange: false)
|
||||
.AddEnvironmentVariables();
|
||||
builder.AddConfiguration("org");
|
||||
var app = await builder
|
||||
.ConfigureWebAppServices()
|
||||
.ConfigurePipeline();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -2,14 +2,14 @@
|
|||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning" ,
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.AspNetCore.SignalR": "Debug",
|
||||
"Microsoft.AspNetCore.Http.Connections": "Debug"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"YavscConnection": "Server=[YOURSERVERNAME];Port=5432;Database=[YOURDBNAME];Username=[YOURDBUSERNAME];Password=[YOURDBPASSW];"
|
||||
"YavscConnection": "*** via dotnet user-secrets ou variable d'environnement *** Server=[YOURSERVERNAME];Port=5432;Database=[YOURDBNAME];Username=[YOURDBUSERNAME];Password=[YOURDBPASSW];"
|
||||
},
|
||||
"Site": {
|
||||
"Title": "yavsc",
|
||||
|
|
@ -81,5 +81,12 @@
|
|||
"Moderation": {
|
||||
"AutoApproveThreshold": 0.7,
|
||||
"AutoRejectThreshold": 0.9
|
||||
},
|
||||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
"Http": {
|
||||
"Url": "http://localhost:3002"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
18
src/Yavsc.Server/Helpers/ConfigHelpers.cs
Normal file
18
src/Yavsc.Server/Helpers/ConfigHelpers.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Yavsc.Server.Helpers;
|
||||
|
||||
public static class ConfigHelpers
|
||||
{
|
||||
public static void AddConfiguration(this WebApplicationBuilder builder, string appName )
|
||||
{
|
||||
var rootConfig = builder.Configuration
|
||||
.AddJsonFile($"appsettings-{appName}.json", optional: false, reloadOnChange: false);
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(builder.Environment.EnvironmentName))
|
||||
rootConfig.AddJsonFile($"appsettings-{appName}.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: false);
|
||||
;
|
||||
rootConfig.AddEnvironmentVariables();
|
||||
}
|
||||
}
|
||||
|
|
@ -12,14 +12,12 @@
|
|||
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Yavsc.Server.Helpers;
|
||||
|
||||
JwtSecurityTokenHandler.DefaultMapInboundClaims = true;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Configuration
|
||||
.AddJsonFile("appsettings-web.json", optional: false, reloadOnChange: false)
|
||||
.AddJsonFile($"appsettings-blogs.{builder.Environment.EnvironmentName}.json", optional: false, reloadOnChange: false)
|
||||
.AddEnvironmentVariables();
|
||||
builder.AddConfiguration("web");
|
||||
var authSection = builder.Configuration.GetSection("Authentication");
|
||||
|
||||
var issuer = authSection.GetValue<String>("Issuer");
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Yavsc.Abstract\Yavsc.Abstract.csproj" />
|
||||
<ProjectReference Include="..\Yavsc.Abstract\Yavsc.Server.csproj" />
|
||||
<PackageReference Include="IdentityModel.AspNetCore" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue