From 7034a3a41172d70cf98a58fd812c9c8101555c79 Mon Sep 17 00:00:00 2001 From: Gleb Tcivie Date: Wed, 10 Jul 2024 09:18:29 +0300 Subject: [PATCH 1/7] Create main.yml --- .github/workflows/main.yml | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..c4155b2 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,51 @@ +name: Docker Container Health Check + +on: + pull_request: + branches: [ main ] + +jobs: + check-containers: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Start Docker Compose + run: docker-compose up -d + + - name: Wait for containers to start + run: sleep 60 # 1 minute + + - name: Check container statuses + run: | + services=("exporter-1" "grafana-1" "postgres-1" "prometheus-1") + + for service in "${services[@]}" + do + container_id=$(docker-compose ps -q $service) + + if [ -z "$container_id" ]; then + echo "Error: Container for $service not found" + exit 1 + fi + + status=$(docker inspect --format='{{.State.Status}}' $container_id) + restarts=$(docker inspect --format='{{.RestartCount}}' $container_id) + + if [ "$status" != "running" ]; then + echo "Error: Container $service ($container_id) is not running. Current status: $status" + exit 1 + fi + + if [ "$restarts" -gt 0 ]; then + echo "Error: Container $service ($container_id) has restarted $restarts times" + exit 1 + fi + + echo "Container $service is running properly and has not restarted." + done + + - name: Clean up + if: always() + run: docker-compose down From a8be85e20cc138acc5183210e48da0b480bac435 Mon Sep 17 00:00:00 2001 From: Gleb Tcivie Date: Wed, 10 Jul 2024 09:22:51 +0300 Subject: [PATCH 2/7] Update main.yml --- .github/workflows/main.yml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c4155b2..f49f4e7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Docker Container Health Check +name: Meshtastic Metrics Exporter Health Check on: pull_request: @@ -15,11 +15,11 @@ jobs: run: docker-compose up -d - name: Wait for containers to start - run: sleep 60 # 1 minute + run: sleep 60 # 1 Minute - name: Check container statuses run: | - services=("exporter-1" "grafana-1" "postgres-1" "prometheus-1") + services=("prometheus" "grafana" "exporter" "postgres") for service in "${services[@]}" do @@ -46,6 +46,18 @@ jobs: echo "Container $service is running properly and has not restarted." done + - name: Check exposed ports + run: | + expected_ports=("9090" "3000" "5432") + for port in "${expected_ports[@]}" + do + if ! netstat -tuln | grep -q ":$port "; then + echo "Error: Port $port is not exposed" + exit 1 + fi + echo "Port $port is correctly exposed" + done + - name: Clean up if: always() - run: docker-compose down + run: docker-compose down -v From c4b051183a3aefb814af1e39e54c5bb7f996b2dd Mon Sep 17 00:00:00 2001 From: Gleb Tcivie Date: Wed, 10 Jul 2024 09:29:47 +0300 Subject: [PATCH 3/7] Update main.yml --- .github/workflows/main.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f49f4e7..1681232 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,7 @@ jobs: - name: Wait for containers to start run: sleep 60 # 1 Minute - - name: Check container statuses + - name: Check container statuses and logs run: | services=("prometheus" "grafana" "exporter" "postgres") @@ -27,6 +27,7 @@ jobs: if [ -z "$container_id" ]; then echo "Error: Container for $service not found" + docker-compose logs $service exit 1 fi @@ -35,11 +36,15 @@ jobs: if [ "$status" != "running" ]; then echo "Error: Container $service ($container_id) is not running. Current status: $status" + echo "Last logs for $service:" + docker-compose logs --tail=50 $service exit 1 fi if [ "$restarts" -gt 0 ]; then echo "Error: Container $service ($container_id) has restarted $restarts times" + echo "Last logs for $service:" + docker-compose logs --tail=50 $service exit 1 fi From 908acc144098708c43d93d65a1be8a592cc2bc62 Mon Sep 17 00:00:00 2001 From: Gleb Tcivie Date: Wed, 10 Jul 2024 09:34:30 +0300 Subject: [PATCH 4/7] Fix missing constants file in docker pod --- docker/exporter/Dockerfile.exporter | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/exporter/Dockerfile.exporter b/docker/exporter/Dockerfile.exporter index 9664ec9..9eae2b4 100644 --- a/docker/exporter/Dockerfile.exporter +++ b/docker/exporter/Dockerfile.exporter @@ -8,4 +8,5 @@ RUN pip3 install -r requirements.txt COPY ../../exporter exporter COPY ../../main.py . +COPY ../../constants.py . CMD ["python3", "-u", "main.py"] \ No newline at end of file From 8d188dc8b3c813e0e7748d3796e6783b964cabb0 Mon Sep 17 00:00:00 2001 From: Gleb Tcivie Date: Wed, 10 Jul 2024 09:34:30 +0300 Subject: [PATCH 5/7] Fix missing constants file in docker pod --- docker/exporter/Dockerfile.exporter | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/exporter/Dockerfile.exporter b/docker/exporter/Dockerfile.exporter index 9664ec9..9eae2b4 100644 --- a/docker/exporter/Dockerfile.exporter +++ b/docker/exporter/Dockerfile.exporter @@ -8,4 +8,5 @@ RUN pip3 install -r requirements.txt COPY ../../exporter exporter COPY ../../main.py . +COPY ../../constants.py . CMD ["python3", "-u", "main.py"] \ No newline at end of file From ab82298df2bbdf77d913c25d1fd7fc91590398d5 Mon Sep 17 00:00:00 2001 From: Gleb Tcivie Date: Wed, 10 Jul 2024 09:40:16 +0300 Subject: [PATCH 6/7] Added simple MQTT connection details to vericy that the pod is starting --- .env | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.env b/.env index b80354c..440e3d7 100644 --- a/.env +++ b/.env @@ -8,10 +8,10 @@ PROMETHEUS_COLLECTOR_PORT=9464 PROMETHEUS_JOB=example # MQTT connection details -MQTT_HOST= +MQTT_HOST=mqtt.meshtastic.org MQTT_PORT=1883 -MQTT_USERNAME= -MQTT_PASSWORD= +MQTT_USERNAME=meshdev +MQTT_PASSWORD=large4cats MQTT_KEEPALIVE=60 MQTT_TOPIC='msh/israel/#' MQTT_IS_TLS=false From da4a5dcfece642ffe202c4b56fd0b1bf54bd94b9 Mon Sep 17 00:00:00 2001 From: Gleb Tcivie Date: Wed, 10 Jul 2024 09:44:57 +0300 Subject: [PATCH 7/7] Close postgress port --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1681232..250d8c1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -53,7 +53,7 @@ jobs: - name: Check exposed ports run: | - expected_ports=("9090" "3000" "5432") + expected_ports=("9090" "3000") for port in "${expected_ports[@]}" do if ! netstat -tuln | grep -q ":$port "; then