diff --git a/.gitea/workflows/build-and-deploy.yml b/.gitea/workflows/build-and-deploy.yml index fafb7ca..38a466c 100644 --- a/.gitea/workflows/build-and-deploy.yml +++ b/.gitea/workflows/build-and-deploy.yml @@ -34,6 +34,7 @@ jobs: --build-arg MAPBOX_ACCESS_TOKEN="${{ secrets.MAPBOX_ACCESS_TOKEN }}" \ --build-arg MAPBOX_STYLE="mapbox/streets-v12" \ --build-arg TELEGRAM_BOT_USERNAME="carfteebot" \ + --build-arg BUILD_VERSION="${GITHUB_SHA}" \ .; then published_images="$(docker image ls --format '{{.Repository}}:{{.Tag}}' | awk -v sha="$IMAGE_SHA" -v latest="$IMAGE_LATEST" '$0 == sha || $0 == latest')" if [ -n "$published_images" ]; then diff --git a/Dockerfile b/Dockerfile index f9b4581..959ec22 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,13 +3,21 @@ WORKDIR /app ARG MAPBOX_ACCESS_TOKEN="" ARG MAPBOX_STYLE="mapbox/streets-v12" ARG TELEGRAM_BOT_USERNAME="carfteebot" +ARG BUILD_VERSION="local" COPY pubspec.* ./ RUN flutter pub get COPY . . -RUN flutter build web --release \ +RUN rm -rf build/web && \ + flutter build web --release --base-href=/ -o build/web \ --dart-define=MAPBOX_ACCESS_TOKEN="$MAPBOX_ACCESS_TOKEN" \ --dart-define=MAPBOX_STYLE="$MAPBOX_STYLE" \ - --dart-define=TELEGRAM_BOT_USERNAME="$TELEGRAM_BOT_USERNAME" + --dart-define=TELEGRAM_BOT_USERNAME="$TELEGRAM_BOT_USERNAME" && \ + cp web/index.prod.html build/web/index.html && \ + rm -f build/web/index.prod.html && \ + dart run sw:generate \ + --input=build/web \ + --prefix=mapflow \ + --version="$BUILD_VERSION" FROM nginx:1.27-alpine COPY nginx.conf /etc/nginx/conf.d/default.conf diff --git a/nginx.conf b/nginx.conf index 5776e0d..f1a64f8 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,11 +1,52 @@ server { listen 80; server_name _; + + gzip on; + gzip_comp_level 6; + gzip_min_length 1024; + gzip_vary on; + gzip_types + application/javascript + application/json + application/manifest+json + application/wasm + image/svg+xml + text/css + text/plain; + + etag on; + root /usr/share/nginx/html; index index.html; + client_max_body_size 25m; - location / { - try_files $uri $uri/ /index.html; + location = /index.html { + add_header Cache-Control "no-cache" always; + add_header Pragma "no-cache" always; + add_header Expires "0" always; + try_files /index.html =404; + } + + location ~* ^/(bootstrap\.js|sw\.js)$ { + add_header Cache-Control "no-cache" always; + add_header Pragma "no-cache" always; + add_header Expires "0" always; + try_files $uri =404; + } + + location ~* ^/(manifest\.json|version\.json)$ { + add_header Cache-Control "no-cache" always; + add_header Pragma "no-cache" always; + add_header Expires "0" always; + try_files $uri =404; + } + + location ~* ^/(flutter_service_worker\.js|flutter_bootstrap\.js|flutter\.js)$ { + add_header Cache-Control "no-cache" always; + add_header Pragma "no-cache" always; + add_header Expires "0" always; + return 410; } location = /graphql { @@ -25,4 +66,31 @@ server { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } + + location ~* ^/assets/.*\.(otf|ttf|woff|woff2)$ { + add_header Cache-Control "public, max-age=31536000, immutable" always; + add_header Access-Control-Allow-Origin "*" always; + types { + font/otf otf; + font/ttf ttf; + font/woff woff; + font/woff2 woff2; + } + try_files $uri =404; + } + + location ~* ^/(assets|canvaskit|icons)/ { + add_header Cache-Control "public, max-age=31536000, immutable" always; + try_files $uri =404; + } + + location ~* \.(js|mjs|wasm|json|png|jpg|jpeg|gif|webp|svg|ico|woff|woff2|ttf)$ { + add_header Cache-Control "public, max-age=31536000, immutable" always; + try_files $uri =404; + } + + location / { + add_header Cache-Control "no-cache" always; + try_files $uri $uri/ /index.html; + } } diff --git a/pubspec.lock b/pubspec.lock index 3d47261..f1c07c5 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1037,6 +1037,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.4.1" + sw: + dependency: "direct dev" + description: + name: sw + sha256: c3c7cb2e728ce068d79e61b7c2e8944de67567acc06a3594ae303f3884089ac4 + url: "https://pub.dev" + source: hosted + version: "0.1.5" term_glyph: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 3906016..17b8a09 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -62,6 +62,7 @@ dev_dependencies: flutter_lints: ^6.0.0 ferry_generator: ^0.12.0+5 build_runner: ^2.15.0 + sw: ^0.1.5 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/web/index.prod.html b/web/index.prod.html new file mode 100644 index 0000000..e4460fa --- /dev/null +++ b/web/index.prod.html @@ -0,0 +1,95 @@ + + +
+