Update web example with WASM build and static-web-server

- Use --wasm flag for WebAssembly compilation
- Add cache-busting for JS/WASM assets
- Replace nginx with static-web-server on scratch (~18MB)
- Run as non-root user

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Mathias Beaulieu-Duncan 2026-02-03 03:56:27 -05:00
parent b5ccf2effa
commit 26797d954d

View File

@ -34,17 +34,28 @@ Lightweight Flutter SDK images for CI/CD pipelines. Built on [Wolfi](https://wol
## Dockerfile Examples
### Web App
### Web App (WASM)
```dockerfile
FROM svrnty/flutter-sdk:web-latest AS build
COPY . /app
WORKDIR /app
RUN flutter pub get && flutter build web --release
COPY . .
RUN flutter pub get && flutter build web --wasm --release
FROM nginx:alpine
COPY --from=build /app/build/web /usr/share/nginx/html
EXPOSE 80
# Cache-busting: append version to JS/WASM references
RUN VERSION=$(date +%s) && cd build/web && \
sed -i "s|flutter_bootstrap\.js\"|flutter_bootstrap.js?v=${VERSION}\"|g" index.html && \
sed -i "s|main\.dart\.js\"|main.dart.js?v=${VERSION}\"|g" flutter_bootstrap.js && \
sed -i "s|main\.dart\.mjs\"|main.dart.mjs?v=${VERSION}\"|g" flutter_bootstrap.js && \
sed -i "s|main\.dart\.wasm\"|main.dart.wasm?v=${VERSION}\"|g" flutter_bootstrap.js
FROM ghcr.io/static-web-server/static-web-server:2 AS sws
FROM scratch
COPY --from=sws /static-web-server /static-web-server
COPY --from=build /app/build/web /public
EXPOSE 8080
USER 65534
ENTRYPOINT ["/static-web-server", "-p", "8080", "-d", "/public"]
```
### Android APK