Subham9126 commited on
Commit
b00cd33
Β·
verified Β·
1 Parent(s): 0122e2f

Upload 5 files

Browse files
Files changed (3) hide show
  1. Dockerfile +27 -15
  2. nginx.conf +1 -12
  3. start.sh +11 -9
Dockerfile CHANGED
@@ -1,16 +1,17 @@
1
- FROM docker.redpanda.com/redpandadata/redpanda:v23.3.11 AS redpanda
2
- FROM nginx:1.25-alpine AS final
 
3
 
4
- # ── Install Redpanda into nginx image ─────────────────────────────────────────
5
- COPY --from=redpanda /usr/bin/redpanda /usr/bin/redpanda
6
- COPY --from=redpanda /usr/bin/rpk /usr/bin/rpk
7
- COPY --from=redpanda /usr/lib/redpanda /usr/lib/redpanda
8
- COPY --from=redpanda /etc/redpanda /etc/redpanda
9
 
10
- # ── Install runtime deps ───────────────────────────────────────────────────────
11
- RUN apk add --no-cache bash curl netcat-openbsd gettext
 
 
 
 
12
 
13
- # ── Copy all config files from root ───────────────────────────────────────────
14
  COPY redpanda.yaml /etc/redpanda/redpanda.yaml
15
  COPY nginx.conf /etc/nginx/nginx.conf
16
  COPY start.sh /start.sh
@@ -18,11 +19,22 @@ COPY init-topics.sh /init-topics.sh
18
 
19
  RUN chmod +x /start.sh /init-topics.sh
20
 
21
- # ── Data dir ──────────────────────────────────────────────────────────────────
22
- RUN mkdir -p /var/lib/redpanda/data && \
23
- chown -R 1000:1000 /var/lib/redpanda /etc/redpanda /start.sh /init-topics.sh
24
-
25
- # HF Spaces only exposes 7860 β€” everything goes through nginx
 
 
 
 
 
 
 
 
 
 
 
26
  EXPOSE 7860
27
 
28
  USER 1000
 
1
+ # Use Redpanda as the base β€” its binary needs /opt/redpanda/libexec at runtime
2
+ # and cannot be copied into another image
3
+ FROM docker.redpanda.com/redpandadata/redpanda:v23.3.11
4
 
5
+ USER root
 
 
 
 
6
 
