From 0ed95540c6b376605b1e4681e01fb5c1161c6e3a Mon Sep 17 00:00:00 2001 From: Rasmus Lauritsen Date: Sat, 19 Aug 2023 15:45:03 +0200 Subject: [PATCH] Moved token to env variable --- README.md | 14 ++++++++++++++ app/script.py | 7 ++++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..68642bb --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# Github Latest Release Exporter +This is a simple service that fetches the latest version of software from github and exposes it as a metric for Prometheus to scrape. +Just query the endpoint with ```owner/repository``, and you will get a metric back. + + +## Development and local testing +```bash +docker buildx build -t latest_release_exporter . +docker run --name latest_release_exporter -d -p 8000:8000 -e GITHUB_TOKEN=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 latest_release_exporter +curl http://localhost:8000/metrics?repo=prometheus/prometheus + +docker stop latest_release_exporter +docker rm latest_release_exporter +``` \ No newline at end of file diff --git a/app/script.py b/app/script.py index 941fe50..f1914f0 100644 --- a/app/script.py +++ b/app/script.py @@ -1,3 +1,5 @@ +import os +import sys import requests from flask import Flask, request from prometheus_client import generate_latest, Gauge, CollectorRegistry @@ -17,7 +19,10 @@ github_latest_release_metric = Gauge( ) # GitHub API token (replace with your actual token) -github_api_token = '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' +github_api_token = os.environ.get('GITHUB_TOKEN') + +if github_api_token is None: + sys.exit("Env variable GITHUB_TOKEN not found!") # Function to fetch the latest release version or the latest tag from GitHub def get_latest_version(repo_url):