Adding Example-Rapp which can be used for notification_url testing 33/14133/1
authorashishj1729 <jain.ashish@samsung.com>
Mon, 3 Feb 2025 12:15:35 +0000 (17:45 +0530)
committerashishj1729 <jain.ashish@samsung.com>
Mon, 3 Feb 2025 12:18:12 +0000 (17:48 +0530)
Change-Id: Ic26d8850e09746a399074ff25f5330df35cf4de8
Signed-off-by: ashishj1729 <jain.ashish@samsung.com>
demos/example-rapp/README.md [new file with mode: 0644]
demos/example-rapp/krm/deployment.yaml [new file with mode: 0644]
demos/example-rapp/krm/service.yaml [new file with mode: 0644]
demos/example-rapp/rapp-image-build.sh [new file with mode: 0644]
demos/example-rapp/rapp/Dockerfile [new file with mode: 0644]
demos/example-rapp/rapp/app/main.py [new file with mode: 0644]
demos/example-rapp/rapp/app/requirements.txt [new file with mode: 0644]

diff --git a/demos/example-rapp/README.md b/demos/example-rapp/README.md
new file mode 100644 (file)
index 0000000..1ea8680
--- /dev/null
@@ -0,0 +1,50 @@
+<!--
+# ==================================================================================
+#
+#       Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+# ==================================================================================
+-->
+# Dummy-Rapp to test notification_url callback
+
+1. Building Image:
+```bash
+./rapp-image-build.sh
+```
+
+2. Deploy rApp:
+```bash
+kubectl apply -f krm/.
+```
+
+3. Test the pod using curl-pod:
+```bash
+# Deploy a curl-pod
+kubectl run curl-pod --image=curlimages/curl:latest --command sleep 3600
+# Query Inference-Service
+kubectl exec -it curl-pod -- \
+curl \
+--location rapp-service.default.svc.cluster.local/callback \
+--header "Content-Type: application/json" \
+--data '{
+        "key1": 3,
+        "key2": []
+        }'
+
+# Response must be
+{"data":{"key1":3,"key2":[]},"message":"Data received"}
+```
+
+Note: Use the callback-url/notification_url as `http://rapp-service.default.svc.cluster.local/callback` in order to test notification_rapp.
\ No newline at end of file
diff --git a/demos/example-rapp/krm/deployment.yaml b/demos/example-rapp/krm/deployment.yaml
new file mode 100644 (file)
index 0000000..228131d
--- /dev/null
@@ -0,0 +1,45 @@
+# ==================================================================================
+#
+#       Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+# ==================================================================================
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: rapp
+  namespace: default
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: rapp
+  template:
+    metadata:
+      labels:
+        app: rapp
+    spec:
+      containers:
+      - name: rapp-container
+        image: rapp:dev
+        imagePullPolicy: IfNotPresent
+        command: ["python3", "-u","main.py"]
+        # command: ["tail", "-f","/dev/null"]
+        resources:
+          requests:
+            memory: "128Mi"
+            cpu: "250m"
+          limits:
+            memory: "256Mi"
+            cpu: "500m"
\ No newline at end of file
diff --git a/demos/example-rapp/krm/service.yaml b/demos/example-rapp/krm/service.yaml
new file mode 100644 (file)
index 0000000..63ff641
--- /dev/null
@@ -0,0 +1,28 @@
+# ==================================================================================
+#
+#       Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+# ==================================================================================
+apiVersion: v1
+kind: Service
+metadata:
+  name: rapp-service
+spec:
+  selector:
+    app: rapp
+  ports:
+    - protocol: TCP
+      port: 80
+      targetPort: 8005
\ No newline at end of file
diff --git a/demos/example-rapp/rapp-image-build.sh b/demos/example-rapp/rapp-image-build.sh
new file mode 100644 (file)
index 0000000..0346160
--- /dev/null
@@ -0,0 +1,26 @@
+# ==================================================================================
+#
+#       Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+# ==================================================================================
+
+# sudo nerdctl --namespace k8s.io rmi -f rapp:dev
+echo "Building New Image & Loading"
+sudo buildctl --addr=nerdctl-container://buildkitd build \
+       --frontend dockerfile.v0 \
+       --opt filename=Dockerfile \
+       --local dockerfile=rapp \
+       --local context=rapp \
+       --output type=oci,name=rapp:dev | sudo nerdctl load --namespace k8s.io
\ No newline at end of file
diff --git a/demos/example-rapp/rapp/Dockerfile b/demos/example-rapp/rapp/Dockerfile
new file mode 100644 (file)
index 0000000..43c03ff
--- /dev/null
@@ -0,0 +1,33 @@
+# ==================================================================================
+#
+#       Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+# ==================================================================================
+FROM python:3.10-slim
+# Set environment variables to avoid user prompts during package installation
+ENV DEBIAN_FRONTEND=noninteractive
+# Install necessary packages and clean up
+RUN apt-get update && apt-get install -y bash vim && apt-get clean && rm -rf /var/lib/apt/lists/*
+RUN touch ~/.vimrc
+
+RUN apt update && apt install -y curl
+
+COPY app app
+# Location in the container
+WORKDIR /app
+RUN pip3 install  -r requirements.txt
+
+EXPOSE 8005
+# CMD ["tail", "-f", "/dev/null"]
\ No newline at end of file
diff --git a/demos/example-rapp/rapp/app/main.py b/demos/example-rapp/rapp/app/main.py
new file mode 100644 (file)
index 0000000..28f02ce
--- /dev/null
@@ -0,0 +1,31 @@
+# ==================================================================================
+#
+#       Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+# ==================================================================================
+from flask import Flask, request, jsonify
+
+
+app = Flask(__name__)
+
+@app.route('/callback', methods=['POST'])
+def test_endpoint():
+    data = request.json
+    print("Recieved Data --> ", data)
+    return jsonify({"message": "Data received", "data": data}), 200
+
+
+if __name__ == '__main__':
+    app.run(host='0.0.0.0', port=8005)
\ No newline at end of file
diff --git a/demos/example-rapp/rapp/app/requirements.txt b/demos/example-rapp/rapp/app/requirements.txt
new file mode 100644 (file)
index 0000000..186091f
--- /dev/null
@@ -0,0 +1,18 @@
+# ==================================================================================
+#
+#       Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#          http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+# ==================================================================================
+flask
\ No newline at end of file