feat: add docker web image support
This commit is contained in:
parent
a4890b6ea0
commit
1dd71a2e23
|
@ -0,0 +1,25 @@
|
|||
# Prevent leaking host-specific caches/paths into the image
|
||||
.dockerignore
|
||||
.git
|
||||
.gitignore
|
||||
.idea
|
||||
.vscode
|
||||
**/.DS_Store
|
||||
build/
|
||||
.dart_tool/
|
||||
.flutter-plugins
|
||||
.flutter-plugins-dependencies
|
||||
.packages
|
||||
pubspec.lock # keep if you want reproducible, comment out to include
|
||||
# Flutter/Platform build outputs
|
||||
android/
|
||||
ios/
|
||||
linux/
|
||||
macos/
|
||||
windows/
|
||||
web/.dart_tool/
|
||||
# Tests and dev artifacts (optional, not needed in image build stage)
|
||||
test/
|
||||
integration_test/
|
||||
coverage/
|
||||
custom_lint.log
|
|
@ -0,0 +1,39 @@
|
|||
## Two-stage build for minimal Flutter web static server (Caddy runtime)
|
||||
# Stage 1: Build the Flutter web app
|
||||
FROM ghcr.io/cirruslabs/flutter:latest AS build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy pubspec first for better layer caching
|
||||
COPY pubspec.* ./
|
||||
RUN flutter pub get
|
||||
|
||||
# Copy the rest of the project
|
||||
COPY . .
|
||||
|
||||
# Ensure no host caches leak into the container
|
||||
RUN rm -rf .dart_tool build && \
|
||||
flutter pub get && \
|
||||
flutter gen-l10n && \
|
||||
flutter build web --release -O4 --wasm
|
||||
|
||||
# Stage 2: Caddy (Alpine) to serve static files with SPA fallback
|
||||
FROM caddy:2-alpine AS runtime
|
||||
WORKDIR /usr/share/caddy
|
||||
# Copy built web assets
|
||||
COPY --from=build /app/build/web/ /usr/share/caddy/
|
||||
# Write Caddyfile inline (listens on :8080 and SPA fallback)
|
||||
RUN cat > /etc/caddy/Caddyfile <<'CADDY'
|
||||
{
|
||||
admin off
|
||||
}
|
||||
|
||||
:8080 {
|
||||
root * /usr/share/caddy
|
||||
encode zstd gzip
|
||||
# SPA fallback: serve index.html if file not found
|
||||
try_files {path} /index.html
|
||||
file_server
|
||||
}
|
||||
CADDY
|
||||
EXPOSE 8080
|
20
README.md
20
README.md
|
@ -39,13 +39,31 @@ flutter build windows
|
|||
flutter pub run msix:create
|
||||
```
|
||||
|
||||
For web
|
||||
#### web
|
||||
|
||||
```bash
|
||||
flutter build web
|
||||
# flutter build web --release -O4 --wasm
|
||||
```
|
||||
Open the `index.html` file in the `build/web` directory. Remove the `<base href="/">` to ensure proper routing on GitHub Pages.
|
||||
|
||||
##### Docker
|
||||
|
||||
To build and run a minimal Docker image serving static Flutter web files:
|
||||
|
||||
```bash
|
||||
# Build the Docker image
|
||||
docker build -t pdf_signature .
|
||||
|
||||
# Run the container (serves static files on port 8080)
|
||||
docker run --rm -p 8080:8080 pdf_signature
|
||||
```
|
||||
Access your app at [http://localhost:8080](http://localhost:8080)
|
||||
|
||||
#### Linux
|
||||
|
||||
For Linux
|
||||
|
||||
```bash
|
||||
flutter build linux
|
||||
cp -r build/linux/x64/release/bundle/ AppDir
|
||||
|
|
Loading…
Reference in New Issue