7
+ # ── Install nginx + deps on top of the Redpanda (Debian-based) image ──────────
8
+ RUN apt-get update && apt-get install -y --no-install-recommends \
9
+ nginx \
10
+ curl \
11
+ netcat-openbsd \
12
+ && rm -rf /var/lib/apt/lists/*
13
 
14
+ # ── Copy all config files (flat root layout) ──────────────────────────────────
15
  COPY redpanda.yaml /etc/redpanda/redpanda.yaml
16
  COPY nginx.conf /etc/nginx/nginx.conf
17
  COPY start.sh /start.sh
 
19
 
20
  RUN chmod +x /start.sh /init-topics.sh
21
 
22
+ # ── nginx needs these dirs writable by user 1000 ──────────────────────────────
23
+ RUN mkdir -p /var/lib/redpanda/data \
24
+ /var/log/nginx \
25
+ /var/lib/nginx \
26
+ /run \
27
+ && chown -R 1000:1000 \
28
+ /var/lib/redpanda \
29
+ /etc/redpanda \
30
+ /var/log/nginx \
31
+ /var/lib/nginx \
32
+ /run \
33
+ /etc/nginx \
34
+ /start.sh \
35
+ /init-topics.sh
36
+
37
+ # HF Spaces only exposes 7860 publicly
38
  EXPOSE 7860
39
 
40
  USER 1000
nginx.conf CHANGED
@@ -1,6 +1,7 @@
1
  worker_processes auto;
2
  error_log /dev/stderr warn;
3
  pid /tmp/nginx.pid;
 
4
 
5
  events {
6
  worker_connections 1024;
@@ -101,15 +102,3 @@ http {
101
  }
102
  }
103
  }
104
-
105
- # ── TCP stream proxy for native Kafka protocol (port 9092) ────────────────────
106
- # NOTE: HF Spaces only exposes port 7860 via HTTPS externally.
107
- # The Kafka binary protocol (TCP) requires a direct TCP connection.
108
- # Use the HTTP proxy paths above for external access.
109
- # For same-network (another HF Space or internal service), connect to :9092 directly.
110
- stream {
111
- server {
112
- listen 7861;
113
- proxy_pass 127.0.0.1:9092;
114
- }
115
- }
 
1
  worker_processes auto;
2
  error_log /dev/stderr warn;
3
  pid /tmp/nginx.pid;
4
+ worker_rlimit_nofile 8192;
5
 
6
  events {
7
  worker_connections 1024;
 
102
  }
103
  }
104
  }
 
 
 
 
 
 
 
 
 
 
 
 
start.sh CHANGED
@@ -32,6 +32,7 @@ until curl -sf http://127.0.0.1:9644/v1/status/ready > /dev/null 2>&1; do
32
  ATTEMPTS=$((ATTEMPTS+1))
33
  if [ $ATTEMPTS -gt 60 ]; then
34
  echo "ERROR: Redpanda failed to start after 120s"
 
35
  exit 1
36
  fi
37
  echo " ... waiting (${ATTEMPTS}/60)"
@@ -43,29 +44,30 @@ echo " βœ“ Redpanda ready"
43
  echo "[3/4] Initializing topics..."
44
  /init-topics.sh
45
 
46
- # ── 4. Start nginx (routes everything through port 7860) ─────────────────────
47
  echo "[4/4] Starting nginx on :7860..."
48
- nginx -g "daemon off;" &
 
 
49
  NGINX_PID=$!
50
 
51
  echo ""
52
  echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
53
  echo " βœ… All services up on port 7860"
54
  echo ""
55
- echo " GET /health β†’ broker status"
56
- echo " * /kafka/... β†’ HTTP REST proxy"
57
- echo " * /admin/... β†’ admin API"
58
- echo " * /schema/... β†’ schema registry"
59
  echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
60
 
61
- # ── Trap shutdown signals ─────────────────────────────────────────────────────
62
  cleanup() {
63
  echo "Shutting down..."
64
- kill $NGINX_PID 2>/dev/null || true
65
  kill $REDPANDA_PID 2>/dev/null || true
66
  exit 0
67
  }
68
  trap cleanup SIGTERM SIGINT
69
 
70
- # ── Keep alive ────────────────────────────────────────────────────────────────
71
  wait $REDPANDA_PID
 
32
  ATTEMPTS=$((ATTEMPTS+1))
33
  if [ $ATTEMPTS -gt 60 ]; then
34
  echo "ERROR: Redpanda failed to start after 120s"
35
+ kill $REDPANDA_PID 2>/dev/null || true
36
  exit 1
37
  fi
38
  echo " ... waiting (${ATTEMPTS}/60)"
 
44
  echo "[3/4] Initializing topics..."
45
  /init-topics.sh
46
 
47
+ # ── 4. Start nginx on :7860 ───────────────────────────────────────────────────
48
  echo "[4/4] Starting nginx on :7860..."
49
+ # Debian nginx binary lives at /usr/sbin/nginx
50
+ # pid to /tmp β€” writable by uid 1000
51
+ /usr/sbin/nginx -g "daemon off; pid /tmp/nginx.pid;" &
52
  NGINX_PID=$!
53
 
54
  echo ""
55
  echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
56
  echo " βœ… All services up on port 7860"
57
  echo ""
58
+ echo " GET /health β†’ broker ready check"
59
+ echo " * /kafka/... β†’ HTTP REST proxy (pandaproxy)"
60
+ echo " * /admin/... β†’ admin API"
61
+ echo " * /schema/... β†’ schema registry"
62
  echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
63
 
64
+ # ── Graceful shutdown ─────────────────────────────────────────────────────────
65
  cleanup() {
66
  echo "Shutting down..."
67
+ kill $NGINX_PID 2>/dev/null || true
68
  kill $REDPANDA_PID 2>/dev/null || true
69
  exit 0
70
  }
71
  trap cleanup SIGTERM SIGINT
72
 
 
73
  wait $REDPANDA_PID