From d5f11e83a40f575fd56c699045214db5cf9e460f Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 20 Sep 2026 18:35:27 +0100 Subject: [PATCH 1/2] reprod deployment --- .env.sample | 2 +- README.md | 2 +- contrib/Makefile | 49 ++++++++++++++++++++---------------- contrib/template.service | 6 ++--- contrib/yavsc-org | 54 ---------------------------------------- 5 files changed, 33 insertions(+), 80 deletions(-) delete mode 100644 contrib/yavsc-org diff --git a/.env.sample b/.env.sample index 65926e57f..e94748a2e 100644 --- a/.env.sample +++ b/.env.sample @@ -15,7 +15,7 @@ POSTGRES_HOST=localhost POSTGRES_PORT=5432 POSTGRES_DB=db POSTGRES_USER=pguser -POSTGRES_PASSWORD=pgpassword +POSTGRES_PASSWORD= ANTHROPIC_API_KEY=none ANTHROPIC_MAX_TOKENS=0 diff --git a/README.md b/README.md index 549348f4a..67713fc64 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ make test ### La Prod -`cd srv/Yavsc` : `make pushInProd CONFIGURATION=Release`. +`cd srv/Yavsc/contrib` : `make reinstall CONFIGURATION=Release APP_INSTALL_ENV=production`. puis, pour une première installation `make install_service`. diff --git a/contrib/Makefile b/contrib/Makefile index 4e4ef4df6..71460a544 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -1,23 +1,25 @@ +DESTDIR= +DOTNET_FRAMEWORK=net10.0 APP_PROJECT_NAMES=Org Blogs Api SLNDIR=.. - -include $(SLNDIR)/.env -include .env +APP_INSTALL_ENV=preprod +APP_INSTALL_PREFIX=$(APP_INSTALL_ENV)- +include .$(APP_INSTALL_ENV).env generated/: @mkdir -p $@ -generated/yavscOrg.service: -generated/yavscBlogs.service: -generated/yavscApi.service: +generated/$(APP_INSTALL_PREFIX)yavscOrg.service: +generated/$(APP_INSTALL_PREFIX)yavscBlogs.service: +generated/$(APP_INSTALL_PREFIX)yavscApi.service: -generated/yavsc%.service: generated/ template.service $(SLNDIR)/.env +generated/$(APP_INSTALL_PREFIX)yavsc%.service: generated/ template.service $(SLNDIR)/.env @cat template.service | APP_NAME="$*" \ DESTDIR="$(DESTDIR)" \ HTTP_HOST="$(HTTP_HOST)" \ HTTP_PORT="$*_$(HTTP_PORT)" \ - BASEAPPDIR="$(BASEAPPDIR)" \ - APP_SYSLOG_ID="yavsc$*" \ + APPDIR="$(APPDIR)" \ + APP_SYSLOG_ID="$(APP_INSTALL_PREFIX)yavsc$*" \ POSTGRES_HOST="$(POSTGRES_HOST)" \ POSTGRES_PORT="$(POSTGRES_PORT)" \ POSTGRES_DB="$(POSTGRES_DB)" \ @@ -34,11 +36,13 @@ generated/yavsc%.service: generated/ template.service $(SLNDIR)/.env envsubst > $@ @echo Created service file: $@ +generate-service-units: generated/$(APP_INSTALL_PREFIX)yavscOrg.service generated/$(APP_INSTALL_PREFIX)yavscBlogs.service generated/$(APP_INSTALL_PREFIX)yavscApi.service -copy-services: copy-service-Org copy-service-Blogs copy-service-Api -copy-service-Org: /etc/systemd/system/yavscOrg.service -copy-service-Blogs: /etc/systemd/system/yavscBlogs.service -copy-service-Api: /etc/systemd/system/yavscApi.service +install-service-%: /etc/systemd/system/$(APP_INSTALL_PREFIX)yavsc%.service + sudo systemctl daemon-reload + sudo systemctl enable $(APP_INSTALL_PREFIX)yavsc$* + +install-services: install-service-Org install-service-Blogs install-service-Api copy-binaries: build_publish_Org build_publish_Blogs build_publish_Api stop-services @for project in $(APP_PROJECT_NAMES); \ @@ -52,23 +56,23 @@ copy-binaries: build_publish_Org build_publish_Blogs build_publish_Api stop-serv rm -f $${BINDIR}/appsettings-$${LCAPI}.json ; \ sync ; \ ls $${BINDIR}/appsettings* 2>&1 ; \ - sudo cp -a $${BINDIR}/* $(BASEAPPDIR) ; \ + sudo cp -a $${BINDIR}/* $(DESTDIR)$(APPDIR) ; \ done - @sudo chown -R $(USER_AND_GROUP) $(BASEAPPDIR) + @sudo chown -R $(USER_AND_GROUP) $(DESTDIR)$(APPDIR) + @sync -/etc/systemd/system/yavsc%.service: generated/yavsc%.service + +$(DESTDIR)/etc/systemd/system/$(APP_INSTALL_PREFIX)yavsc%.service: generated/$(APP_INSTALL_PREFIX)yavsc%.service sudo cp $^ $@ sudo chown root:root $@ build_publish_%: clean_publish_dir_% @ASPNETCORE_ENV=$(CONFIGURATION) dotnet publish $(SLNDIR)/src/Yavsc.$*/Yavsc.$*.csproj -build_publish: build_publish_Org build_publish_Blogs build_publish_Api - clean_publish_dir_%: @rm -rf $(SLNDIR)/src/Yavsc.$*/bin/$(CONFIGURATION)/$(DOTNET_FRAMEWORK)/publish -install: build_publish copy-binaries copy-services +install: copy-binaries copy-services @sudo systemctl daemon-reload @for project in $(APP_PROJECT_NAMES); \ do \ @@ -77,10 +81,13 @@ install: build_publish copy-binaries copy-services done reinstall: copy-binaries - @sync @for project in $(APP_PROJECT_NAMES); do \ sudo systemctl start yavsc$${project} ; done +reinstall-pre: copy-binaries + @for project in $(APP_PROJECT_NAMES); do \ + sudo systemctl start yavscPre$${project} ; done + stop-services: @for project in $(APP_PROJECT_NAMES); \ do \ @@ -93,7 +100,7 @@ $(SLNDIR)/src/Yavsc.Api/bin/$(CONFIGURATION)/$(DOTNET_FRAMEWORK)/publish: build_ showConfig: @echo CONFIGURATION: $(CONFIGURATION) - @echo BASEAPPDIR: $(BASEAPPDIR) + @echo APPDIR: $(APPDIR) showApiLogs: @sudo journalctl -u yavscApi.service -S "2 min ago" | tee yavscApi.log diff --git a/contrib/template.service b/contrib/template.service index b075c4da1..38ba2c82a 100644 --- a/contrib/template.service +++ b/contrib/template.service @@ -10,10 +10,10 @@ RestartSec=5s Type=simple User=yavsc Group=yavsc -WorkingDirectory=$DESTDIR -ExecStart=$DESTDIR/Yavsc.$APP_NAME +WorkingDirectory=$APPDIR +ExecStart=$APPDIR/Yavsc.$APP_NAME Restart=always -Environment="HOME=$DESTDIR" +Environment="HOME=$APPDIR" Environment="ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY" Environment="ANTHROPIC_MAX_TOKENS=$ANTHROPIC_MAX_TOKENS" Environment="ASPNETCORE_Environment=$ENV" diff --git a/contrib/yavsc-org b/contrib/yavsc-org deleted file mode 100644 index dc65aa9fe..000000000 --- a/contrib/yavsc-org +++ /dev/null @@ -1,54 +0,0 @@ - - -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; - } -} - From 93fd4e61ad82c3ec46c522f471832d3e0cc4b422 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 20 Sep 2026 21:06:02 +0100 Subject: [PATCH 2/2] code cleaup --- contrib/template.service | 2 -- src/Yavsc.Org.Tests/MarkdownTests.cs | 34 ------------------------- src/Yavsc.Server/Services/MailSender.cs | 4 +++ 3 files changed, 4 insertions(+), 36 deletions(-) delete mode 100644 src/Yavsc.Org.Tests/MarkdownTests.cs diff --git a/contrib/template.service b/contrib/template.service index 38ba2c82a..3959c7151 100644 --- a/contrib/template.service +++ b/contrib/template.service @@ -29,8 +29,6 @@ Environment="ASPNETCORE_Smtp__Password=\"$ASPNETCORE_Smtp__Password\"" CapabilityBoundingSet=CAP_NET_BIND_SERVICE AmbientCapabilities=CAP_NET_BIND_SERVICE -StandardOutput=syslog -StandardError=syslog SyslogIdentifier=$APP_SYSLOG_ID [Install] diff --git a/src/Yavsc.Org.Tests/MarkdownTests.cs b/src/Yavsc.Org.Tests/MarkdownTests.cs deleted file mode 100644 index 1bd0db9c5..000000000 --- a/src/Yavsc.Org.Tests/MarkdownTests.cs +++ /dev/null @@ -1,34 +0,0 @@ -using DotMarkdown.Linq; -using Markdig; -using Xunit; -using static DotMarkdown.Linq.MFactory; - - -public class MarkdownTests -{ - [Fact] - public void TestMarkdownRendering() - { - MDocument document = Document( - Heading1("Markdown Sample"), - Heading2("Bullet List"), - BulletList( - "text", - Bold("bold text")), - HorizontalRule(), - Heading2("IndentedCodeBlock"), - IndentedCodeBlock("string s = null;")); - - Console.WriteLine(document.ToString()); - - } - - [Fact] - public void TestAnotherMarkdownRendering() - { - var result = Markdown.ToHtml("This is a text with some *emphasis*"); - - - Console.WriteLine(result); - } -} diff --git a/src/Yavsc.Server/Services/MailSender.cs b/src/Yavsc.Server/Services/MailSender.cs index 81518eddb..9a6c60ed9 100644 --- a/src/Yavsc.Server/Services/MailSender.cs +++ b/src/Yavsc.Server/Services/MailSender.cs @@ -140,6 +140,10 @@ namespace Yavsc.Services catch (FormatException ex) { logger.LogError(ex, "Refusing to send email because the recipient or sender address is malformed. To={To}, From={From}", email, siteSettings.Owner.EMail); + logger.LogError(ex.Message); + if (ex.InnerException!=null) + logger.LogError(ex.InnerException.Message); + return string.Empty; } catch (SmtpCommandException ex)