From 78c3644b2c86938a3a57b48f66e0257d501782da Mon Sep 17 00:00:00 2001 From: lzw-723 Date: Sat, 21 Mar 2026 22:05:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 5 ++++ Dockerfile | 66 +++++++++++++++++++++++++++++++++++++--------- docker-compose.yml | 21 +++++++++++++++ 3 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore index 69e4249..1820a50 100644 --- a/.dockerignore +++ b/.dockerignore @@ -8,5 +8,10 @@ build/ .idea/ .packages +# Frontend build artifacts (we build in Docker) +web/.svelte-kit/ +web/node_modules/ + +# Data and cache (mounted at runtime) data cache \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index c333dee..6faceb3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,63 @@ -# Use latest stable channel SDK. -FROM dart:stable AS build +# Stage 1: Build frontend +FROM node:22-alpine AS frontend-build + +WORKDIR /app/web + +# Install pnpm +RUN corepack enable && corepack prepare pnpm@latest --activate + +# Copy frontend package files +COPY web/package.json web/pnpm-lock.yaml web/pnpm-workspace.yaml ./ + +# Install dependencies +RUN pnpm install --frozen-lockfile + +# Copy frontend source +COPY web/ ./ + +# Build frontend +RUN pnpm build + +# Stage 2: Build backend +FROM dart:stable AS backend-build -# Resolve app dependencies. WORKDIR /app + +# Resolve app dependencies COPY pubspec.* ./ RUN dart pub get -# Copy app source code (except anything in .dockerignore) and AOT compile app. -COPY . . +# Copy app source code and compile +COPY bin/ ./bin/ +COPY --from=frontend-build /app/web/build ./web/build/ + RUN dart compile exe bin/server.dart -o bin/server -# Build minimal serving image from AOT-compiled `/server` -# and the pre-built AOT-runtime in the `/runtime/` directory of the base image. -FROM scratch -COPY --from=build /runtime/ / -COPY --from=build /app/bin/server /app/bin/ +# Stage 3: Runtime image with libvips +FROM debian:bookworm-slim AS runtime -# Start server. +# Install libvips and ca-certificates +RUN apt-get update && apt-get install -y --no-install-recommends \ + libvips42 \ + ca-certificates \ + curl \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# Copy the AOT runtime and compiled server from build stage +COPY --from=backend-build /runtime/ / +COPY --from=backend-build /app/bin/server /app/bin/ +COPY --from=backend-build /app/web/build /app/web/build + +# Create data and cache directories +RUN mkdir -p /app/data /app/cache + +# Expose port EXPOSE 8080 -CMD ["/app/bin/server"] + +# Set environment variables +ENV PORT=8080 + +# Start server +CMD ["/app/bin/server"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..942c932 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +services: + loongyan: + build: + context: . + dockerfile: Dockerfile + image: loongyan:latest + container_name: loongyan + ports: + - "8080:8080" + volumes: + - ./data:/app/data + - ./cache:/app/cache + environment: + - PORT=8080 + restart: unless-stopped + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8080/api/v1/"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 10s \ No newline at end of file