27 lines
615 B
Python
27 lines
615 B
Python
import docker
|
|
|
|
from docker import DockerClient
|
|
|
|
# Container Management
|
|
|
|
## Build Image
|
|
def build(client: DockerClient, app: str):
|
|
with open(f"{app}/Dockerfile") as dockerfile:
|
|
image, _ = client.images.build(fileobj=dockerfile, tag="")
|
|
return image
|
|
|
|
## Run Image
|
|
def run(client: DockerClient, image, app: str):
|
|
container = client.containers.run(image, detach=True, name=app)
|
|
|
|
# Main Packaging Function
|
|
def pkg(app, version):
|
|
client = docker.from_env()
|
|
|
|
try:
|
|
image = build(client, app)
|
|
|
|
container = run(client, image, app)
|
|
except Exception as e:
|
|
print("Error")
|