diff --git a/.env.sample b/.env.sample index e94748a2e..65926e57f 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= +POSTGRES_PASSWORD=pgpassword ANTHROPIC_API_KEY=none ANTHROPIC_MAX_TOKENS=0 diff --git a/README.md b/README.md index 67713fc64..549348f4a 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ make test ### La Prod -`cd srv/Yavsc/contrib` : `make reinstall CONFIGURATION=Release APP_INSTALL_ENV=production`. +`cd srv/Yavsc` : `make pushInProd CONFIGURATION=Release`. puis, pour une première installation `make install_service`. diff --git a/contrib/Makefile b/contrib/Makefile index 71460a544..4e4ef4df6 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -1,25 +1,23 @@ -DESTDIR= -DOTNET_FRAMEWORK=net10.0 APP_PROJECT_NAMES=Org Blogs Api SLNDIR=.. -APP_INSTALL_ENV=preprod -APP_INSTALL_PREFIX=$(APP_INSTALL_ENV)- -include .$(APP_INSTALL_ENV).env + +include $(SLNDIR)/.env +include .env generated/: @mkdir -p $@ -generated/$(APP_INSTALL_PREFIX)yavscOrg.service: -generated/$(APP_INSTALL_PREFIX)yavscBlogs.service: -generated/$(APP_INSTALL_PREFIX)yavscApi.service: +generated/yavscOrg.service: +generated/yavscBlogs.service: +generated/yavscApi.service: -generated/$(APP_INSTALL_PREFIX)yavsc%.service: generated/ template.service $(SLNDIR)/.env +generated/yavsc%.service: generated/ template.service $(SLNDIR)/.env @cat template.service | APP_NAME="$*" \ DESTDIR="$(DESTDIR)" \ HTTP_HOST="$(HTTP_HOST)" \ HTTP_PORT="$*_$(HTTP_PORT)" \ - APPDIR="$(APPDIR)" \ - APP_SYSLOG_ID="$(APP_INSTALL_PREFIX)yavsc$*" \ + BASEAPPDIR="$(BASEAPPDIR)" \ + APP_SYSLOG_ID="yavsc$*" \ POSTGRES_HOST="$(POSTGRES_HOST)" \ POSTGRES_PORT="$(POSTGRES_PORT)" \ POSTGRES_DB="$(POSTGRES_DB)" \ @@ -36,13 +34,11 @@ generated/$(APP_INSTALL_PREFIX)yavsc%.service: generated/ template.service $(SLN 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 -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-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 copy-binaries: build_publish_Org build_publish_Blogs build_publish_Api stop-services @for project in $(APP_PROJECT_NAMES); \ @@ -56,23 +52,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}/* $(DESTDIR)$(APPDIR) ; \ + sudo cp -a $${BINDIR}/* $(BASEAPPDIR) ; \ done - @sudo chown -R $(USER_AND_GROUP) $(DESTDIR)$(APPDIR) - @sync + @sudo chown -R $(USER_AND_GROUP) $(BASEAPPDIR) - -$(DESTDIR)/etc/systemd/system/$(APP_INSTALL_PREFIX)yavsc%.service: generated/$(APP_INSTALL_PREFIX)yavsc%.service +/etc/systemd/system/yavsc%.service: generated/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: copy-binaries copy-services +install: build_publish copy-binaries copy-services @sudo systemctl daemon-reload @for project in $(APP_PROJECT_NAMES); \ do \ @@ -81,13 +77,10 @@ install: 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 \ @@ -100,7 +93,7 @@ $(SLNDIR)/src/Yavsc.Api/bin/$(CONFIGURATION)/$(DOTNET_FRAMEWORK)/publish: build_ showConfig: @echo CONFIGURATION: $(CONFIGURATION) - @echo APPDIR: $(APPDIR) + @echo BASEAPPDIR: $(BASEAPPDIR) showApiLogs: @sudo journalctl -u yavscApi.service -S "2 min ago" | tee yavscApi.log diff --git a/contrib/template.service b/contrib/template.service index 3959c7151..b075c4da1 100644 --- a/contrib/template.service +++ b/contrib/template.service @@ -10,10 +10,10 @@ RestartSec=5s Type=simple User=yavsc Group=yavsc -WorkingDirectory=$APPDIR -ExecStart=$APPDIR/Yavsc.$APP_NAME +WorkingDirectory=$DESTDIR +ExecStart=$DESTDIR/Yavsc.$APP_NAME Restart=always -Environment="HOME=$APPDIR" +Environment="HOME=$DESTDIR" Environment="ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY" Environment="ANTHROPIC_MAX_TOKENS=$ANTHROPIC_MAX_TOKENS" Environment="ASPNETCORE_Environment=$ENV" @@ -29,6 +29,8 @@ 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/contrib/yavsc-org b/contrib/yavsc-org new file mode 100644 index 000000000..dc65aa9fe --- /dev/null +++ b/contrib/yavsc-org @@ -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; + } +} + diff --git a/src/Yavsc.Org.Tests/MarkdownTests.cs b/src/Yavsc.Org.Tests/MarkdownTests.cs new file mode 100644 index 000000000..1bd0db9c5 --- /dev/null +++ b/src/Yavsc.Org.Tests/MarkdownTests.cs @@ -0,0 +1,34 @@ +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 9a6c60ed9..81518eddb 100644 --- a/src/Yavsc.Server/Services/MailSender.cs +++ b/src/Yavsc.Server/Services/MailSender.cs @@ -140,10 +140,6 @@ 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)