Deploy: QA and production Docker setup, serve web app from the API, report menu names

- deploy/qa and deploy/prod: Dockerfile (API + built web app), compose, .env.example, Apache vhost templates
- API serves wwwroot with an SPA fallback that leaves file requests to the static file middleware
- Docker/ENVIRONMENTS docs for QA and production
- Reports menu: drop the word تقرير from the item names

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Samer Salameh 2026-11-12 17:31:22 +03:00
parent b88ced45c4
commit e24ab12182
12 changed files with 200 additions and 12 deletions

14
.dockerignore Normal file
View File

@ -0,0 +1,14 @@
**/bin/
**/obj/
**/node_modules/
**/dist/
.git/
.claude/
.vs/
tests/
# secrets and per-developer settings never go into an image
**/appsettings.Local.json
**/.env.local
**/.env.*.local
deploy/qa/.env
deploy/prod/.env

2
.gitignore vendored
View File

@ -21,3 +21,5 @@ TestResults/
# stray empty lockfile at the repository root (the real one is web/package-lock.json) # stray empty lockfile at the repository root (the real one is web/package-lock.json)
/package-lock.json /package-lock.json
deploy/qa/.env
deploy/prod/.env

10
deploy/prod/.env.example Normal file
View File

@ -0,0 +1,10 @@
# Copy to .env on the production server (git-ignored, chmod 600) and fill in. See docs/ENVIRONMENTS.md.
# The API refuses to start while a connection string or Jwt__Key is missing, so fill these in before `docker compose up`.
ConnectionStrings__NAFITHTCS=User Id=ntp;Password=zaPRFN$do36;Data Source=10.20.1.7:1521/nafithmain;Min Pool Size=5;Max Pool Size=100;Connection Timeout=15;Statement Cache Size=50
ConnectionStrings__NtpSchema=User Id=nafithtcs;Password=sLDDo83@fs;Data Source=10.20.1.7:1521/nafithmain;Min Pool Size=5;Max Pool Size=100;Connection Timeout=15;Statement Cache Size=50
# at least 32 random characters, a NEW value for production (openssl rand -base64 48)
Jwt__Key=ItSCgUNhyCt1ZuYaJigPr9HDgSNR3eo/3v6eXp8OSWI+6OEW55E417QmCbpNzqb/
# origin users open in the browser, exactly as typed in the address bar
Cors__AllowedOrigins__0=https://ntpv2.nafith.net
# logins that may hold role SU (none by default in production), e.g. Auth__SuperUsers__0=login
# NTP_PORT=8081

View File

@ -0,0 +1,27 @@
# Apache virtual hosts that publish the production container as https://<production-host>/
# NOT applied by the deployment. Replace <production-host>, the certificate paths and the upstream address (the host and the
# NTP_PORT of the container), then:
# sudo a2enmod proxy proxy_http headers rewrite ssl
# sudo a2ensite ntp-prod && sudo apachectl configtest && sudo systemctl reload apache2
<VirtualHost *:80>
ServerName <production-host>
RewriteEngine On
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
</VirtualHost>
<VirtualHost *:443>
ServerName <production-host>
ErrorLog ${APACHE_LOG_DIR}/ntp_prod_error.log
CustomLog ${APACHE_LOG_DIR}/ntp_prod_access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/certificate/<production-host>.cer
SSLCertificateKeyFile /etc/apache2/certificate/<production-host>.key
ProxyPreserveHost On
RequestHeader set X-Forwarded-Proto "https"
ProxyTimeout 120
ProxyPass / http://127.0.0.1:8081/
ProxyPassReverse / http://127.0.0.1:8081/
</VirtualHost>

View File

@ -0,0 +1,19 @@
# Production: one container (API + web app). Same image recipe as QA (deploy/qa/Dockerfile) built in production mode
# (web/.env.production). A reverse proxy publishes it over https; see apache-ntp.conf.
# Run from this folder after creating .env (copy .env.example): docker compose up -d --build
services:
ntp:
image: ntpv2:prod
container_name: ntpv2-prod
build:
context: ../..
dockerfile: deploy/prod/Dockerfile
args:
WEB_MODE: build:prod
restart: unless-stopped
env_file: .env
environment:
ASPNETCORE_ENVIRONMENT: Production
ports:
# change the left side (or set NTP_PORT in .env) when 8081 is taken; use 127.0.0.1: when the proxy runs on this host
- "127.0.0.1:${NTP_PORT:-8081}:8080"

6
deploy/qa/.env.example Normal file
View File

