# Multi-stage build untuk HF Spaces # Stage 1: Build Next.js FROM node:18-alpine AS nextjs-builder WORKDIR /app # Install dependencies COPY package.json package-lock.json* ./ RUN npm ci --only=production # Copy source dan build COPY . . RUN npm run build # Stage 2: Jekyll + Ruby FROM ruby:3.1-alpine AS final # Install system dependencies RUN apk add --no-cache \ build-base \ git \ nodejs \ npm \ curl \ bash \ tzdata # Install Jekyll dan Bundler RUN gem install jekyll bundler && gem cleanup # Set working directory WORKDIR /app # Copy Next.js build dari stage sebelumnya COPY --from=nextjs-builder /app/.next ./.next COPY --from=nextjs-builder /app/node_modules ./node_modules COPY --from=nextjs-builder /app/package.json ./package.json COPY --from=nextjs-builder /app/public ./public # Copy sisa files COPY . . # Create user dan directories untuk HF Spaces RUN addgroup -g 1000 appuser && \ adduser -D -s /bin/bash -u 1000 -G appuser appuser # Create directories dengan proper permissions RUN mkdir -p /app/projects /app/templates /app/.next && \ chmod -R 755 /app && \ chown -R appuser:appuser /app # Copy dan setup entrypoint COPY entrypoint-hf.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh && \ chown appuser:appuser /usr/local/bin/entrypoint.sh # Switch ke non-root user USER appuser # Expose port untuk HF Spaces EXPOSE 7860 # Environment variables ENV PORT=7860 ENV NODE_ENV=production ENV JEKYLL_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 ENV CI=true # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ CMD curl -f http://localhost:7860/api/health || exit 1 ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] CMD ["start"]