v1.0.0b3
All checks were successful
Build Docker Image / build (push) Successful in 35s

This commit is contained in:
2025-11-29 09:52:29 -06:00
parent 70f64f1766
commit dcfb2b89d5
3 changed files with 63 additions and 45 deletions

View File

@@ -1,4 +1,6 @@
FROM python:alpine as base FROM python:alpine
ENV APKG_IS_DOCKER=true
WORKDIR /app WORKDIR /app

86
main.py
View File

@@ -1,6 +1,6 @@
import os import os
import logging import logging
import configparser from configparser import ConfigParser
import requests import requests
@@ -15,56 +15,68 @@ apps = {
} }
def main(): class Autopkg:
# Handle apps (get versions) def __init__(self):
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__":
# Logging Setup # Logging Setup
setup_log() 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 # Environment Setup
target = os.getenv("APKG_TARGET") target = os.getenv("APKG_TARGET")
if target == "prod": if target == "prod":
datafile = "/etc/autopkg/data.ini" self.datafile = "/etc/autopkg/data.ini"
elif target == "test" or None: elif target == "test" or target == "debug":
logging.warning("Running autopkg in testing mode!") 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 ## Config File Setup
data = configparser.ConfigParser() self.data = ConfigParser()
data.read(datafile) self.data.read(self.datafile)
## Setup file if not present ## Setup file if not present
if "Versions" not in data: if "Versions" not in self.data:
data["Versions"] = {} 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 # Call main function
main() Autopkg().main()

View File

@@ -29,5 +29,9 @@ def pkg(app, version):
image = build(client, app) image = build(client, app)
container = run(client, image, app) container = run(client, image, app)
return True
except Exception as e: except Exception as e:
logging.error(f"Error starting docker container for {app}") logging.error(f"Error starting docker container for {app}")
return False