This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
FROM python:alpine as base
|
FROM python:alpine
|
||||||
|
|
||||||
|
ENV APKG_IS_DOCKER=true
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
|||||||
100
main.py
100
main.py
@@ -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():
|
# Logging Setup
|
||||||
ini_version = data["Versions"][app] # Version previously packaged from data.ini
|
setup_log()
|
||||||
|
|
||||||
response = requests.get(url)
|
logging.info("Running autopkg (c) 2025 phantom <phantom@shadeouts.net> https://shadeouts.net/")
|
||||||
|
|
||||||
# Parse through JSON data
|
# Environment Setup
|
||||||
if response.status_code == 200:
|
target = os.getenv("APKG_TARGET")
|
||||||
json = response.json()
|
|
||||||
version = json["id"]
|
|
||||||
|
|
||||||
ini_version = str(version)
|
if target == "prod":
|
||||||
|
self.datafile = "/etc/autopkg/data.ini"
|
||||||
|
elif target == "test" or target == "debug":
|
||||||
|
logging.warning("Running autopkg in testing mode!")
|
||||||
|
|
||||||
# Package new versions if available
|
self.datafile = os.path.dirname(os.path.abspath(__file__)) + "/test/data.ini"
|
||||||
if version != ini_version:
|
|
||||||
logging.info(f"Found new version ({version}) for {app}, packaging..")
|
|
||||||
|
|
||||||
pkg(app, version)
|
if os.path.exists(self.datafile): os.remove(self.datafile)
|
||||||
|
else:
|
||||||
|
raise ValueError("APKG_TARGET environment variable not setup correctly!")
|
||||||
|
|
||||||
# Write changes
|
## Config File Setup
|
||||||
with open("data.ini", "w") as datafile:
|
self.data = ConfigParser()
|
||||||
data.write(datafile)
|
|
||||||
|
self.data.read(self.datafile)
|
||||||
|
|
||||||
|
## Setup file if not present
|
||||||
|
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()
|
||||||
|
|
||||||
|
|
||||||
# Main Application
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Logging Setup
|
|
||||||
setup_log()
|
|
||||||
|
|
||||||
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:
|
|
||||||
logging.warning("Running autopkg in testing mode!")
|
|
||||||
|
|
||||||
datafile = "test/data.ini"
|
|
||||||
|
|
||||||
## Config File Setup
|
|
||||||
data = configparser.ConfigParser()
|
|
||||||
|
|
||||||
data.read(datafile)
|
|
||||||
|
|
||||||
## Setup file if not present
|
|
||||||
if "Versions" not in data:
|
|
||||||
data["Versions"] = {}
|
|
||||||
|
|
||||||
# Call main function
|
# Call main function
|
||||||
main()
|
Autopkg().main()
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user