Skip to content

Commit

Permalink
✨ Add WebSocket client example
Browse files Browse the repository at this point in the history
  • Loading branch information
mertyildiran committed Feb 11, 2024
1 parent 6484b7d commit 7a419e3
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 0 deletions.
9 changes: 9 additions & 0 deletions additions/websocket-client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.8-slim-buster

WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
RUN apt-get update
RUN apt-get -y install curl procps
COPY example.py .
COPY run.sh .
3 changes: 3 additions & 0 deletions additions/websocket-client/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker build . -t mertyildiran/mizutest-websocket-client:latest && docker push mertyildiran/mizutest-websocket-client:latest
13 changes: 13 additions & 0 deletions additions/websocket-client/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import websocket
import time

while True:
ws = websocket.WebSocket()
ws.connect("ws://echo.websocket.events")
ws.send("Hello, Server")

print(ws.recv())

ws.close()

time.sleep(3)
2 changes: 2 additions & 0 deletions additions/websocket-client/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Faker>=4.18.0
pika>=1.2.0
3 changes: 3 additions & 0 deletions additions/websocket-client/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

python3 example.py
61 changes: 61 additions & 0 deletions deploy/kubernetes/complete-demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1880,3 +1880,64 @@ spec:
release: nginx-ingress
app.kubernetes.io/component: controller
type: "LoadBalancer"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mizutest-websocket-client
labels:
name: mizutest-websocket-client
namespace: sock-shop
spec:
replicas: 1
selector:
matchLabels:
name: mizutest-websocket-client
template:
metadata:
labels:
name: mizutest-websocket-client
spec:
containers:
- name: mizutest-websocket-client
image: mertyildiran/mizutest-websocket-client:latest
env:
- name: PYTHONUNBUFFERED
value: "1"
- name: PYTHONIOENCODING
value: "UTF-8"
imagePullPolicy: Always
command: ["sh", "-c", "./run.sh > /dev/null 2>&1"]
resources:
limits:
cpu: 50m
memory: 200Mi
requests:
cpu: 10m
memory: 10Mi
ports:
- containerPort: 5672
securityContext:
runAsNonRoot: true
runAsUser: 10001
capabilities:
drop:
- all
add:
- NET_BIND_SERVICE
readOnlyRootFilesystem: true
nodeSelector:
beta.kubernetes.io/os: linux
---
apiVersion: v1
kind: Service
metadata:
name: mizutest-websocket-client
annotations:
prometheus.io/scrape: 'true'
labels:
name: mizutest-websocket-client
namespace: sock-shop
spec:
selector:
name: mizutest-websocket-client
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mizutest-websocket-client
labels:
name: mizutest-websocket-client
namespace: sock-shop
spec:
replicas: 1
selector:
matchLabels:
name: mizutest-websocket-client
template:
metadata:
labels:
name: mizutest-websocket-client
spec:
containers:
- name: mizutest-websocket-client
image: mertyildiran/mizutest-websocket-client:latest
env:
- name: PYTHONUNBUFFERED
value: "1"
- name: PYTHONIOENCODING
value: "UTF-8"
imagePullPolicy: Always
command: ["sh", "-c", "./run.sh > /dev/null 2>&1"]
resources:
limits:
cpu: 50m
memory: 200Mi
requests:
cpu: 10m
memory: 10Mi
ports:
- containerPort: 5672
securityContext:
runAsNonRoot: true
runAsUser: 10001
capabilities:
drop:
- all
add:
- NET_BIND_SERVICE
readOnlyRootFilesystem: true
nodeSelector:
beta.kubernetes.io/os: linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: v1
kind: Service
metadata:
name: mizutest-websocket-client
annotations:
prometheus.io/scrape: 'true'
labels:
name: mizutest-websocket-client
namespace: sock-shop
spec:
selector:
name: mizutest-websocket-client

0 comments on commit 7a419e3

Please sign in to comment.