sync
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 3m1s

This commit is contained in:
2025-12-15 06:45:50 -08:00
parent 5ac0a84953
commit fcfb6d3f4e
3 changed files with 35 additions and 27 deletions

22
.github/workflows/nomad-deploy.yml vendored Normal file
View File

@@ -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

View File

@@ -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 {

View File

@@ -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.")