Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a17fb42
Implemented sensantionl-sensor manifest
grrlopes Aug 12, 2023
88b8b8f
Added api and real-fake manifest
grrlopes Aug 12, 2023
66428b5
Added sensation router
grrlopes Aug 14, 2023
567a032
Added proxy headers for uvicorn
grrlopes Aug 14, 2023
61b4e47
Fixed uvicorn CMD in dockerfiles
grrlopes Aug 14, 2023
dc5acac
Changed api cmd port
grrlopes Aug 15, 2023
65e35a4
Included 'root-path' into dockerfile
grrlopes Aug 15, 2023
0a1187d
Changed to be a api debug
grrlopes Aug 15, 2023
2fdafe3
Removed 'get' test debug from api
grrlopes Aug 15, 2023
bba0212
Fixed ingress router to reach api
grrlopes Aug 15, 2023
3fd50dd
Replaced cmd to one without root-path
grrlopes Aug 15, 2023
32f62f1
Implemented frontend app manifest
grrlopes Aug 15, 2023
7a8ded1
Added resources into manifests
grrlopes Aug 16, 2023
b7d9d26
Implemented chart template
grrlopes Aug 16, 2023
816e498
Changed frontend api localhost to env
grrlopes Aug 17, 2023
a696aaa
Removed useless env
grrlopes Aug 17, 2023
43afbda
Quick fix 'iot.local' to test
grrlopes Aug 17, 2023
3d739ec
Changed quick fix 'iot.local' api
grrlopes Aug 17, 2023
b2c6ca6
Changed request api resquest addr
grrlopes Aug 17, 2023
4e3118c
Quick changed origin to test
grrlopes Aug 17, 2023
5d03131
Added app configmap
grrlopes Aug 18, 2023
082fd93
Merge branch 'develop' into k8s-manifest
grrlopes Aug 18, 2023
a22aac8
Fixed api main to fit into k8s setup
grrlopes Aug 18, 2023
b7d15b2
fixed const url addr api main
grrlopes Aug 18, 2023
f7a8258
Overwrite cond at api main
grrlopes Aug 18, 2023
1aa13c3
Quick test 'removed sense'
grrlopes Aug 18, 2023
7ee1135
Changed 'app index api fetch' url
grrlopes Aug 18, 2023
ae3941f
Uncommented sensation api main
grrlopes Aug 18, 2023
0a19773
Changed app index url fetch
grrlopes Aug 18, 2023
01e5965
Merge branch 'develop' into k8s-manifest
grrlopes Aug 18, 2023
f98627e
Added app url env into values
grrlopes Aug 18, 2023
1ec1b68
Fixed app manifest key env
grrlopes Aug 18, 2023
2e99ed2
Added hardcoded app and api
grrlopes Aug 18, 2023
a01c38d
Added proxy-header to api
grrlopes Aug 18, 2023
c3ae7d9
Changed real-fake Dockerfile to proxyheader
grrlopes Aug 18, 2023
722a962
Removed root path from real fake DockerFile
grrlopes Aug 18, 2023
ef70ec1
Removed root path from api dockerfile
grrlopes Aug 18, 2023
b02a77f
Changed const API URL to iot.local
grrlopes Aug 18, 2023
36b47a0
Fixed API_URL 'app' iotal.local
grrlopes Aug 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build and push images
on:
push:
branches:
- develop
- k8s-manifest

jobs:
docker-build:
Expand Down
4 changes: 2 additions & 2 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN pip install --no-cache-dir --upgrade -r /requirements.txt
COPY ./api/main.py main.py

EXPOSE 8080
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
# CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]

# If running behind a proxy like Nginx or Traefik add --proxy-headers
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80", "--proxy-headers"]
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080", "--proxy-headers"]
24 changes: 14 additions & 10 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@

# Set base URLs based on the environment
if env == "prod":
REAL_FAKE_SENSORS_BASE_URL = "http://real_fake_sensors:8081"
SENSATIONAL_SENSORS_BASE_URL = "http://sensational_sensors:8082"
REAL_FAKE_SENSORS_BASE_URL = "http://real-fake-service:8081"
SENSATIONAL_SENSORS_BASE_URL = "http://sensational-sensor-service:8082"
else:
REAL_FAKE_SENSORS_BASE_URL = "http://localhost:8081"
SENSATIONAL_SENSORS_BASE_URL = "http://localhost:8082"

