wjm55 commited on
Commit
72f5836
·
1 Parent(s): cf8d4dd

Refactor Dockerfile to integrate supervisord for managing Weaviate and Nginx services, replace start.sh with supervisord configuration, and enhance Nginx settings for improved proxy handling. Remove obsolete start.sh script.

Browse files
Files changed (5) hide show
  1. Dockerfile +56 -35
  2. README.md +25 -0
  3. grpc_proxy.sh +3 -0
  4. nginx.conf +26 -0
  5. start.sh +0 -10
Dockerfile CHANGED
@@ -1,51 +1,72 @@
1
  FROM cr.weaviate.io/semitechnologies/weaviate:1.30.0
2
 
 
 
 
 
 
 
 
3
  ENV QUERY_DEFAULTS_LIMIT=25 \
4
  AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED=true \
5
  PERSISTENCE_DATA_PATH=/var/lib/weaviate \
6
  ENABLE_API_BASED_MODULES=true \
7
  CLUSTER_HOSTNAME=node1 \
8
- GRPC_PORT=50051 \
9
- HTTP_PORT=8080
10
-
11
- # Install Nginx and required tools
12
- RUN apt-get update && \
13
- apt-get install -y nginx gettext-base && \
14
- apt-get clean && \
15
- rm -rf /var/lib/apt/lists/*
16
-
17
- # Create Nginx configuration
18
- RUN echo 'server {\n\
19
- listen 7860 http2;\n\
20
- server_name localhost;\n\
21
- \n\
22
- # HTTP API traffic\n\
23
- location / {\n\
24
- proxy_pass http://localhost:8080;\n\
25
- proxy_set_header Host $host;\n\
26
- proxy_set_header X-Real-IP $remote_addr;\n\
27
- }\n\
28
- \n\
29
- # gRPC traffic\n\
30
- location /weaviate.Weaviate/ {\n\
31
- grpc_pass grpc://localhost:50051;\n\
32
- }\n\
33
- }' > /etc/nginx/conf.d/weaviate.conf
34
-
35
- # Remove default Nginx site
36
- RUN rm /etc/nginx/sites-enabled/default
37
-
38
- EXPOSE 7860
39
 
40
  # Create data directory with proper permissions
41
  RUN mkdir -p /var/lib/weaviate && \
42
  chmod 777 /var/lib/weaviate
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  # Create volume for persistent data
45
  VOLUME ["/var/lib/weaviate"]
46
 
47
- # Start script to run both services
48
- COPY start.sh /start.sh
49
- RUN chmod +x /start.sh
50
 
51
- CMD ["/start.sh"]
 
 
1
  FROM cr.weaviate.io/semitechnologies/weaviate:1.30.0
2
 
3
+ # Install Nginx and other utilities
4
+ RUN apt-get update && \
5
+ apt-get install -y nginx supervisor socat && \
6
+ apt-get clean && \
7
+ rm -rf /var/lib/apt/lists/*
8
+
9
+ # Environment variables
10
  ENV QUERY_DEFAULTS_LIMIT=25 \
11
  AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED=true \
12
  PERSISTENCE_DATA_PATH=/var/lib/weaviate \
13
  ENABLE_API_BASED_MODULES=true \
14
  CLUSTER_HOSTNAME=node1 \
15
+ GRPC_PORT=50051
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  # Create data directory with proper permissions
18
  RUN mkdir -p /var/lib/weaviate && \
19
  chmod 777 /var/lib/weaviate
20
 
21
+ # Copy the gRPC proxy script
22
+ COPY grpc_proxy.sh /usr/local/bin/
23
+ RUN chmod +x /usr/local/bin/grpc_proxy.sh
24
+
25
+ # Nginx configuration
26
+ RUN echo 'events { worker_connections 1024; }' > /etc/nginx/nginx.conf && \
27
+ echo 'http { \
28
+ server { \
29
+ listen 7860; \
30
+ location / { \
31
+ proxy_pass http://localhost:8080; \
32
+ proxy_set_header Host $host; \
33
+ proxy_set_header X-Real-IP $remote_addr; \
34
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; \
35
+ proxy_set_header X-Forwarded-Proto $scheme; \
36
+ } \
37
+ } \
38
+ }' >> /etc/nginx/nginx.conf
39
+
40
+ # Configure supervisord to run all services
41
+ RUN echo '[supervisord]\n\
42
+ nodaemon=true\n\
43
+ \n\
44
+ [program:weaviate]\n\
45
+ command=/bin/weaviate --host 0.0.0.0 --port 8080 --scheme http\n\
46
+ stdout_logfile=/dev/stdout\n\
47
+ stdout_logfile_maxbytes=0\n\
48
+ stderr_logfile=/dev/stderr\n\
49
+ stderr_logfile_maxbytes=0\n\
50
+ \n\
51
+ [program:nginx]\n\
52
+ command=/usr/sbin/nginx -g "daemon off;"\n\
53
+ stdout_logfile=/dev/stdout\n\
54
+ stdout_logfile_maxbytes=0\n\
55
+ stderr_logfile=/dev/stderr\n\
56
+ stderr_logfile_maxbytes=0\n\
57
+ \n\
58
+ [program:grpc_proxy]\n\
59
+ command=/usr/local/bin/grpc_proxy.sh\n\
60
+ stdout_logfile=/dev/stdout\n\
61
+ stdout_logfile_maxbytes=0\n\
62
+ stderr_logfile=/dev/stderr\n\
63
+ stderr_logfile_maxbytes=0' > /etc/supervisor/conf.d/supervisord.conf
64
+
65
  # Create volume for persistent data
66
  VOLUME ["/var/lib/weaviate"]
67
 
68
+ # Expose the main port
69
+ EXPOSE 7860
 
70
 
71
+ # Run all services using supervisord
72
+ CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
README.md CHANGED
@@ -9,3 +9,28 @@ app_port: 7860
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
12
+
13
+ # Weaviate with Nginx Proxy
14
+
15
+ This Dockerfile sets up a container with both Weaviate and Nginx. Weaviate runs internally on ports 8080 (HTTP) and 50051 (gRPC), while Nginx forwards external requests from port 7860 to these internal ports.
16
+
17
+ ## Build the Image
18
+
19
+ ```bash
20
+ docker build -t weaviate-nginx .
21
+ ```
22
+
23
+ ## Run the Container
24
+
25
+ ```bash
26
+ docker run -d -p 7860:7860 -v weaviate_data:/var/lib/weaviate --name weaviate-container weaviate-nginx
27
+ ```
28
+
29
+ ## Accessing Weaviate
30
+
31
+ - Access the Weaviate HTTP API at: http://localhost:7860
32
+ - The gRPC port is also accessible at port 7860
33
+
34
+ ## Persistent Data
35
+
36
+ The container uses a Docker volume named `weaviate_data` to persist the Weaviate database.
grpc_proxy.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ # Simple TCP forwarding for gRPC from port 7860 to 50051
3
+ socat TCP-LISTEN:7860,fork,reuseaddr TCP:localhost:50051
nginx.conf ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ events {
2
+ worker_connections 1024;
3
+ }
4
+
5
+ http {
6
+ server {
7
+ listen 7860;
8
+
9
+ # HTTP API proxy
10
+ location / {
11
+ proxy_pass http://weaviate:8080;
12
+ proxy_set_header Host $host;
13
+ proxy_set_header X-Real-IP $remote_addr;
14
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
15
+ proxy_set_header X-Forwarded-Proto $scheme;
16
+ }
17
+ }
18
+ }
19
+
20
+ stream {
21
+ # gRPC proxy
22
+ server {
23
+ listen 7861;
24
+ proxy_pass weaviate:50051;
25
+ }
26
+ }
start.sh DELETED
@@ -1,10 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Start Weaviate in the background
4
- /bin/weaviate --host 0.0.0.0 --port $HTTP_PORT --scheme http &
5
-
6
- # Give Weaviate a moment to start
7
- sleep 5
8
-
9
- # Start Nginx in the foreground
10
- nginx -g 'daemon off;'