Working with hard resets

This commit is contained in:
iamBadgers
2026-04-18 21:41:08 -07:00
parent aa90ef14c3
commit 0b00377f77
4 changed files with 26 additions and 5 deletions

View File

@@ -2,6 +2,8 @@ import docker
from game_tables import GameTable
from key_tables import KeyTable
import os
import socket
import inspect
from flask import current_app
@@ -26,8 +28,19 @@ def build_container_routing_labels(prefix: str, strip_prefix=True):
return labels
def delete_container(docker_id) -> bool:
if not docker_id:
return False
def stop_container(docker_id):
try:
client = docker.from_env()
container = client.containers.get(docker_id)
container.remove()
return True
except docker.errors.NotFound, docker.errors.APIError:
return False
def stop_container(docker_id) -> bool:
try:
client = docker.from_env()
container = client.containers.get(docker_id)
@@ -40,6 +53,7 @@ def stop_container(docker_id):
def start_foundry_container(table: GameTable, key: KeyTable):
client = docker.from_env()
container = None
networkName = client.containers.get(socket.gethostname()).attrs["HostConfig"]["NetworkMode"]
if table.docker_id != None and table.docker_id != 0:
try:
@@ -60,7 +74,7 @@ def start_foundry_container(table: GameTable, key: KeyTable):
): {"bind": "/data", "mode": "rw"},
"{data_bind}/container_cache".format(
data_bind=os.environ.get("FOUNDRY_DATA_BIND")
): {"bind": "/data/container_cache", "mode": "ro"},
): {"bind": "/data/container_cache", "mode": "rw"},
}
environment = [
"FOUNDRY_ROUTE_PREFIX={prefix}".format(prefix=table.game_table_link),
@@ -77,6 +91,7 @@ def start_foundry_container(table: GameTable, key: KeyTable):
environment=environment,
ports=ports,
detach=True,
network=networkName
)
return container.id