Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions app/opensense.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
'''Module to get entries from OpenSenseMap API and get the average temperature'''
from datetime import datetime, timezone, timedelta
import os
import socket
import requests
import redis

HOSTNAME = socket.gethostname()
IPADDR = socket.gethostbyname(HOSTNAME)

REDIS_HOST = os.getenv('REDIS_HOST', 'localhost')
REDIS_PORT = int(os.environ.get('REDIS_PORT', 6379))
REDIS_DB = int(os.environ.get('REDIS_DB', 0))
Expand Down Expand Up @@ -50,7 +54,7 @@ def get_temperature():

print('Getting data from OpenSenseMap API...')

response = requests.get("https://api.opensensemap.org/boxes", params=params, timeout=240)
response = requests.get("https://api.opensensemap.org/boxes", params=params, timeout=300)
print('Data retrieved successfully!')

res = [d.get('sensors') for d in response.json() if 'sensors' in d]
Expand Down Expand Up @@ -82,4 +86,4 @@ def get_temperature():
except redis.RedisError as e:
print(f"Redis error while caching data: {e}")

return result
return result + f"From: {IPADDR}\n"
51 changes: 41 additions & 10 deletions k8s/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,28 @@ spec:
app: hivebox
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000
seccompProfile:
type: RuntimeDefault
containers:
- name: hivebox
image: ghcr.io/gabrielpalmar/hivebox:0.5.0@sha256:81aa2e46d597ad24c0d25b5f0df9e48d0a0b7503eec060fafdde71be602662a6
image: ghcr.io/gabrielpalmar/hivebox:latest@sha256:4e385cbb108b94a13b9faa884ebc1150119fcf6d4963a75450ed13b344a3c9c5
ports:
- containerPort: 5000
env:
- name: REDIS_HOST
value: "redis-service"
- name: REDIS_PORT
value: "6379"
- name: REDIS_DB
value: "0"
- name: CACHE_TTL
value: "300"
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsGroup: 1000
runAsUser: 1000
capabilities:
drop:
Expand All @@ -45,9 +52,9 @@ spec:
httpGet:
path: /version
port: 5000
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
initialDelaySeconds: 60
periodSeconds: 120
timeoutSeconds: 10
failureThreshold: 3
readinessProbe:
httpGet:
Expand All @@ -60,6 +67,31 @@ spec:
volumeMounts:
- name: tmp-volume
mountPath: /tmp
volumes:
- name: tmp-volume
emptyDir: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
labels:
app: redis
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
securityContext:
fsGroup: 1000
seccompProfile:
type: RuntimeDefault
containers:
- name: valkey
image: valkey/valkey:8-alpine3.22@sha256:0d27f0bca0249f61d060029a6aaf2e16b2c417d68d02a508e1dfb763fa2948b4
ports:
Expand All @@ -69,7 +101,8 @@ spec:
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 999
runAsGroup: 1000
runAsUser: 1000
capabilities:
drop:
- ALL
Expand All @@ -84,7 +117,5 @@ spec:
- name: valkey-data
mountPath: /data
volumes:
- name: tmp-volume
emptyDir: {}
- name: valkey-data
emptyDir: {}
11 changes: 11 additions & 0 deletions k8s/ingress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@ spec:
name: hivebox-service
port:
number: 80
---
apiVersion: v1
kind: Service
metadata:
name: redis-service
spec:
selector:
app: redis
ports:
- port: 6379
targetPort: 6379
62 changes: 30 additions & 32 deletions tests/fixtures/vcr_cassettes/version.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.31.0
method: GET
uri: http://127.0.0.1:5000/version
response:
body:
string: 'Current app version: 0.4.1

'
headers:
Connection:
- close
Content-Length:
- '27'
Content-Type:
- text/html; charset=utf-8
Date:
- Wed, 25 Jun 2025 17:19:51 GMT
Server:
- Werkzeug/3.1.3 Python/3.13.5
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- "*/*"
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.31.0
method: GET
uri: http://127.0.0.1:5000/version
response:
body:
string: "Current app version: 0.5.0"
headers:
Connection:
- close
Content-Length:
- "27"
Content-Type:
- text/html; charset=utf-8
Date:
- Wed, 25 Jun 2025 17:19:51 GMT
Server:
- Werkzeug/3.1.3 Python/3.13.5
status:
code: 200
message: OK
version: 1