From fe1e731e44b4cba9ab750137a5b2f4502258aa0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Mon, 13 Apr 2026 09:02:52 +0200 Subject: [PATCH] prod build fix --- README.md | 21 ++++++++-------- frontend/Dockerfile | 4 +-- frontend/angular.json | 50 ++++++++++++++++++++++++++++++++++---- frontend/package.json | 4 ++- reverse-proxy/default.conf | 15 ++++-------- 5 files changed, 65 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 0d81b78..06709a8 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,17 @@ # RouterOS Backup Manager Next -## Produkcja w Dockerze +## Deploy in docker ```bash cp .env.example .env -# uzupełnij SECRET_KEY i DEFAULT_ADMIN_PASSWORD -./start_prod.sh ``` -Domyślnie frontend będzie dostępny na: -- `http://127.0.0.1:5581` +# edit SECRET_KEY & DEFAULT_ADMIN_PASSWORD -## Migracja starej bazy Flask/SQLite -Jeżeli masz starą bazę `backup_routeros.db`, możesz zaimportować dane: -```bash -cd backend -PYTHONPATH=. python scripts/migrate_legacy_sqlite.py /sciezka/do/backup_routeros.db -``` +`bash start_prod.sh` + +or + +`docker compose up -d` + +## Default app port: +`http://127.0.0.1:5581` diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 248a647..142d644 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -3,9 +3,9 @@ WORKDIR /app COPY frontend/package*.json /app/ RUN npm ci || npm install COPY frontend /app -RUN npm run build +RUN npm run build:prod -FROM nginx:1.29-alpine +FROM nginx:mainline COPY frontend/nginx/default.conf /etc/nginx/conf.d/default.conf COPY --from=build /app/dist/routeros-backup-manager-next-ui/browser /usr/share/nginx/html EXPOSE 80 diff --git a/frontend/angular.json b/frontend/angular.json index 16e94f4..5183941 100644 --- a/frontend/angular.json +++ b/frontend/angular.json @@ -14,24 +14,64 @@ "outputPath": "dist/routeros-backup-manager-next-ui", "index": "src/index.html", "browser": "src/main.ts", - "polyfills": ["zone.js"], + "polyfills": [ + "zone.js" + ], "tsConfig": "tsconfig.app.json", - "assets": ["src/favicon.ico", "src/assets"], + "assets": [ + "src/favicon.ico", + "src/assets" + ], "styles": [ "node_modules/primeicons/primeicons.css", "node_modules/primeng/resources/themes/lara-light-blue/theme.css", "node_modules/primeng/resources/primeng.min.css", "src/styles.css" ] - } + }, + "configurations": { + "production": { + "optimization": true, + "outputHashing": "all", + "sourceMap": false, + "extractLicenses": true, + "budgets": [ + { + "type": "initial", + "maximumWarning": "1mb", + "maximumError": "2mb" + }, + { + "type": "anyComponentStyle", + "maximumWarning": "10kb", + "maximumError": "20kb" + } + ] + }, + "development": { + "optimization": false, + "sourceMap": true, + "extractLicenses": false + } + }, + "defaultConfiguration": "production" }, "serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { "buildTarget": "routeros-backup-manager-next-ui:build" - } + }, + "configurations": { + "production": { + "buildTarget": "routeros-backup-manager-next-ui:build:production" + }, + "development": { + "buildTarget": "routeros-backup-manager-next-ui:build:development" + } + }, + "defaultConfiguration": "development" } } } } -} \ No newline at end of file +} diff --git a/frontend/package.json b/frontend/package.json index 5ef412d..0ef572d 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -6,7 +6,9 @@ "start": "ng serve --host 127.0.0.1 --port 4200 --proxy-config proxy.conf.json", "start:lan": "ng serve --host 0.0.0.0 --port 4200 --proxy-config proxy.conf.json", "build": "ng build", - "test": "ng test" + "test": "ng test", + "build:prod": "ng build --configuration production", + "build:dev": "ng build --configuration development" }, "dependencies": { "@angular/animations": "^17.3.0", diff --git a/reverse-proxy/default.conf b/reverse-proxy/default.conf index cc902ee..7aa9fa9 100644 --- a/reverse-proxy/default.conf +++ b/reverse-proxy/default.conf @@ -8,11 +8,6 @@ upstream backend_upstream { keepalive 16; } -map $uri $static_file { - ~*\.(?:css|js|mjs|png|jpg|jpeg|gif|svg|ico|webp|woff2?)$ 1; - default 0; -} - server { listen 80; server_name _; @@ -53,13 +48,13 @@ server { proxy_pass http://backend_upstream/redoc; } + location ~* \.(?:css|js|mjs|png|jpg|jpeg|gif|svg|ico|webp|woff2?)$ { + proxy_pass http://frontend_upstream; + add_header Cache-Control "public, max-age=31536000, immutable" always; + } + location / { proxy_pass http://frontend_upstream; - - if ($static_file) { - add_header Cache-Control "public, max-age=31536000, immutable" always; - } - add_header Cache-Control "no-store, no-cache" always; } }