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

This commit is contained in:
2025-11-28 04:51:21 -06:00
parent 9392eded43
commit 70f64f1766
8 changed files with 59 additions and 50 deletions

View File

@@ -1 +1,2 @@
.devcontainer/
pkg/ pkg/

View File

@@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v6 uses: actions/checkout@v6
- name: Login to Gitea Registry - name: Login to Gitea Registry
if: github.event_name != 'pull_request' if: gitea.event_name != 'pull_request'
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: git.shadeouts.net registry: git.shadeouts.net

2
.gitignore vendored
View File

@@ -2,3 +2,5 @@
__pycache__/ __pycache__/
.venv/ .venv/
test/ test/
.devcontainer/

View File

@@ -7,4 +7,4 @@ COPY . .
RUN crontab autopkg.cron RUN crontab autopkg.cron
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt
CMD crond -f && python main.py CMD python main.py; crond -f

View File

@@ -1,10 +1,11 @@
services: services:
autopkg: autopkg:
image: EDITTHISNOW image: git.shadeouts.net/phantom/autopkg
container_name: autopkg container_name: autopkg
restart: unless-stopped restart: unless-stopped
volumes: volumes:
- $PWD/data.ini:/etc/autopkg/data.ini - $PWD/data.ini:/etc/autopkg/data.ini
- $PWD/autopkg.log:/var/log/autopkg.log - /var/run/docker.sock:/var/run/docker.sock
environment: environment:
# debug, test, or prod
APKG_TARGET: "prod" APKG_TARGET: "prod"

View File

@@ -1,16 +1,12 @@
import os
import logging import logging
from main import logfile # Setup logging
def setup_log():
loglevel = 10 if os.getenv("APKG_TARGET") == "debug" else 20
# Setup Logging logging.basicConfig(
logging.basicConfig(filename=logfile, format="%(asctime)s %(levelname)s %(message)s",
encoding="utf-8", datefmt="%Y-%m-%d %H:%M:%S",
filemode="a", level=loglevel
format="%(asctime)s %(name)s %(levelname)s %(message)s", )
datefmt="%Y-%m-%d %H:%M:%S",
level=logging.INFO)
# Logging handler
## DEBUG (10), INFO (20), WARNING (30), ERROR (40), and CRITICAL (50)
def log(msg: str, level=20):
logging.log(level=level, msg=msg)

64
main.py
View File

@@ -1,35 +1,12 @@
import os import os
import logging
import configparser import configparser
import requests import requests
import logger from logger import setup_log
from package import pkg from package import pkg
# Local Variables
## Autopkg Environment Setup
_target = os.getenv("APKG_TARGET")
if _target == "prod":
datafile = "/etc/autopkg/data.ini"
logfile = "/var/log/autopkg.log"
elif _target == "test":
datafile = "test/data.ini"
logfile = "test/autopkg.log"
else:
logger.log("APKG_TARGET not defined", 50)
exit()
## Setup Config
data = configparser.ConfigParser()
data.read(datafile)
if "Versions" not in data: ## Setup file if not present
data["Versions"] = {}
## Autopkg Apps ## Autopkg Apps
apps = { apps = {
@@ -38,10 +15,7 @@ apps = {
} }
# Main Application def main():
if __name__ == "__main__":
logger.log("Running Autopkg (c) 2025 phantom <phantom@shadeouts.net> https://shadeouts.net/")
# Handle apps (get versions) # Handle apps (get versions)
for app, url in apps.items(): for app, url in apps.items():
ini_version = data["Versions"][app] # Version previously packaged from data.ini ini_version = data["Versions"][app] # Version previously packaged from data.ini
@@ -57,10 +31,40 @@ if __name__ == "__main__":
# Package new versions if available # Package new versions if available
if version != ini_version: if version != ini_version:
logger.log(f"Found new version ({version}) for {app}, packaging..") logging.info(f"Found new version ({version}) for {app}, packaging..")
pkg(app, version) pkg(app, version)
# Write changes # Write changes
with open("data.ini", "w") as datafile: with open("data.ini", "w") as datafile:
data.write(datafile) data.write(datafile)
# Main Application
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
main()

View File

@@ -1,7 +1,9 @@
import logging
import docker import docker
from docker import DockerClient from docker import DockerClient
import logger from logger import setup_log
# Container Management # Container Management
@@ -18,6 +20,9 @@ def run(client: DockerClient, image, app: str):
# Main Packaging Function # Main Packaging Function
def pkg(app, version): def pkg(app, version):
# Logging Setup
setup_log()
client = docker.from_env() # Docker.sock connection client = docker.from_env() # Docker.sock connection
try: try:
@@ -25,4 +30,4 @@ def pkg(app, version):
container = run(client, image, app) container = run(client, image, app)
except Exception as e: except Exception as e:
logger.log(f"Error starting docker container for {app}", 40) logging.error(f"Error starting docker container for {app}")