35 lines
940 B
Docker
35 lines
940 B
Docker
FROM node:21-alpine AS base
|
|
|
|
WORKDIR /app
|
|
|
|
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
|
|
RUN \
|
|
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
|
elif [ -f package-lock.json ]; then npm ci; \
|
|
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
|
|
else echo "Lockfile not found." && exit 1; \
|
|
fi
|
|
|
|
# Rebuild the source code only when needed
|
|
FROM base AS builder
|
|
WORKDIR /app
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
|
|
# Set the environment to production
|
|
ENV NODE_ENV=production
|
|
|
|
# Build the scripts
|
|
RUN \
|
|
if [ -f yarn.lock ]; then yarn run build; \
|
|
elif [ -f package-lock.json ]; then npm run build; \
|
|
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
|
|
else echo "Lockfile not found." && exit 1; \
|
|
fi
|
|
|
|
FROM nginx:alpine AS runner
|
|
|
|
COPY --from=builder /app/dist/ /usr/share/nginx/html
|
|
|
|
EXPOSE 80
|
|
CMD ["nginx", "-g", "daemon off;"] |