@ -0,0 +1,6 @@
# Copy to .env on the server (git-ignored, chmod 600) and fill in. See docs/ENVIRONMENTS.md.
ConnectionStrings__NAFITHTCS=User Id=<schema>;Password=<secret>;Data Source=<host>:1521/<service>;Min Pool Size=1;Max Pool Size=50;Connection Timeout=15;Statement Cache Size=50
ConnectionStrings__NtpSchema=User Id=<schema>;Password=<secret>;Data Source=<host>:1521/<service>;Min Pool Size=1;Max Pool Size=50;Connection Timeout=15;Statement Cache Size=50
# at least 32 random characters, e.g. openssl rand -base64 48
Jwt__Key=
Cors__AllowedOrigins__0=https://ntpv2.nafithit.com

26
deploy/qa/Dockerfile Normal file
View File

@ -0,0 +1,26 @@
# One image for QA / production: the .NET API plus the built web app (served from wwwroot by the API).
# Build context is the repository root: docker build -f deploy/qa/Dockerfile -t ntpv2:qa .
FROM node:22-alpine AS web
WORKDIR /web
COPY web/package.json web/package-lock.json ./
RUN npm ci
COPY web/ ./
# Vite mode decides the env file: build:qa -> web/.env.qa, build:prod -> web/.env.production
ARG WEB_MODE=build:qa
RUN npm run ${WEB_MODE}
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS api
WORKDIR /src
COPY Directory.Build.props Directory.Packages.props NTP.slnx ./
COPY src/ src/
RUN dotnet publish src/NTP.Api/NTP.Api.csproj -c Release -o /app /p:UseAppHost=false
FROM mcr.microsoft.com/dotnet/aspnet:10.0
WORKDIR /app
COPY --from=api /app ./
COPY --from=web /web/dist ./wwwroot
ENV ASPNETCORE_URLS=http://+:8080 \
ASPNETCORE_FORWARDEDHEADERS_ENABLED=true
EXPOSE 8080
ENTRYPOINT ["dotnet", "NTP.Api.dll"]

View File

@ -0,0 +1,28 @@
# Apache virtual hosts that publish the QA container (127.0.0.1:8081) as https://ntpv2.nafithit.com/
# NOT applied by the deployment: add it to /etc/apache2/sites-available/ntpv2.conf, then
# sudo a2enmod proxy proxy_http headers rewrite ssl
# sudo a2ensite ntpv2 && sudo apachectl configtest && sudo systemctl reload apache2
# Replace the two certificate paths with a certificate that covers ntpv2.nafithit.com
# (the existing nafithnet2025 certificate is for *.nafith.net only).
<VirtualHost *:80>
ServerName ntpv2.nafithit.com
RewriteEngine On
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
</VirtualHost>
<VirtualHost *:443>
ServerName ntpv2.nafithit.com
ErrorLog ${APACHE_LOG_DIR}/ntpv2_error.log
CustomLog ${APACHE_LOG_DIR}/ntpv2_access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/certificate/ntpv2.nafithit.com.cer
SSLCertificateKeyFile /etc/apache2/certificate/ntpv2.nafithit.com.key
ProxyPreserveHost On
RequestHeader set X-Forwarded-Proto "https"
ProxyTimeout 120
ProxyPass / http://127.0.0.1:8081/
ProxyPassReverse / http://127.0.0.1:8081/
</VirtualHost>

View File

@ -0,0 +1,15 @@
# QA: one container (API + web app) on 0.0.0.0:8081. A reverse proxy (Apache) publishes it as https://ntpv2.nafithit.com/
# Run from this folder after creating .env (copy .env.example): docker compose up -d --build
services:
ntpv2:
image: ntpv2:qa
container_name: ntpv2
build:
context: ../..
dockerfile: deploy/qa/Dockerfile
restart: unless-stopped
env_file: .env
environment:
ASPNETCORE_ENVIRONMENT: QA
ports:
- "0.0.0.0:8081:8080"

View File

@ -94,3 +94,32 @@ dotnet run --launch-profile https-qa # https://localhost:7181
- [ ] `/health/ready` is Healthy - [ ] `/health/ready` is Healthy
- [ ] web built with the matching mode and published behind the same origin as `/api` (or `VITE_API_BASE` set) - [ ] web built with the matching mode and published behind the same origin as `/api` (or `VITE_API_BASE` set)
- [ ] sign in as SU and as one limited role and compare the menu with the permission table - [ ] sign in as SU and as one limited role and compare the menu with the permission table
## QA server (Docker)
One container holds the API and the built web app (the API serves `wwwroot`), listening on `127.0.0.1:8081` of the QA server. A reverse
proxy publishes it as `https://ntpv2.nafithit.com/` (`deploy/qa/apache-ntpv2.conf` is the Apache virtual host; it is applied by hand).
```bash
cd deploy/qa
cp .env.example .env # fill in the Oracle connection strings and Jwt__Key; never commit .env
docker compose up -d --build
```
Checks: `curl http://127.0.0.1:8081/health/ready` answers `Healthy`; `docker logs ntpv2` shows the log. Redeploy = copy the new source and run the
last command again. The server copy lives in `/opt/ntpv2/src`.
## Production server (Docker)
Same one-container layout as QA, built with the production web settings (`web/.env.production`) and `ASPNETCORE_ENVIRONMENT=Production`
(Swagger off, warning level logs, no SU logins unless `Auth__SuperUsers__0` is set).
```bash
cd deploy/prod
cp .env.example .env # Oracle connection strings of the PRODUCTION database, a new Jwt__Key, the public origin
chmod 600 .env
docker compose up -d --build
```
`deploy/prod/apache-ntp.conf` is the matching Apache virtual host (applied by hand). Run the `db/` scripts listed above on the production
database first. Check with `curl http://127.0.0.1:8081/health/ready` (`Healthy` means Oracle answers) and `docker logs ntpv2-prod`.

