33 lines
865 B
Python
33 lines
865 B
Python
import os
|
|
import logging
|
|
|
|
import docker
|
|
|
|
from logger import setup_log
|
|
|
|
# Container Management
|
|
|
|
## Build Image
|
|
class Package:
|
|
def __init__(self, app: str, version: str):
|
|
# Logging Setup
|
|
setup_log()
|
|
|
|
# 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()
|
|
|
|
def run(self, image):
|
|
container = self.client.containers.run(self.image, detach=True, name=f"autopkg-{self.app}")
|
|
return container
|