更新dockerfile
This commit is contained in:
@@ -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
|
||||
66
Dockerfile
66
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"]
|
||||
21
docker-compose.yml
Normal file
21
docker-compose.yml
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user