View File

@ -58,10 +58,22 @@ if (app.Environment.IsDevelopment())
app.UseSwaggerUI(o => o.SwaggerEndpoint("/openapi/v1.json", "NTP API v1")); app.UseSwaggerUI(o => o.SwaggerEndpoint("/openapi/v1.json", "NTP API v1"));
} }
// Container deployment: the image copies the built web app (web/dist) into wwwroot and the API serves it, so the
// reverse proxy in front only needs this one upstream. Not present in Development (Vite serves the web app there).
var serveWeb = app.Environment.WebRootPath is { } webRoot && File.Exists(Path.Combine(webRoot, "index.html"));
if (serveWeb)
{
app.UseDefaultFiles();
app.UseStaticFiles();
}
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
app.MapControllers(); app.MapControllers();
// Browser routes of the single page app: not the API, not a health check and not a file (no dot in the path). A matched
// endpoint makes the static file middleware step aside, so file requests (assets/x.js) must NOT match this route.
if (serveWeb) app.MapFallbackToFile("{*path:regex(^(?!api/|health/)[^.]*$)}", "index.html").AllowAnonymous();
// Liveness: process is up. Readiness: Oracle reachable. // Liveness: process is up. Readiness: Oracle reachable.
app.MapHealthChecks("/health/live", new HealthCheckOptions { Predicate = _ => false }).AllowAnonymous(); app.MapHealthChecks("/health/live", new HealthCheckOptions { Predicate = _ => false }).AllowAnonymous();

View File

