更新dockerfile
This commit is contained in:
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"]
|
||||
Reference in New Issue
Block a user