43 lines
987 B
Docker
43 lines
987 B
Docker
# Base Image
|
|
FROM node:22-alpine AS base
|
|
WORKDIR /app
|
|
|
|
# Enable pnpm
|
|
RUN corepack enable && corepack prepare pnpm@latest --activate
|
|
|
|
# Copy manifest files first to cache dependencies
|
|
COPY pnpm-lock.yaml package.json ./
|
|
|
|
# Install dependencies
|
|
RUN pnpm install
|
|
|
|
# --- Development Stage ---
|
|
FROM base AS development
|
|
COPY . .
|
|
# Astro default port
|
|
EXPOSE 4321
|
|
# --host is required to expose the server to the container
|
|
CMD ["pnpm", "dev", "--host"]
|
|
|
|
# --- Build Stage ---
|
|
FROM base AS build
|
|
COPY . .
|
|
RUN pnpm build
|
|
|
|
# --- Production Stage ---
|
|
FROM base AS production
|
|
WORKDIR /app
|
|
|
|
# We install 'serve' globally here so we don't rely on node_modules
|
|
# This keeps the final image smaller/cleaner
|
|
RUN npm install -g serve
|
|
|
|
# Copy the built output from the build stage
|
|
# Astro outputs to 'dist' by default
|
|
COPY --from=build /app/dist ./dist
|
|
COPY serve.json ./dist
|
|
|
|
# Expose the port you want for production (e.g., 3000)
|
|
EXPOSE 5000
|
|
|
|
CMD ["serve", "dist", "-l", "5000", "--config", "serve.json"] |