Working with hard resets
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user