REAL_FAKE_SENSORS_BASE_URL = "http://real-fake-service:8081"
SENSATIONAL_SENSORS_BASE_URL = "http://sensational-sensor-service:8082"

app = FastAPI()

# whitelist
Expand All @@ -27,9 +30,11 @@
"http://0.0.0.0:8082",
]

origin = ["*"]

app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_origins=origin,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
Expand All @@ -38,7 +43,6 @@

class SensorType(Enum):
LIQUID_BIN_LEVEL = "liquid bin level"
SOLID_BIN_LEVEL = "solid bin level"


class BasicSensor(BaseModel):
Expand Down Expand Up @@ -105,7 +109,7 @@ class SensationalSensor(BaseModel):
def sensational_sensor_to_simple_sensor(sensor: SensationalSensor) -> BasicSensor:
return BasicSensor(
id=sensor["id"],
sensor_type=SensorType.SOLID_BIN_LEVEL,
sensor_type=SensorType.LIQUID_BIN_LEVEL,
fill_level=sensor["fill_level"] if sensor["fill_level"] else None,
sim=sensor["sim"],
lat=sensor["lat"],
Expand All @@ -131,12 +135,12 @@ def get_sensors():
real_fake_sensors = requests.get(REAL_FAKE_SENSORS_BASE_URL + "/sensors").json()
rfs_as_simple_sensor_list = rfs_list_to_bs_list(real_fake_sensors["sensors"])

sensational_sensors = requests.get(SENSATIONAL_SENSORS_BASE_URL + "/sensors").json()
ss_as_simple_sensor_list = sensational_sensor_list_to_simple_sensor_list(
sensational_sensors["sensors"]
)
# sensational_sensors = requests.get(SENSATIONAL_SENSORS_BASE_URL + "/sensors").json()
# ss_as_simple_sensor_list = sensational_sensor_list_to_simple_sensor_list(
# sensational_sensors["sensors"]
# )

all_sensors_list = rfs_as_simple_sensor_list + ss_as_simple_sensor_list
all_sensors_list = rfs_as_simple_sensor_list #+ ss_as_simple_sensor_list
return {"total": len(all_sensors_list), "sensors": all_sensors_list}


Expand Down
2 changes: 1 addition & 1 deletion app/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface Sensor {
address_line2: string;
}

const API_URL = process.env.NEXT_PUBLIC_API_HOST || "http://localhost:8080";
const API_URL = process.env.NEXT_PUBLIC_API_HOST || "http://real.iot.local";

const Home: NextPage = () => {
const Map = useMemo(
Expand Down
42 changes: 42 additions & 0 deletions deploy/manifest/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-app
labels:
app: iotapp
spec:
replicas: 1
selector:
matchLabels:
app: api-app
template:
metadata:
labels:
app: api-app
spec:
imagePullSecrets:
- name: ghcr-secret
containers:
- name: api-app
image: ghcr.io/button-inc/iot-system-prototype/api:latest
ports:
- containerPort: 8080
resources:
requests:
memory: "16Mi"
cpu: "40m"
limits:
memory: "128Mi"
cpu: "100m"
---
apiVersion: v1
kind: Service
metadata:
name: api-app-service
spec:
selector:
app: api-app
ports:
- protocol: TCP
port: 8080
targetPort: 8080
42 changes: 42 additions & 0 deletions deploy/manifest/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: custom-app
labels:
app: iotapp
spec:
replicas: 1
selector:
matchLabels:
app: custom-app
template:
metadata:
labels:
app: custom-app
spec:
imagePullSecrets:
- name: ghcr-secret
containers:
- name: custom-app
image: ghcr.io/button-inc/iot-system-prototype/app:latest
ports:
- containerPort: 3000
resources:
requests:
memory: "16Mi"
cpu: "40m"
limits:
memory: "128Mi"
cpu: "100m"
---
apiVersion: v1
kind: Service
metadata:
name: custom-app-service
spec:
selector:
app: custom-app
ports:
- protocol: TCP
port: 3000
targetPort: 3000
23 changes: 23 additions & 0 deletions deploy/manifest/iot-system-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: iot-ingress
spec:
rules:
- host: iot.local
http:
paths:
- path: /sensors
pathType: Prefix
backend:
service:
name: api-app-service
port:
number: 8080
- path: /
pathType: Prefix
backend:
service:
name: custom-app-service
port:
number: 3000
23 changes: 23 additions & 0 deletions deploy/manifest/iot-system/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
13 changes: 13 additions & 0 deletions deploy/manifest/iot-system/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v2
name: iot-system
description: A Helm chart for leveraging IoT sensor data infrastructure in the cloud.
keywords:
- iot
- sensors
- helm

type: application

version: 1.0.0

appVersion: "1.0.0"
49 changes: 49 additions & 0 deletions deploy/manifest/iot-system/templates/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.deployApi.name }}
namespace: {{ .Values.deployApi.namespace }}
labels:
app: iotapp
spec:
replicas: {{ .Values.deployApi.replicas }}
selector:
matchLabels:
app: {{ .Values.deployApi.name }}
template:
metadata:
labels:
app: {{ .Values.deployApi.name }}
spec:
imagePullSecrets:
- name: ghcr-secret
containers:
- name: {{ .Values.deployApi.name }}
image: "{{ .Values.deployApi.image.name }}:{{ .Values.deployApi.image.tag }}"
ports:
- containerPort: {{ .Values.deployApi.port }}
env:
- name: ENV
valueFrom:
configMapKeyRef:
name: iot-configmap
key: environment
resources:
requests:
memory: {{ .Values.deployApi.resources.requests.memory }}
cpu: {{ .Values.deployApi.resources.requests.cpu }}
limits:
memory: {{ .Values.deployApi.resources.limits.memory }}
cpu: {{ .Values.deployApi.resources.limits.cpu }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.serviceApi.name }}
spec:
selector:
app: {{ .Values.deployApi.name }}
ports:
- protocol: TCP
port: {{ .Values.serviceApi.port }}
targetPort: {{ .Values.serviceApi.targetPort }}
59 changes: 59 additions & 0 deletions deploy/manifest/iot-system/templates/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.deployApp.name }}
namespace: {{ .Values.deployApp.namespace }}
labels:
app: iotapp
spec:
replicas: {{ .Values.deployApp.replicas }}
selector:
matchLabels:
app: {{ .Values.deployApp.name }}
template:
metadata:
labels:
app: {{ .Values.deployApp.name }}
spec:
imagePullSecrets:
- name: ghcr-secret
containers:
- name: {{ .Values.deployApp.name }}
image: "{{ .Values.deployApp.image.name }}:{{ .Values.deployApp.image.tag }}"
ports:
- containerPort: {{ .Values.deployApp.port }}
env:
- name: API
valueFrom:
configMapKeyRef:
name: iot-configmap
key: api
- name: APP_URL
valueFrom:
configMapKeyRef:
name: iot-configmap
key: next_public_api_host
- name: API_PORT
valueFrom:
configMapKeyRef:
name: iot-configmap
key: api_port
resources:
requests:
memory: {{ .Values.deployApp.resources.requests.memory }}
cpu: {{ .Values.deployApp.resources.requests.cpu }}
limits:
memory: {{ .Values.deployApp.resources.limits.memory }}
cpu: {{ .Values.deployApp.resources.limits.cpu }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.serviceApp.name }}
spec:
selector:
app: {{ .Values.deployApp.name }}
ports:
- protocol: TCP
port: {{ .Values.serviceApp.port }}
targetPort: {{ .Values.serviceApp.targetPort }}
9 changes: 9 additions & 0 deletions deploy/manifest/iot-system/templates/iot-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: iot-configmap
data:
api: iot.local
api_port: "8080"
environment: prod
next_public_api_host: http://real.iot.local/sensors
23 changes: 23 additions & 0 deletions deploy/manifest/iot-system/templates/iot-system-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: iot-ingress
spec:
rules:
- host: iot.local
http:
paths:
- path: /sensors
pathType: Prefix
backend:
service:
name: api-app-service
port:
number: 8080
- path: /
pathType: Prefix
backend:
service:
name: custom-app-service
port:
number: 3000
Loading