mirror of
https://github.com/auricom/home-cluster.git
synced 2025-09-17 18:24:14 +02:00
feat: archive pushover-notifier
This commit is contained in:
@@ -41,7 +41,6 @@ resources:
|
||||
- ./plant-it/ks.yaml
|
||||
- ./pgadmin/ks.yaml
|
||||
- ./prowlarr/ks.yaml
|
||||
- ./pushover-notifier/ks.yaml
|
||||
- ./qbittorrent/ks.yaml
|
||||
- ./radarr/ks.yaml
|
||||
- ./readeck/ks.yaml
|
||||
|
@@ -1,36 +0,0 @@
|
||||
---
|
||||
# yaml-language-server: $schema=https://kubernetes-schemas.pages.dev/external-secrets.io/externalsecret_v1beta1.json
|
||||
apiVersion: external-secrets.io/v1beta1
|
||||
kind: ExternalSecret
|
||||
metadata:
|
||||
name: pushover-notifier
|
||||
namespace: default
|
||||
spec:
|
||||
secretStoreRef:
|
||||
kind: ClusterSecretStore
|
||||
name: onepassword-connect
|
||||
target:
|
||||
name: pushover-notifier-secret
|
||||
template:
|
||||
engineVersion: v2
|
||||
data:
|
||||
# App
|
||||
POSTGRES_DB: &dbName pushover-notifier
|
||||
POSTGRES_HOST: &dbHost postgres16-rw.database.svc.cluster.local
|
||||
POSTGRES_USER: &dbUser "{{ .POSTGRES_USER }}"
|
||||
POSTGRES_PASS: &dbPass "{{ .POSTGRES_PASS }}"
|
||||
PUSHOVER_API_TOKEN: "{{ .PUSHOVER_API_TOKEN }}"
|
||||
PUSHOVER_USER_KEY: "{{ .PUSHOVER_USER_KEY }}"
|
||||
# Postgres Init
|
||||
INIT_POSTGRES_DBNAME: *dbName
|
||||
INIT_POSTGRES_HOST: *dbHost
|
||||
INIT_POSTGRES_USER: *dbUser
|
||||
INIT_POSTGRES_PASS: *dbPass
|
||||
INIT_POSTGRES_SUPER_PASS: "{{ .POSTGRES_SUPER_PASS }}"
|
||||
dataFrom:
|
||||
- extract:
|
||||
key: cloudnative-pg
|
||||
- extract:
|
||||
key: pushover-notifier
|
||||
- extract:
|
||||
key: pushover
|
@@ -1,16 +0,0 @@
|
||||
repositories:
|
||||
- name: fluxcd/flux2
|
||||
check: "releases"
|
||||
- name: opnsense/core
|
||||
check: "tags"
|
||||
ignore_tags_containing:
|
||||
- a
|
||||
- b
|
||||
- r
|
||||
- name: siderolabs/talos
|
||||
check: "releases"
|
||||
- name: truenas/core-build
|
||||
check: "tags"
|
||||
ignore_tags_containing:
|
||||
- TrueNAS
|
||||
- FN
|
@@ -1,139 +0,0 @@
|
||||
import os
|
||||
import requests
|
||||
import yaml
|
||||
import psycopg2
|
||||
from psycopg2 import sql
|
||||
from datetime import datetime
|
||||
from requests.exceptions import HTTPError
|
||||
|
||||
# Load configuration file
|
||||
with open("config.yaml", "r") as config_file:
|
||||
config = yaml.safe_load(config_file)
|
||||
|
||||
# Pushover credentials
|
||||
PUSHOVER_API_URL = "https://api.pushover.net/1/messages.json"
|
||||
PUSHOVER_API_TOKEN = os.environ["PUSHOVER_API_TOKEN"]
|
||||
PUSHOVER_USER_KEY = os.environ["PUSHOVER_USER_KEY"]
|
||||
|
||||
# PostgreSQL connection
|
||||
conn = psycopg2.connect(
|
||||
dbname=os.environ["POSTGRES_DB"],
|
||||
user=os.environ["POSTGRES_USER"],
|
||||
password=os.environ["POSTGRES_PASS"],
|
||||
host=os.environ["POSTGRES_HOST"],
|
||||
port=os.environ.get("POSTGRES_PORT", "5432"),
|
||||
)
|
||||
|
||||
# Create table if not exists
|
||||
def create_table():
|
||||
with conn.cursor() as cursor:
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS github_releases (
|
||||
repo_name VARCHAR(255) PRIMARY KEY,
|
||||
latest_release VARCHAR(255),
|
||||
release_date TIMESTAMP
|
||||
)
|
||||
""")
|
||||
conn.commit()
|
||||
|
||||
# Check for new release
|
||||
def check_new_release(repo_name):
|
||||
try:
|
||||
response = requests.get(f"https://api.github.com/repos/{repo_name}/releases/latest")
|
||||
response.raise_for_status()
|
||||
release_data = response.json()
|
||||
return release_data["tag_name"], release_data["published_at"]
|
||||
except HTTPError as e:
|
||||
if e.response.status_code == 404:
|
||||
# Handle the case where the release is not found
|
||||
# For example, return None or check for tags instead
|
||||
return None, None
|
||||
else:
|
||||
raise
|
||||
|
||||
# Function to check if tag should be ignored
|
||||
def should_ignore_tag(tag_name, ignore_list):
|
||||
return any(ignore_str in tag_name for ignore_str in ignore_list)
|
||||
|
||||
# Modified function to check for latest tag
|
||||
def check_latest_tag(repo_name, ignore_list):
|
||||
response = requests.get(f"https://api.github.com/repos/{repo_name}/tags")
|
||||
response.raise_for_status()
|
||||
tags = response.json()
|
||||
|
||||
for tag in tags:
|
||||
tag_name = tag["name"]
|
||||
if should_ignore_tag(tag_name, ignore_list):
|
||||
continue # Skip this tag as it's in the ignore list
|
||||
|
||||
commit_url = tag["commit"]["url"]
|
||||
commit_response = requests.get(commit_url)
|
||||
commit_response.raise_for_status()
|
||||
commit_data = commit_response.json()
|
||||
commit_date = commit_data["commit"]["committer"]["date"]
|
||||
|
||||
return tag_name, commit_date
|
||||
|
||||
return None, None # No valid tags found
|
||||
|
||||
# Send pushover notification
|
||||
def send_pushover_notification(repo_name, tag_name):
|
||||
payload = {
|
||||
"token": PUSHOVER_API_TOKEN,
|
||||
"user": PUSHOVER_USER_KEY,
|
||||
"html": "1",
|
||||
"message": f'New stable release {tag_name} for repository <a href="https://github.com/{repo_name}">{repo_name}</a> is available.'
|
||||
}
|
||||
response = requests.post(PUSHOVER_API_URL, data=payload)
|
||||
response.raise_for_status()
|
||||
|
||||
# Main function
|
||||
def main():
|
||||
create_table()
|
||||
|
||||
for repo_config in config["repositories"]:
|
||||
repo_name = repo_config["name"]
|
||||
check_type = repo_config.get("check", "releases")
|
||||
ignore_list = repo_config.get("ignore_tags_containing", [])
|
||||
|
||||
print(f"Checking {check_type} for repository: {repo_name}")
|
||||
|
||||
if check_type == "releases":
|
||||
latest_tag, release_date = check_new_release(repo_name)
|
||||
if latest_tag is None or release_date is None:
|
||||
print(f"No release found for {repo_name}")
|
||||
continue
|
||||
elif check_type == "tags":
|
||||
latest_tag, release_date = check_latest_tag(repo_name, ignore_list)
|
||||
if latest_tag is None or release_date is None:
|
||||
print(f"No valid tags found for {repo_name}, moving to next repository.")
|
||||
continue
|
||||
else:
|
||||
print(f"Invalid check type for {repo_name}: {check_type}")
|
||||
continue
|
||||
|
||||
print(f"Latest tag for {repo_name}: {latest_tag}, published at: {release_date}")
|
||||
release_date = datetime.strptime(release_date, "%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
with conn.cursor() as cursor:
|
||||
print(f"Updating database for {repo_name}...")
|
||||
cursor.execute("""
|
||||
INSERT INTO github_releases (repo_name, latest_release, release_date)
|
||||
VALUES (%s, %s, %s)
|
||||
ON CONFLICT (repo_name) DO UPDATE
|
||||
SET latest_release = EXCLUDED.latest_release,
|
||||
release_date = EXCLUDED.release_date
|
||||
WHERE EXCLUDED.release_date > github_releases.release_date
|
||||
RETURNING *
|
||||
""", (repo_name, latest_tag, release_date))
|
||||
result = cursor.fetchone()
|
||||
conn.commit()
|
||||
|
||||
if result:
|
||||
print(f"New release for {repo_name} found, sending notification.")
|
||||
send_pushover_notification(repo_name, latest_tag)
|
||||
else:
|
||||
print(f"No new release to update for {repo_name}.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@@ -1,88 +0,0 @@
|
||||
---
|
||||
# yaml-language-server: $schema=https://raw.githubusercontent.com/bjw-s/helm-charts/main/charts/other/app-template/schemas/helmrelease-helm-v2.schema.json
|
||||
apiVersion: helm.toolkit.fluxcd.io/v2
|
||||
kind: HelmRelease
|
||||
metadata:
|
||||
name: &app pushover-notifier-github-releases
|
||||
namespace: default
|
||||
spec:
|
||||
interval: 30m
|
||||
chart:
|
||||
spec:
|
||||
chart: app-template
|
||||
version: 3.3.2
|
||||
sourceRef:
|
||||
kind: HelmRepository
|
||||
name: bjw-s
|
||||
namespace: flux-system
|
||||
maxHistory: 2
|
||||
install:
|
||||
createNamespace: true
|
||||
remediation:
|
||||
retries: 3
|
||||
upgrade:
|
||||
cleanupOnFail: true
|
||||
remediation:
|
||||
retries: 3
|
||||
uninstall:
|
||||
keepHistory: false
|
||||
values:
|
||||
controllers:
|
||||
pushover-notifier-github-releases:
|
||||
type: cronjob
|
||||
cronjob:
|
||||
concurrencyPolicy: Forbid
|
||||
schedule: 23 */3 * * *
|
||||
initContainers:
|
||||
init-db:
|
||||
image:
|
||||
repository: ghcr.io/onedr0p/postgres-init
|
||||
tag: 16
|
||||
envFrom: &envFrom
|
||||
- secretRef:
|
||||
name: pushover-notifier-secret
|
||||
containers:
|
||||
app:
|
||||
image:
|
||||
repository: cgr.dev/chainguard/python
|
||||
tag: latest-dev@sha256:39d3b461ec14222f7eadb6cf5c64153291c03aca514e09b307b77aa60d0f0a3b
|
||||
command:
|
||||
- /bin/bash
|
||||
- -c
|
||||
- |
|
||||
#!/bin/bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
|
||||
pip install requests PyYAML psycopg2-binary
|
||||
|
||||
cd /app
|
||||
|
||||
python /app/script.py
|
||||
envFrom: *envFrom
|
||||
resources:
|
||||
requests:
|
||||
cpu: 50m
|
||||
memory: 250Mi
|
||||
limits:
|
||||
memory: 250Mi
|
||||
service:
|
||||
app:
|
||||
controller: *app
|
||||
enabled: false
|
||||
persistence:
|
||||
config:
|
||||
enabled: true
|
||||
type: configMap
|
||||
name: pushover-notifier-github-releases-configmap
|
||||
globalMounts:
|
||||
- path: /app/config.yaml
|
||||
subPath: config.yaml
|
||||
script:
|
||||
enabled: true
|
||||
type: configMap
|
||||
name: pushover-notifier-github-releases-configmap
|
||||
globalMounts:
|
||||
- path: /app/script.py
|
||||
subPath: script.py
|
@@ -1,14 +0,0 @@
|
||||
---
|
||||
# yaml-language-server: $schema=https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/kustomization.json
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
namespace: default
|
||||
resources:
|
||||
- ./helmrelease.yaml
|
||||
configMapGenerator:
|
||||
- name: pushover-notifier-github-releases-configmap
|
||||
files:
|
||||
- ./config/config.yaml
|
||||
- ./config/script.py
|
||||
generatorOptions:
|
||||
disableNameSuffixHash: true
|
@@ -1,8 +0,0 @@
|
||||
---
|
||||
# yaml-language-server: $schema=https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/kustomization.json
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
namespace: default
|
||||
resources:
|
||||
- ./externalsecret.yaml
|
||||
- ./github-releases
|
@@ -1,26 +0,0 @@
|
||||
---
|
||||
# yaml-language-server: $schema=https://raw.githubusercontent.com/fluxcd-community/flux2-schemas/main/kustomization-kustomize-v1.json
|
||||
apiVersion: kustomize.toolkit.fluxcd.io/v1
|
||||
kind: Kustomization
|
||||
metadata:
|
||||
name: &app pushover-notifier
|
||||
namespace: flux-system
|
||||
spec:
|
||||
targetNamespace: default
|
||||
commonMetadata:
|
||||
labels:
|
||||
app.kubernetes.io/name: *app
|
||||
dependsOn:
|
||||
- name: external-secrets-stores
|
||||
path: ./kubernetes/apps/default/pushover-notifier/app
|
||||
prune: true
|
||||
sourceRef:
|
||||
kind: GitRepository
|
||||
name: home-ops-kubernetes
|
||||
wait: false
|
||||
interval: 30m
|
||||
retryInterval: 1m
|
||||
timeout: 5m
|
||||
postBuild:
|
||||
substitute:
|
||||
APP: *app
|
Reference in New Issue
Block a user