Skip to content

Commit ff99fac

Browse files
committed
writing and streaming containers
1 parent 8deb94a commit ff99fac

File tree

6 files changed

+88
-14
lines changed

6 files changed

+88
-14
lines changed

Dockerfile.streaming-client

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM ghcr.io/prefix-dev/pixi:latest
2+
3+
WORKDIR /app
4+
5+
# Copy pixi files
6+
COPY pixi.toml pixi.lock ./
7+
8+
# Install dependencies using pixi
9+
RUN pixi install
10+
11+
# Copy the streaming client
12+
COPY streaming_client.py .
13+
14+
# Set default environment variable
15+
ENV REDIS_WS_API_URL=localhost:8000
16+
17+
# Run the streaming client
18+
CMD ["pixi", "run", "python", "streaming_client.py"]

Dockerfile.writing-client

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM ghcr.io/prefix-dev/pixi:latest
2+
3+
WORKDIR /app
4+
5+
# Copy pixi files
6+
COPY pixi.toml pixi.lock ./
7+
8+
# Install dependencies using pixi
9+
RUN pixi install
10+
11+
# Copy the writing client
12+
COPY writing_client.py .
13+
14+
# Set default environment variables
15+
ENV REDIS_WS_API_URL=localhost:8000
16+
ENV WRITE_DELAY=0.5
17+
ENV NUM_WRITES=10
18+
19+
# Run the writing client
20+
CMD ["pixi", "run", "python", "writing_client.py"]

kube/README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
1-
# Redis Kubernetes Deployment
1+
# Kubernetes Deployments
22

3-
This directory contains Kubernetes manifests for deploying Redis.
3+
This directory contains Kubernetes manifests for deploying Redis and the test-redis-ws application.
44

55
## Files
66
- `redis-deployment.yaml` - Redis deployment with 1 replica
7-
- `redis-service.yaml` - ClusterIP service exposing port 6379
7+
- `redis-service.yaml` - ClusterIP service exposing Redis on port 6379
8+
- `test-redis-ws-deployment.yaml` - test-redis-ws deployment with 3 replicas
9+
- `test-redis-ws-service.yaml` - ClusterIP service exposing test-redis-ws on port 8000
810

911
## Deploy
1012
```bash
13+
# Deploy everything
1114
kubectl apply -f .
15+
16+
# Or deploy individually
17+
kubectl apply -f redis-deployment.yaml
18+
kubectl apply -f redis-service.yaml
19+
kubectl apply -f test-redis-ws-deployment.yaml
20+
kubectl apply -f test-redis-ws-service.yaml
1221
```
1322

14-
## Test
23+
## Container Image
24+
The test-redis-ws image is automatically built and pushed to GitHub Container Registry on push to main branch.
25+
- Image: `ghcr.io/nsls2/test-redis-ws:latest`
26+
- Build workflow: `.github/workflows/build-push.yml`
27+
28+
## Test Redis
1529
```bash
1630
# Connect to a netshoot container
1731
kubectl run netshoot --image=nicolaka/netshoot --rm -it --restart=Never -- /bin/bash
1832

1933
# Test Redis connection from inside the container
2034
echo -e "PING\r\n" | nc redis 6379
35+
```
36+
37+
## Test test-redis-ws
38+
```bash
39+
# Connect to a netshoot container
40+
kubectl run netshoot --image=nicolaka/netshoot --rm -it --restart=Never -- /bin/bash
41+
42+
# Test the service from inside the container
43+
curl http://test-redis-ws:8000/
2144
```

kube/test-redis-ws-deployment.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ spec:
1616
spec:
1717
containers:
1818
- name: test-redis-ws
19-
image: ghcr.io/nsls2/test-redis-ws:latest
19+
image: ghcr.io/nsls2/test-redis-ws:kube
2020
imagePullPolicy: Always
2121
ports:
2222
- containerPort: 8000
@@ -28,8 +28,8 @@ spec:
2828
value: "6379"
2929
resources:
3030
requests:
31-
memory: "256Mi"
32-
cpu: "250m"
31+
memory: "64Mi"
32+
cpu: "50m"
3333
limits:
34-
memory: "512Mi"
35-
cpu: "500m"
34+
memory: "256Mi"
35+
cpu: "200m"

streaming_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55
import json
66
import msgpack
7+
import os
78
# from httpx_ws import aconnect_ws
89
# from httpx_ws.transport import ASGIWebSocketTransport
910

@@ -25,15 +26,18 @@
2526
# transport=ASGIWebSocketTransport(app=app), base_url="http://localhost"
2627
# )
2728

28-
client = AsyncClient(base_url="http://localhost:8000")
29+
# Get base URL from environment variable, default to localhost
30+
REDIS_WS_API_URL = os.getenv("REDIS_WS_API_URL", "localhost:8000")
31+
client = AsyncClient(base_url=f"http://{REDIS_WS_API_URL}")
2932

3033

3134
async def get_live():
3235
result = await client.get("/stream/live")
3336
return result.json()
3437

3538
async def stream_node(node_id: str, envelope_format="json"):
36-
websocket_url = f"ws://localhost:8000/stream/single/{node_id}?envelope_format={envelope_format}&seq_num=1"
39+
# Create WebSocket URL from base URL
40+
websocket_url = f"ws://{REDIS_WS_API_URL}/stream/single/{node_id}?envelope_format={envelope_format}&seq_num=1"
3741

3842
async with websockets.connect(websocket_url) as websocket:
3943
print(f"Connected to {websocket_url}")

writing_client.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,26 @@
22
import httpx
33
import time
44
import sys
5+
import os
56

6-
client = httpx.Client(base_url="http://localhost:8000")
7+
# Get base URL from environment variable, default to localhost
8+
REDIS_WS_API_URL = os.getenv("REDIS_WS_API_URL", "localhost:8000")
9+
client = httpx.Client(base_url=f"http://{REDIS_WS_API_URL}")
10+
11+
# Get write delay from environment variable, default to 0.5 seconds
12+
WRITE_DELAY = float(os.getenv("WRITE_DELAY", "0.5"))
13+
14+
# Get number of writes from environment variable, default to 10
15+
NUM_WRITES = int(os.getenv("NUM_WRITES", "10"))
716

817

918
def main():
1019
for _ in range(3):
1120
#content = client.post("/upload").raise_for_status().json()
1221
#node_id = content["node_id"]
1322
node_id = 481980
14-
for i in range(10):
15-
time.sleep(0.5)
23+
for i in range(NUM_WRITES):
24+
time.sleep(WRITE_DELAY)
1625
binary_data = (np.ones(5) * i).tobytes()
1726
client.post(
1827
f"/upload/{node_id}",

0 commit comments

Comments
 (0)