File size: 1,759 Bytes
5878f15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# 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"]