From fcfb6d3f4e94544100df6b842003c50ffb153565 Mon Sep 17 00:00:00 2001 From: sstent Date: Mon, 15 Dec 2025 06:45:50 -0800 Subject: [PATCH] sync --- .github/workflows/nomad-deploy.yml | 22 ++++++++++++++++++ fitbit-garmin-sync.nomad | 4 ++++ fitbitsync.py | 36 ++++++++---------------------- 3 files changed, 35 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/nomad-deploy.yml diff --git a/.github/workflows/nomad-deploy.yml b/.github/workflows/nomad-deploy.yml new file mode 100644 index 0000000..7e587be --- /dev/null +++ b/.github/workflows/nomad-deploy.yml @@ -0,0 +1,22 @@ +name: Deploy to Nomad + +on: + workflow_run: + workflows: ["build-container"] # Name of your build workflow + types: + - completed + +jobs: + deploy: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Deploy with Nomad + uses: qazz92/nomad-deploy@v1 + with: + address: http://nomad.service.dc1.consul:4646 + job: fitbit-garmin-sync.nomad diff --git a/fitbit-garmin-sync.nomad b/fitbit-garmin-sync.nomad index cfcbbd8..059961c 100644 --- a/fitbit-garmin-sync.nomad +++ b/fitbit-garmin-sync.nomad @@ -13,7 +13,11 @@ job "fitbit-garmin-sync" { volumes = [ "/mnt/Public/configs/fitbit-garmin-sync:/app/data" ] + memory_hard_limit = 2048 } + env { + CONFIG_SOURCE = "consul" + } # Sensible resource allocation for a lightweight Python script. resources { diff --git a/fitbitsync.py b/fitbitsync.py index 84fb4da..cd5ac92 100644 --- a/fitbitsync.py +++ b/fitbitsync.py @@ -1,6 +1,7 @@ # Fitbit to Garmin Weight Sync Application # Syncs weight data from Fitbit API to Garmin Connect +import base64 import sys import asyncio import json @@ -139,38 +140,19 @@ class ConfigManager: port=consul_config.get('port', 8500) ) prefix = consul_config.get('prefix', 'fitbit-garmin-sync').strip('/') - config_prefix = f"{prefix}/config/" + full_config_key = f"{prefix}/config" # The key where the full JSON config is stored - index, data = c.kv.get(config_prefix, recurse=True) + index, data = c.kv.get(full_config_key) # Fetch this specific key - if not data: - logger.info("No configuration found in Consul at prefix: %s", config_prefix) + if not data or not data.get('Value'): + logger.info("No configuration found in Consul at key: %s", full_config_key) return - consul_conf = {} - for item in data: - key_path = item['Key'].replace(config_prefix, '').split('/') - value_str = item['Value'].decode('utf-8') - - # Try to convert value to appropriate type - value: object - if value_str.lower() == 'true': - value = True - elif value_str.lower() == 'false': - value = False - elif value_str.isdigit(): - value = int(value_str) - else: - try: - value = float(value_str) - except ValueError: - value = value_str # It's a string + # Value is base64 encoded JSON + encoded_value = data['Value'] + decoded_json_str = base64.b64decode(encoded_value).decode('utf-8') + consul_conf = json.loads(decoded_json_str) # Parse the JSON - temp_conf = consul_conf - for part in key_path[:-1]: - temp_conf = temp_conf.setdefault(part, {}) - temp_conf[key_path[-1]] = value - # Deep merge consul_conf into self.config self._deep_merge(self.config, consul_conf) logger.info("Successfully loaded and merged configuration from Consul.")