Implement version checking and basic refactoring
All checks were successful
Build Docker Image / build (push) Successful in 27s
All checks were successful
Build Docker Image / build (push) Successful in 27s
This commit is contained in:
47
package.py
47
package.py
@@ -1,37 +1,32 @@
|
||||
import os
|
||||
import logging
|
||||
|
||||
import docker
|
||||
from docker import DockerClient
|
||||
|
||||
from logger import setup_log
|
||||
|
||||
# Container Management
|
||||
|
||||
## Build Image
|
||||
def build(client: DockerClient, app: str):
|
||||
with open(f"{app}/Dockerfile") as dockerfile:
|
||||
image, _ = client.images.build(fileobj=dockerfile, tag=app)
|
||||
return image
|
||||
class Package:
|
||||
def __init__(self, app: str, version: str):
|
||||
# Logging Setup
|
||||
setup_log()
|
||||
|
||||
## Run Image
|
||||
def run(client: DockerClient, image, app: str):
|
||||
container = client.containers.run(image, detach=True, name=f"autopkg-{app}")
|
||||
return container
|
||||
# Variable Setup
|
||||
self.runtime_dir = os.getenv("APKG_RUNTIME_DIR")
|
||||
self.client = docker.from_env() # Docker.sock connection
|
||||
self.app = app
|
||||
self.version = version
|
||||
|
||||
# Main Packaging Function
|
||||
def build(self):
|
||||
with open(f"{self.runtime_dir}/{self.app}/Dockerfile") as dockerfile:
|
||||
self.image, _ = self.client.images.build(fileobj=dockerfile, tag=f"{self.app}-{self.version}")
|
||||
|
||||
# Run Container
|
||||
self.run()
|
||||
|
||||
# Main Packaging Function
|
||||
def pkg(app, version):
|
||||
# Logging Setup
|
||||
setup_log()
|
||||
|
||||
client = docker.from_env() # Docker.sock connection
|
||||
|
||||
try:
|
||||
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
|
||||
def run(self, image):
|
||||
container = self.client.containers.run(self.image, detach=True, name=f"autopkg-{self.app}")
|
||||
return container
|
||||
|
||||
Reference in New Issue
Block a user