stuff
This commit is contained in:
@@ -26,26 +26,30 @@ 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):
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
if container:
|
||||
container.start()
|
||||
|
||||
else:
|
||||
image = "felddy/foundryvtt:{version}".format(version=version)
|
||||
labels = build_container_routing_labels(table.game_table_link, False)
|
||||
volumes = {
|
||||
@@ -60,8 +64,12 @@ def start_foundry_container(table: GameTable, version=12):
|
||||
"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={"30000":"30000"}, detach=True
|
||||
image=image, labels=labels, volumes=volumes, environment=environment, ports=ports, detach=True
|
||||
)
|
||||
|
||||
return container.id
|
||||
|
||||
@@ -98,12 +98,14 @@ def activate_table(table_id):
|
||||
def deactivate_table(table_id):
|
||||
db = get_db()
|
||||
cursor = db.cursor()
|
||||
|
||||
table = game_tables.read_by_id(table_id, cursor)
|
||||
key = key_tables.get_key_for_table(table_id, cursor)
|
||||
|
||||
if table == None:
|
||||
"No such table", 404
|
||||
return "No such table", 404
|
||||
|
||||
if not table.active:
|
||||
return "Table not active", 400
|
||||
|
||||
table.active = False
|
||||
if key != None:
|
||||
|
||||
Reference in New Issue
Block a user