File size: 2,026 Bytes
1313c62 | 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 | # --- STAGE 1: Builder ---
FROM node:20-slim AS builder
WORKDIR /app
# Install build tools yang dibutuhkan untuk native modules & git
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
git \
python3 \
make \
g++ \
&& rm -rf /var/lib/apt/lists/*
# Clone repository
RUN git clone https://github.com/decolua/9router.git .
# Install dependencies & build aplikasi
RUN npm install --legacy-peer-deps
RUN npm run build
# --- STAGE 2: Runner (Production) ---
FROM node:20-slim AS runner
WORKDIR /app
# Install ca-certificates, curl, dan gunakan script resmi Cloudflare
# Ini otomatis mendeteksi arsitektur CPU (AMD64 / ARM64) di Hugging Face
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl \
&& curl -L https://pkg.cloudflare.com/cloudflare-main.gpg -o /usr/share/keyrings/cloudflare-main.gpg \
&& echo "deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared bookworm main" | tee /etc/apt/sources.list.d/cloudflared.list \
&& apt-get update && apt-get install -y cloudflared \
&& apt-get purge -y --auto-remove curl \
&& rm -rf /var/lib/apt/lists/*
# Set environment ke production
ENV NODE_ENV=production
ENV PORT=7860
ENV HOSTNAME=0.0.0.0
# Hanya salin hasil build dan file yang dibutuhkan dari stage builder
COPY --from=builder /app /app
# Buat startup script secara inline untuk menjalankan Tunnel dan Node app
RUN echo '#!/bin/sh\n\
if [ -z "$TUNNEL_TOKEN" ]; then\n\
echo "Menjalankan Cloudflare Quick Tunnel (Random URL)..."\n\
cloudflared tunnel --url http://127.0.0.1:$PORT &\n\
else\n\
echo "Menjalankan Cloudflare Tunnel dengan Token..."\n\
cloudflared tunnel --no-autoupdate run --token $TUNNEL_TOKEN &\n\
fi\n\
echo "Menjalankan aplikasi Node.js..."\n\
exec npm run start' > /app/start.sh
# Berikan akses eksekusi pada script
RUN chmod +x /app/start.sh
EXPOSE 7860
# Gunakan script sebagai command utama
CMD ["/app/start.sh"] |