@ -12,13 +12,13 @@ export default defineStrings({
'rpt.menu.imports': { en: 'File imports', ar: 'تحميل الملفات' }, 'rpt.menu.imports': { en: 'File imports', ar: 'تحميل الملفات' },
'rpt.menu.dashboard': { en: 'Trips dashboard', ar: 'لوحة الرحلات' }, 'rpt.menu.dashboard': { en: 'Trips dashboard', ar: 'لوحة الرحلات' },
'rpt.menu.numOfTrips': { en: 'Trucks and trips per company', ar: 'عدد الشاحنات والرحلات لكل شركة' }, 'rpt.menu.numOfTrips': { en: 'Trucks and trips per company', ar: 'عدد الشاحنات والرحلات لكل شركة' },
'rpt.menu.quota': { en: 'Quota report', ar: 'تقرير المحاصصة' }, 'rpt.menu.quota': { en: 'Quota', ar: 'المحاصصة' },
'rpt.menu.frequency': { en: 'Trip frequency', ar: 'تكرار الرحلات' }, 'rpt.menu.frequency': { en: 'Trip frequency', ar: 'تكرار الرحلات' },
'rpt.menu.distribution': { en: 'Trips distribution', ar: 'توزيع الرحلات' }, 'rpt.menu.distribution': { en: 'Trips distribution', ar: 'توزيع الرحلات' },
'rpt.menu.details': { en: 'Detailed report', ar: 'التقرير التفصيلي' }, 'rpt.menu.details': { en: 'Detailed', ar: 'التفصيلي' },
'rpt.menu.phoneApprovals': { en: 'Approvals file (IVR)', ar: 'تحميل ملف الموافقات' }, 'rpt.menu.phoneApprovals': { en: 'Approvals file (IVR)', ar: 'تحميل ملف الموافقات' },
'rpt.menu.wbFiles': { en: 'Weighbridge files', ar: 'ملفات القبان' }, 'rpt.menu.wbFiles': { en: 'Weighbridge files', ar: 'ملفات القبان' },
'rpt.menu.motMulti': { en: 'Multi-trip report (MOT)', ar: 'تقرير تعدد الرحلات' }, 'rpt.menu.motMulti': { en: 'Multi-trip (MOT)', ar: 'تعدد الرحلات' },
// ---- common page bits // ---- common page bits
'rpt.from': { en: 'From', ar: 'من' }, 'rpt.from': { en: 'From', ar: 'من' },
@ -111,20 +111,20 @@ export default defineStrings({
'rpt.mot.note': { en: 'Based on all grains permits recorded in the system (no date filter, as in the legacy report).', ar: 'بناءً على جميع إرساليات الحبوب المسجلة في النظام (بدون فلترة بالتاريخ كما في التقرير القديم).' }, 'rpt.mot.note': { en: 'Based on all grains permits recorded in the system (no date filter, as in the legacy report).', ar: 'بناءً على جميع إرساليات الحبوب المسجلة في النظام (بدون فلترة بالتاريخ كما في التقرير القديم).' },
// ---- table reports: titles // ---- table reports: titles
'rpt.t.weighbridge-events': { en: 'Loading and discharge weighbridge movements', ar: 'تقارير حركات قبان التحميل والتفريغ' }, 'rpt.t.weighbridge-events': { en: 'Loading and discharge weighbridge movements', ar: 'حركات قبان التحميل والتفريغ' },
'rpt.t.waybridge-summary': { en: 'Weighbridge movements - totals', ar: 'حركات القبان - تقرير إجمالي' }, 'rpt.t.waybridge-summary': { en: 'Weighbridge movements - totals', ar: 'حركات القبان - إجمالي' },
'rpt.t.waybridge-details': { en: 'Weighbridge movements - details', ar: 'حركات القبان - تقرير تفصيلي' }, 'rpt.t.waybridge-details': { en: 'Weighbridge movements - details', ar: 'حركات القبان - تفصيلي' },
'rpt.t.loading-weights': { en: 'Loading weights', ar: 'تقرير أوزان التحميل' }, 'rpt.t.loading-weights': { en: 'Loading weights', ar: 'أوزان التحميل' },
'rpt.t.closed-permits': { en: 'Completed permits', ar: 'الارساليات المكتملة' }, 'rpt.t.closed-permits': { en: 'Completed permits', ar: 'الارساليات المكتملة' },
'rpt.t.incapability': { en: 'Shortage report', ar: 'تقرير العجز' }, 'rpt.t.incapability': { en: 'Shortage', ar: 'العجز' },
'rpt.t.tender-order': { en: 'Tender order permits', ar: 'ارسالية عطاء التموين' }, 'rpt.t.tender-order': { en: 'Tender order permits', ar: 'ارسالية عطاء التموين' },
'rpt.t.distribution-summary': { en: 'Distribution summary', ar: 'ملخص التوزيع' }, 'rpt.t.distribution-summary': { en: 'Distribution summary', ar: 'ملخص التوزيع' },
'rpt.t.order-distribution': { en: 'Bulk order distribution ratios', ar: 'نسب التوزيع في طلبيات السائب' }, 'rpt.t.order-distribution': { en: 'Bulk order distribution ratios', ar: 'نسب التوزيع في طلبيات السائب' },
'rpt.t.call-list': { en: 'IVR call list', ar: 'قائمة الاتصال الآلي' }, 'rpt.t.call-list': { en: 'IVR call list', ar: 'قائمة الاتصال الآلي' },
'rpt.t.companies-turn': { en: 'Companies turn', ar: 'تقرير دور الشركات' }, 'rpt.t.companies-turn': { en: 'Companies turn', ar: 'دور الشركات' },
'rpt.t.owners-turn': { en: 'Individuals turn', ar: 'تقرير دور الأفراد' }, 'rpt.t.owners-turn': { en: 'Individuals turn', ar: 'دور الأفراد' },
'rpt.t.drivers': { en: 'Registered drivers', ar: 'تقرير السائقين المسجلين' }, 'rpt.t.drivers': { en: 'Registered drivers', ar: 'السائقين المسجلين' },
'rpt.t.trucks': { en: 'Registered trucks', ar: 'تقرير القاطرات المسجلة' }, 'rpt.t.trucks': { en: 'Registered trucks', ar: 'القاطرات المسجلة' },
'rpt.t.mot-grain-cube': { en: 'Grain cube (MOT)', ar: 'مكعب الحبوب (وزارة النقل)' }, 'rpt.t.mot-grain-cube': { en: 'Grain cube (MOT)', ar: 'مكعب الحبوب (وزارة النقل)' },
'rpt.t.mot-grain-frequency': { en: 'Grain trip frequency (MOT)', ar: 'تكرار رحلات الحبوب (وزارة النقل)' }, 'rpt.t.mot-grain-frequency': { en: 'Grain trip frequency (MOT)', ar: 'تكرار رحلات الحبوب (وزارة النقل)' },
'rpt.t.shortageTotal': { en: 'Total shortage', ar: 'إجمالي العجز' }, 'rpt.t.shortageTotal': { en: 'Total shortage', ar: 'إجمالي العجز' },