This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
FROM python:alpine as base
|
||||
FROM python:alpine
|
||||
|
||||
ENV APKG_IS_DOCKER=true
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
||||
86
main.py
86
main.py
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
from configparser import ConfigParser
|
||||
|
||||
import requests
|
||||
|
||||
@@ -15,56 +15,68 @@ apps = {
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
# Handle apps (get versions)
|
||||
for app, url in apps.items():
|
||||
ini_version = data["Versions"][app] # Version previously packaged from data.ini
|
||||
|
||||
response = requests.get(url)
|
||||
|
||||
# Parse through JSON data
|
||||
if response.status_code == 200:
|
||||
json = response.json()
|
||||
version = json["id"]
|
||||
|
||||
ini_version = str(version)
|
||||
|
||||
# Package new versions if available
|
||||
if version != ini_version:
|
||||
logging.info(f"Found new version ({version}) for {app}, packaging..")
|
||||
|
||||
pkg(app, version)
|
||||
|
||||
# Write changes
|
||||
with open("data.ini", "w") as datafile:
|
||||
data.write(datafile)
|
||||
|
||||
|
||||
# Main Application
|
||||
if __name__ == "__main__":
|
||||
class Autopkg:
|
||||
def __init__(self):
|
||||
# Logging Setup
|
||||
setup_log()
|
||||
|
||||
logging.info("Running Autopkg (c) 2025 phantom <phantom@shadeouts.net> https://shadeouts.net/")
|
||||
logging.info("Running autopkg (c) 2025 phantom <phantom@shadeouts.net> https://shadeouts.net/")
|
||||
|
||||
# Environment Setup
|
||||
target = os.getenv("APKG_TARGET")
|
||||
|
||||
if target == "prod":
|
||||
datafile = "/etc/autopkg/data.ini"
|
||||
elif target == "test" or None:
|
||||
self.datafile = "/etc/autopkg/data.ini"
|
||||
elif target == "test" or target == "debug":
|
||||
logging.warning("Running autopkg in testing mode!")
|
||||
|
||||
datafile = "test/data.ini"
|
||||
self.datafile = os.path.dirname(os.path.abspath(__file__)) + "/test/data.ini"
|
||||
|
||||
if os.path.exists(self.datafile): os.remove(self.datafile)
|
||||
else:
|
||||
raise ValueError("APKG_TARGET environment variable not setup correctly!")
|
||||
|
||||
## Config File Setup
|
||||
data = configparser.ConfigParser()
|
||||
self.data = ConfigParser()
|
||||
|
||||
data.read(datafile)
|
||||
self.data.read(self.datafile)
|
||||
|
||||
## Setup file if not present
|
||||
if "Versions" not in data:
|
||||
data["Versions"] = {}
|
||||
if "Versions" not in self.data:
|
||||
self.data.add_section("Versions")
|
||||
|
||||
self.write_data()
|
||||
|
||||
|
||||
# Write datafile changes
|
||||
def write_data(self):
|
||||
with open(self.datafile, "w") as f:
|
||||
self.data.write(f)
|
||||
|
||||
|
||||
# Main Application
|
||||
def main(self):
|
||||
# Handle apps (get versions)
|
||||
for app, url in apps.items():
|
||||
ini_version = self.data.getint("Versions", app, fallback=0) # Version previously packaged from data.ini
|
||||
|
||||
response = requests.get(url) # Fetch data from API
|
||||
|
||||
# Parse through JSON data
|
||||
if response.status_code == 200:
|
||||
json = response.json()
|
||||
version = json["id"] # App version from API
|
||||
|
||||
# Package new versions if available
|
||||
if version != ini_version:
|
||||
logging.info(f"Found new version ({version}) for {app}, packaging..")
|
||||
|
||||
if pkg(app, version):
|
||||
ini_version = str(version)
|
||||
|
||||
self.write_data()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Call main function
|
||||
main()
|
||||
Autopkg().main()
|
||||
|
||||
@@ -29,5 +29,9 @@ def pkg(app, version):
|
||||
image = build(client, app)
|
||||
|
||||
container = run(client, image, app)
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
logging.error(f"Error starting docker container for {app}")
|
||||
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user