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/

View File

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

4
.gitignore vendored
View File

@@ -1,4 +1,6 @@
.git/
__pycache__/
.venv/
test/
test/
.devcontainer/

View File

@@ -7,4 +7,4 @@ COPY . .
RUN crontab autopkg.cron
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:
autopkg:
image: EDITTHISNOW
image: git.shadeouts.net/phantom/autopkg
container_name: autopkg
restart: unless-stopped
volumes:
- $PWD/data.ini:/etc/autopkg/data.ini
- $PWD/autopkg.log:/var/log/autopkg.log
- /var/run/docker.sock:/var/run/docker.sock
environment:
# debug, test, or prod
APKG_TARGET: "prod"

View File

@@ -1,16 +1,12 @@
import os
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(filename=logfile,
encoding="utf-8",
filemode="a",
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)
logging.basicConfig(
format="%(asctime)s %(levelname)s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
level=loglevel
)

64
main.py
View File

@@ -1,35 +1,12 @@
import os
import logging
import configparser
import requests
import logger
from logger import setup_log
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
apps = {
@@ -38,10 +15,7 @@ apps = {
}
# Main Application
if __name__ == "__main__":
logger.log("Running Autopkg (c) 2025 phantom <phantom@shadeouts.net> https://shadeouts.net/")
def main():
# Handle apps (get versions)
for app, url in apps.items():
ini_version = data["Versions"][app] # Version previously packaged from data.ini
@@ -57,10 +31,40 @@ if __name__ == "__main__":
# Package new versions if available
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)
# Write changes
with open("data.ini", "w") as 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
from docker import DockerClient
import logger
from logger import setup_log
# Container Management
@@ -18,6 +20,9 @@ def run(client: DockerClient, image, app: str):
# Main Packaging Function
def pkg(app, version):
# Logging Setup
setup_log()
client = docker.from_env() # Docker.sock connection
try:
@@ -25,4 +30,4 @@ def pkg(app, version):
container = run(client, image, app)
except Exception as e:
logger.log(f"Error starting docker container for {app}", 40)
logging.error(f"Error starting docker container for {app}")