Spaces:
Running
Running
FROM node:20-alpine AS base | |
# Frontend build | |
FROM base AS frontend-deps | |
RUN apk add --no-cache libc6-compat | |
WORKDIR /app | |
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ | |
RUN \ | |
if [ -f yarn.lock ]; then \ | |
echo "Installing dependencies with yarn..." && \ | |
yarn --frozen-lockfile || exit 1; \ | |
elif [ -f package-lock.json ]; then \ | |
echo "Installing dependencies with npm..." && \ | |
npm ci || exit 1; \ | |
elif [ -f pnpm-lock.yaml ]; then \ | |
echo "Installing dependencies with pnpm..." && \ | |
yarn global add pnpm && pnpm i --frozen-lockfile || exit 1; \ | |
else \ | |
echo "No lockfile found. Please provide either yarn.lock, package-lock.json, or pnpm-lock.yaml" && \ | |
exit 1; \ | |
fi | |
FROM base AS frontend-builder | |
WORKDIR /app | |
COPY --from=frontend-deps /app/node_modules ./node_modules | |
COPY . . | |
RUN npm run build | |
# Backend build | |
FROM python:3.9-slim AS backend | |
WORKDIR /backend | |
COPY backend/requirements.txt . | |
RUN pip install --no-cache-dir -r requirements.txt | |
COPY backend . | |
# Final image | |
FROM python:3.9-slim AS runner | |
WORKDIR /app | |
ENV NODE_ENV production | |
# Install Node.js and wget | |
RUN apt-get update && apt-get install -y curl wget && \ | |
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ | |
apt-get install -y nodejs && \ | |
apt-get clean && \ | |
rm -rf /var/lib/apt/lists/* | |
RUN addgroup --system --gid 1001 nodejs && \ | |
adduser --system --uid 1001 nextjs | |
COPY --from=frontend-builder /app/public ./frontend/public | |
COPY --from=frontend-builder --chown=nextjs:nodejs /app/.next/standalone ./frontend | |
COPY --from=frontend-builder --chown=nextjs:nodejs /app/.next/static ./frontend/.next/static | |
COPY --from=frontend-builder --chown=nextjs:nodejs /app/.next/cache ./frontend/.next/cache | |
COPY --from=backend /backend ./backend | |
COPY --from=backend /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages | |
COPY start.sh . | |
RUN chmod +x start.sh | |
EXPOSE 3000 8000 | |
CMD ["./start.sh"] |