Compare commits
3 Commits
33f3ddd7e9
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| b63abca296 | |||
| 1311aadffb | |||
| f903ddeee5 |
@@ -1,52 +0,0 @@
|
|||||||
# ABOUTME: Periodic batch job for PhaseFlow Garmin sync.
|
|
||||||
# ABOUTME: Triggers daily sync at 6 AM to fetch fitness data and generate training recommendations.
|
|
||||||
|
|
||||||
job "phaseflow-cron" {
|
|
||||||
datacenters = ["alo"]
|
|
||||||
type = "batch"
|
|
||||||
|
|
||||||
periodic {
|
|
||||||
crons = ["0 8 * * *"]
|
|
||||||
prohibit_overlap = true
|
|
||||||
time_zone = "Europe/Lisbon"
|
|
||||||
}
|
|
||||||
|
|
||||||
group "garmin-sync" {
|
|
||||||
task "trigger" {
|
|
||||||
driver = "raw_exec"
|
|
||||||
|
|
||||||
config {
|
|
||||||
command = "/bin/sh"
|
|
||||||
args = ["local/script.sh"]
|
|
||||||
}
|
|
||||||
|
|
||||||
template {
|
|
||||||
destination = "local/script.sh"
|
|
||||||
data = <<EOH
|
|
||||||
set -e
|
|
||||||
RESPONSE=$(/run/current-system/sw/bin/curl -s -w "\n%%{http_code}" -X POST \
|
|
||||||
-H "Authorization: Bearer $CRON_SECRET" \
|
|
||||||
https://phaseflow.v.paler.net/api/cron/garmin-sync)
|
|
||||||
|
|
||||||
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
|
|
||||||
BODY=$(echo "$RESPONSE" | sed '$d')
|
|
||||||
|
|
||||||
echo "$BODY"
|
|
||||||
|
|
||||||
if [ "$HTTP_CODE" -ge 400 ]; then
|
|
||||||
echo "HTTP error: $HTTP_CODE" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
EOH
|
|
||||||
}
|
|
||||||
|
|
||||||
template {
|
|
||||||
destination = "secrets/env.env"
|
|
||||||
env = true
|
|
||||||
data = <<EOH
|
|
||||||
{{- with nomadVar "secrets/phaseflow" -}}CRON_SECRET="{{ .cron_secret }}"{{- end -}}
|
|
||||||
EOH
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,8 @@
|
|||||||
# Setup required before running:
|
# Setup required before running:
|
||||||
# sudo mkdir -p /data/services/phaseflow/pb_data && sudo chown 1000:1000 /data/services/phaseflow /data/services/phaseflow/pb_data
|
# sudo mkdir -p /data/services/phaseflow/pb_data && sudo chown 1000:1000 /data/services/phaseflow /data/services/phaseflow/pb_data
|
||||||
# nomad var put secrets/phaseflow \
|
# nomad var put secrets/phaseflow \
|
||||||
# resend_api_key="re_xxxx" \
|
# mailgun_api_key="key-xxxx" \
|
||||||
|
# mailgun_domain="paler.net" \
|
||||||
# encryption_key="$(openssl rand -hex 16)" \
|
# encryption_key="$(openssl rand -hex 16)" \
|
||||||
# cron_secret="$(openssl rand -hex 32)" \
|
# cron_secret="$(openssl rand -hex 32)" \
|
||||||
# pocketbase_admin_email="admin@example.com" \
|
# pocketbase_admin_email="admin@example.com" \
|
||||||
@@ -89,6 +90,7 @@ job "phaseflow" {
|
|||||||
NEXT_PUBLIC_POCKETBASE_URL = "https://pocketbase-phaseflow.v.paler.net"
|
NEXT_PUBLIC_POCKETBASE_URL = "https://pocketbase-phaseflow.v.paler.net"
|
||||||
APP_URL = "https://phaseflow.v.paler.net"
|
APP_URL = "https://phaseflow.v.paler.net"
|
||||||
EMAIL_FROM = "phaseflow@paler.net"
|
EMAIL_FROM = "phaseflow@paler.net"
|
||||||
|
MAILGUN_URL = "https://api.eu.mailgun.net"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Secrets from Nomad variables
|
# Secrets from Nomad variables
|
||||||
@@ -96,7 +98,8 @@ job "phaseflow" {
|
|||||||
destination = "secrets/env.env"
|
destination = "secrets/env.env"
|
||||||
env = true
|
env = true
|
||||||
data = <<EOH
|
data = <<EOH
|
||||||
RESEND_API_KEY={{ with nomadVar "secrets/phaseflow" }}{{ .resend_api_key }}{{ end }}
|
MAILGUN_API_KEY={{ with nomadVar "secrets/phaseflow" }}{{ .mailgun_api_key }}{{ end }}
|
||||||
|
MAILGUN_DOMAIN={{ with nomadVar "secrets/phaseflow" }}{{ .mailgun_domain }}{{ end }}
|
||||||
ENCRYPTION_KEY={{ with nomadVar "secrets/phaseflow" }}{{ .encryption_key }}{{ end }}
|
ENCRYPTION_KEY={{ with nomadVar "secrets/phaseflow" }}{{ .encryption_key }}{{ end }}
|
||||||
CRON_SECRET={{ with nomadVar "secrets/phaseflow" }}{{ .cron_secret }}{{ end }}
|
CRON_SECRET={{ with nomadVar "secrets/phaseflow" }}{{ .cron_secret }}{{ end }}
|
||||||
POCKETBASE_ADMIN_EMAIL={{ with nomadVar "secrets/phaseflow" }}{{ .pocketbase_admin_email }}{{ end }}
|
POCKETBASE_ADMIN_EMAIL={{ with nomadVar "secrets/phaseflow" }}{{ .pocketbase_admin_email }}{{ end }}
|
||||||
|
|||||||
Reference in New Issue
Block a user