cpa01 commited on
Commit
1313c62
·
verified ·
1 Parent(s): b141b4b

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +61 -0
Dockerfile ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # --- STAGE 1: Builder ---
2
+ FROM node:20-slim AS builder
3
+ WORKDIR /app
4
+
5
+ # Install build tools yang dibutuhkan untuk native modules & git
6
+ RUN apt-get update && apt-get install -y --no-install-recommends \
7
+ ca-certificates \
8
+ git \
9
+ python3 \
10
+ make \
11
+ g++ \
12
+ && rm -rf /var/lib/apt/lists/*
13
+
14
+ # Clone repository
15
+ RUN git clone https://github.com/decolua/9router.git .
16
+
17
+ # Install dependencies & build aplikasi
18
+ RUN npm install --legacy-peer-deps
19
+ RUN npm run build
20
+
21
+
22
+ # --- STAGE 2: Runner (Production) ---
23
+ FROM node:20-slim AS runner
24
+ WORKDIR /app
25
+
26
+ # Install ca-certificates, curl, dan gunakan script resmi Cloudflare
27
+ # Ini otomatis mendeteksi arsitektur CPU (AMD64 / ARM64) di Hugging Face
28
+ RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl \
29
+ && curl -L https://pkg.cloudflare.com/cloudflare-main.gpg -o /usr/share/keyrings/cloudflare-main.gpg \
30
+ && 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 \
31
+ && apt-get update && apt-get install -y cloudflared \
32
+ && apt-get purge -y --auto-remove curl \
33
+ && rm -rf /var/lib/apt/lists/*
34
+
35
+ # Set environment ke production
36
+ ENV NODE_ENV=production
37
+ ENV PORT=7860
38
+ ENV HOSTNAME=0.0.0.0
39
+
40
+ # Hanya salin hasil build dan file yang dibutuhkan dari stage builder
41
+ COPY --from=builder /app /app
42
+
43
+ # Buat startup script secara inline untuk menjalankan Tunnel dan Node app
44
+ RUN echo '#!/bin/sh\n\
45
+ if [ -z "$TUNNEL_TOKEN" ]; then\n\
46
+ echo "Menjalankan Cloudflare Quick Tunnel (Random URL)..."\n\
47
+ cloudflared tunnel --url http://127.0.0.1:$PORT &\n\
48
+ else\n\
49
+ echo "Menjalankan Cloudflare Tunnel dengan Token..."\n\
50
+ cloudflared tunnel --no-autoupdate run --token $TUNNEL_TOKEN &\n\
51
+ fi\n\
52
+ echo "Menjalankan aplikasi Node.js..."\n\
53
+ exec npm run start' > /app/start.sh
54
+
55
+ # Berikan akses eksekusi pada script
56
+ RUN chmod +x /app/start.sh
57
+
58
+ EXPOSE 7860
59
+
60
+ # Gunakan script sebagai command utama
61
+ CMD ["/app/start.sh"]