first commit
This commit is contained in:
24
.devcontainer/devcontainer.json
Normal file
24
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||||
|
// README at: https://github.com/devcontainers/templates/tree/main/src/python
|
||||||
|
{
|
||||||
|
"name": "Python 3",
|
||||||
|
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
||||||
|
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bookworm",
|
||||||
|
|
||||||
|
// Features to add to the dev container. More info: https://containers.dev/features.
|
||||||
|
// "features": {},
|
||||||
|
|
||||||
|
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||||
|
// "forwardPorts": [],
|
||||||
|
|
||||||
|
// Use 'postCreateCommand' to run commands after the container is created.
|
||||||
|
// "postCreateCommand": "pip3 install --user -r requirements.txt",
|
||||||
|
|
||||||
|
"postCreateCommand": "./.devcontainer/postCreateCommand.sh"
|
||||||
|
|
||||||
|
// Configure tool-specific properties.
|
||||||
|
// "customizations": {},
|
||||||
|
|
||||||
|
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
||||||
|
// "remoteUser": "root"
|
||||||
|
}
|
||||||
2
.devcontainer/postCreateCommand.sh
Executable file
2
.devcontainer/postCreateCommand.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
pip install --upgrade pip
|
||||||
|
pip3 install --user -r ./app/requirements.txt
|
||||||
7
Dockerfile
Normal file
7
Dockerfile
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
FROM registry.access.redhat.com/ubi9/python-311:1-17.1690899890
|
||||||
|
|
||||||
|
USER 0
|
||||||
|
COPY /app/. /app
|
||||||
|
RUN pip install --upgrade pip \
|
||||||
|
pip install -r /app/requirements.txt
|
||||||
|
CMD python /app/script.py
|
||||||
3
app/requirements.txt
Normal file
3
app/requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Flask
|
||||||
|
prometheus-client
|
||||||
|
requests
|
||||||
56
app/script.py
Normal file
56
app/script.py
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import requests
|
||||||
|
from flask import Flask, request
|
||||||
|
from prometheus_client import generate_latest, Gauge, CollectorRegistry
|
||||||
|
import time
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
# Create a CollectorRegistry
|
||||||
|
registry = CollectorRegistry()
|
||||||
|
|
||||||
|
# Create a Prometheus metric for the latest release
|
||||||
|
github_latest_release_metric = Gauge(
|
||||||
|
'github_latest_release',
|
||||||
|
'Latest release version of a GitHub repository',
|
||||||
|
['repo', 'version'],
|
||||||
|
registry=registry,
|
||||||
|
)
|
||||||
|
|
||||||
|
# GitHub API token (replace with your actual token)
|
||||||
|
github_api_token = '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'
|
||||||
|
|
||||||
|
# Function to fetch the latest release version from GitHub
|
||||||
|
def get_latest_release(repo_url):
|
||||||
|
api_url = f"https://api.github.com/repos/{repo_url}/releases/latest"
|
||||||
|
headers = {
|
||||||
|
'Authorization': f'Bearer {github_api_token}',
|
||||||
|
'Accept': 'application/vnd.github.v3+json'
|
||||||
|
}
|
||||||
|
response = requests.get(api_url, headers=headers)
|
||||||
|
data = response.json()
|
||||||
|
return data["tag_name"]
|
||||||
|
|
||||||
|
@app.route('/metrics')
|
||||||
|
def metrics():
|
||||||
|
# Get the GitHub repository URL from the query parameter
|
||||||
|
repo_url = request.args.get('repo')
|
||||||
|
if not repo_url:
|
||||||
|
return "Error: Please provide a 'repo' parameter.", 400
|
||||||
|
|
||||||
|
try:
|
||||||
|
latest_release = get_latest_release(repo_url)
|
||||||
|
print(f"Latest release: {latest_release}")
|
||||||
|
|
||||||
|
# Reset the metric to its initial state
|
||||||
|
github_latest_release_metric.clear()
|
||||||
|
|
||||||
|
# Set the metric value to 1 with appropriate labels
|
||||||
|
github_latest_release_metric.labels(repo=repo_url, version=latest_release).set(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error: {e}")
|
||||||
|
|
||||||
|
return generate_latest(registry)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# Start the web service on port 8000
|
||||||
|
app.run(host='0.0.0.0', port=8000)
|
||||||
Reference in New Issue
Block a user