stuff
This commit is contained in:
@@ -26,42 +26,50 @@ def build_container_routing_labels(prefix: str, strip_prefix=True):
|
||||
return labels
|
||||
|
||||
|
||||
def start_container(table_name, prefix):
|
||||
client = docker.from_env()
|
||||
labels = build_container_labels(prefix)
|
||||
|
||||
container = client.containers.run(
|
||||
image="crccheck/hello-world", detach=True, labels=labels, ports={8000: 8000}
|
||||
)
|
||||
|
||||
return container.id
|
||||
|
||||
|
||||
def stop_container(docker_id):
|
||||
client = docker.from_env()
|
||||
container = client.containers.get(docker_id)
|
||||
container.kill()
|
||||
try:
|
||||
client = docker.from_env()
|
||||
container = client.containers.get(docker_id)
|
||||
container.kill()
|
||||
return True
|
||||
except docker.errors.NotFound, docker.errors.APIError:
|
||||
return False
|
||||
|
||||
|
||||
def start_foundry_container(table: GameTable, version=12):
|
||||
client = docker.from_env()
|
||||
container = None
|
||||
|
||||
image = "felddy/foundryvtt:{version}".format(version=version)
|
||||
labels = build_container_routing_labels(table.game_table_link, False)
|
||||
volumes = {
|
||||
"/home/cow/Projects/dockertesting/server_data_mount/{prefix}".format(
|
||||
prefix=table.game_table_link
|
||||
): {"bind": "/data", "mode": "rw"},
|
||||
"/home/cow/Projects/dockertesting/server_data_mount/foundry_cache": {
|
||||
"bind": "/data/container_cache"
|
||||
},
|
||||
}
|
||||
environment = [
|
||||
"FOUNDRY_ROUTE_PREFIX={prefix}".format(prefix=table.game_table_link)
|
||||
]
|
||||
if table.docker_id != None and table.docker_id != 0 and table.docker_id != Null:
|
||||
try:
|
||||
container = client.containers.get(table.docker_id)
|
||||
except docker.errors.NotFound, docker.errors.NullResource:
|
||||
container = None
|
||||
|
||||
container = client.containers.run(
|
||||
image=image, labels=labels, volumes=volumes, environment=environment, ports={"30000":"30000"}, detach=True
|
||||
)
|
||||
if container:
|
||||
container.start()
|
||||
|
||||
else:
|
||||
image = "felddy/foundryvtt:{version}".format(version=version)
|
||||
labels = build_container_routing_labels(table.game_table_link, False)
|
||||
volumes = {
|
||||
"/home/cow/Projects/dockertesting/server_data_mount/{prefix}".format(
|
||||
prefix=table.game_table_link
|
||||
): {"bind": "/data", "mode": "rw"},
|
||||
"/home/cow/Projects/dockertesting/server_data_mount/foundry_cache": {
|
||||
"bind": "/data/container_cache"
|
||||
},
|
||||
}
|
||||
environment = [
|
||||
"FOUNDRY_ROUTE_PREFIX={prefix}".format(prefix=table.game_table_link)
|
||||
]
|
||||
|
||||
ports = {
|
||||
"30000": str(30000 + table.game_table_id)
|
||||
}
|
||||
|
||||
container = client.containers.run(
|
||||
image=image, labels=labels, volumes=volumes, environment=environment, ports=ports, detach=True
|
||||
)
|
||||
|
||||
return container.id
|
||||
|
||||
Reference in New Issue
Block a user