feat: refine dockerfile to deploy on host service provider

This commit is contained in:
insleker 2025-09-04 18:04:15 +08:00
parent 1dd71a2e23
commit bec3f38cc5
2 changed files with 40 additions and 4 deletions

View File

@ -23,3 +23,24 @@ test/
integration_test/
coverage/
custom_lint.log
test_cache/
unit_test_assets/
# Docs and repo meta to avoid cache busting
docs/
**/*.md
wireframe.assets/
AGENTS.md
README.md
LICENSE
# Packaging artifacts not needed for web image
AppDir/
AppRun
pdf_signature.desktop
tool/
*.iml
*.ipr
*.iws
.github/
.husky/

View File

@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1.7-labs
## 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
@ -6,13 +7,17 @@ WORKDIR /app
# Copy pubspec first for better layer caching
COPY pubspec.* ./
RUN flutter pub get
# Use BuildKit cache for Dart pub cache
RUN --mount=type=cache,target=/root/.pub-cache \
flutter pub get
# Copy the rest of the project
COPY . .
# Ensure no host caches leak into the container
RUN rm -rf .dart_tool build && \
# Ensure no host caches leak into the container; use BuildKit caches for pub and Flutter
RUN --mount=type=cache,target=/root/.pub-cache \
--mount=type=cache,target=/sdks/flutter/bin/cache \
rm -rf .dart_tool build && \
flutter pub get && \
flutter gen-l10n && \
flutter build web --release -O4 --wasm
@ -23,12 +28,13 @@ 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)
ENV PORT=8080
RUN cat > /etc/caddy/Caddyfile <<'CADDY'
{
admin off
}
:8080 {
:{$PORT} {
root * /usr/share/caddy
encode zstd gzip
# SPA fallback: serve index.html if file not found
@ -36,4 +42,13 @@ RUN cat > /etc/caddy/Caddyfile <<'CADDY'
file_server
}
CADDY
# Some platforms (e.g., gVisor/Firecracker like Render) forbid file capabilities; strip and copy to a clean path
USER root
RUN apk add --no-cache libcap && \
(setcap -r /usr/bin/caddy || true) && \
install -m 0755 /usr/bin/caddy /caddy && \
apk del libcap
# Use numeric UID/GID for caddy to avoid passwd lookup issues across platforms
USER 65532:65532
EXPOSE 8080
ENTRYPOINT ["/caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]