lab1: add CI/CD testing
All checks were successful
Test Agent / test-agent-run (push) Successful in 5m24s

This commit is contained in:
ІО-23 Шмуляр Олег 2026-02-23 23:53:42 +02:00
parent b2c7427af0
commit b330180909
6 changed files with 75 additions and 3 deletions

View File

@ -0,0 +1,25 @@
name: Test Agent
on: [push, workflow_dispatch]
jobs:
test-agent-run:
runs-on: arch-x86_64
steps:
- name: Fetch the repository
run: git clone --branch ${{ gitea.ref_name }} --depth 1 ${{ gitea.server_url }}/${{ gitea.repository }}
- name: Build containers
run: docker-compose -f docker-compose-test.yaml build
working-directory: sem8-iot-test/agent/docker
- name: Start MQTT broker
run: docker-compose -f docker-compose-test.yaml up -d mqtt
working-directory: sem8-iot-test/agent/docker
- name: Start agent
run: docker-compose -f docker-compose-test.yaml run fake_agent
working-directory: sem8-iot-test/agent/docker
- name: Clean up
if: always()
run: docker-compose -f docker-compose-test.yaml down
working-directory: sem8-iot-test/agent/docker

View File

@ -0,0 +1,34 @@
version: "3.3"
#name: "road_vision"
services:
mqtt:
image: eclipse-mosquitto
container_name: mqtt
volumes:
- ./mosquitto:/mosquitto
- ./mosquitto/data:/mosquitto/data
- ./mosquitto/log:/mosquitto/log
ports:
- 1883:1883
- 9001:9001
networks:
mqtt_network:
fake_agent:
container_name: agent
build: ../
depends_on:
- mqtt
environment:
MQTT_BROKER_HOST: "mqtt"
MQTT_BROKER_PORT: 1883
MQTT_TOPIC: "agent_data_topic"
DELAY: 0.1
MAX_SENDS: 30
networks:
mqtt_network:
networks:
mqtt_network:

View File

@ -1,4 +1,5 @@
name: "road_vision" version: "3.3"
#name: "road_vision"
services: services:
mqtt: mqtt:
image: eclipse-mosquitto image: eclipse-mosquitto

View File

@ -16,3 +16,6 @@ MQTT_TOPIC = os.environ.get("MQTT_TOPIC") or "agent"
# Delay for sending data to mqtt in seconds # Delay for sending data to mqtt in seconds
DELAY = try_parse(float, os.environ.get("DELAY")) or 1 DELAY = try_parse(float, os.environ.get("DELAY")) or 1
# Testing switches for CI/CD
MAX_SENDS = try_parse(int, os.environ.get("MAX_SENDS"))

View File

@ -24,9 +24,13 @@ def connect_mqtt(broker, port):
return client return client
def publish(client, topic, datasource, delay): def publish(client, topic, datasource, delay, max_sends = None):
datasource.startReading() datasource.startReading()
i = 0
while True: while True:
i += 1
time.sleep(delay) time.sleep(delay)
data = datasource.read() data = datasource.read()
msg = AggregatedDataSchema().dumps(data) msg = AggregatedDataSchema().dumps(data)
@ -39,6 +43,10 @@ def publish(client, topic, datasource, delay):
else: else:
print(f"Failed to send message to topic {topic}") print(f"Failed to send message to topic {topic}")
if max_sends and i >= max_sends:
# display test success
exit(0)
def run(): def run():
# Prepare mqtt client # Prepare mqtt client
@ -46,7 +54,7 @@ def run():
# Prepare datasource # Prepare datasource
datasource = FileDatasource("data/data.csv", "data/gps_data.csv") datasource = FileDatasource("data/data.csv", "data/gps_data.csv")
# Infinity publish data # Infinity publish data
publish(client, config.MQTT_TOPIC, datasource, config.DELAY) publish(client, config.MQTT_TOPIC, datasource, config.DELAY, getattr(config, "MAX_SENDS", None))
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -13,6 +13,7 @@ services:
- 19001:9001 - 19001:9001
networks: networks:
mqtt_network: mqtt_network:
user: 1000:1000
edge: edge: