volume support. add in subvols, too.
This commit is contained in:
@@ -8,6 +8,8 @@ from flask import current_app
|
||||
|
||||
|
||||
def build_container_routing_labels(prefix: str, strip_prefix=True):
|
||||
host_name = os.environ.get("API_HOST_NAME") or "localhost"
|
||||
|
||||
router_key = "traefik.http.routers.{prefix}.rule".format(prefix=prefix)
|
||||
middleware_key = (
|
||||
"traefik.http.middlewares.{prefix}-stripprefix.stripprefix.prefixes".format(
|
||||
@@ -19,7 +21,8 @@ def build_container_routing_labels(prefix: str, strip_prefix=True):
|
||||
)
|
||||
|
||||
labels = {}
|
||||
labels[router_key] = "Host(`localhost`) && PathPrefix(`/{prefix}`)".format(
|
||||
labels[router_key] = "Host(`{host_name}`) && PathPrefix(`/{prefix}`)".format(
|
||||
host_name=host_name,
|
||||
prefix=prefix
|
||||
)
|
||||
if strip_prefix:
|
||||
@@ -54,6 +57,8 @@ def start_foundry_container(table: GameTable, key: KeyTable):
|
||||
client = docker.from_env()
|
||||
container = None
|
||||
networkName = client.containers.get(socket.gethostname()).attrs["HostConfig"]["NetworkMode"]
|
||||
data_bind = os.environ.get("FOUNDRY_DATA_BIND")
|
||||
data_volume = os.environ.get("FOUNDRY_DATA_VOL")
|
||||
|
||||
if table.docker_id != None and table.docker_id != 0:
|
||||
try:
|
||||
@@ -65,33 +70,63 @@ def start_foundry_container(table: GameTable, key: KeyTable):
|
||||
container.start()
|
||||
|
||||
else:
|
||||
image = "felddy/foundryvtt:{version}".format(version=table.version)
|
||||
labels = build_container_routing_labels(table.game_table_link, False)
|
||||
volumes = {
|
||||
"{data_bind}/{prefix}".format(
|
||||
data_bind=os.environ.get("FOUNDRY_DATA_BIND"),
|
||||
prefix=table.game_table_link,
|
||||
): {"bind": "/data", "mode": "rw"},
|
||||
"{data_bind}/container_cache".format(
|
||||
data_bind=os.environ.get("FOUNDRY_DATA_BIND")
|
||||
): {"bind": "/data/container_cache", "mode": "rw"},
|
||||
}
|
||||
|
||||
environment = [
|
||||
"FOUNDRY_ROUTE_PREFIX={prefix}".format(prefix=table.game_table_link),
|
||||
"FOUNDRY_TELEMETRY=FALSE",
|
||||
"FOUNDRY_LICENSE_KEY={key_value}".format(key_value=key.key),
|
||||
]
|
||||
|
||||
ports = {"30000": str(30000 + table.game_table_id)}
|
||||
|
||||
container = client.containers.run(
|
||||
image=image,
|
||||
labels=labels,
|
||||
volumes=volumes,
|
||||
environment=environment,
|
||||
ports=ports,
|
||||
detach=True,
|
||||
network=networkName
|
||||
)
|
||||
image = "felddy/foundryvtt:{version}".format(version=table.version)
|
||||
labels = build_container_routing_labels(table.game_table_link, False)
|
||||
|
||||
if data_volume:
|
||||
|
||||
os.makedirs("/data/{prefix}".format(prefix=table.game_table_link), exist_ok=True)
|
||||
|
||||
mounts = [
|
||||
docker.types.Mount(
|
||||
target="/data",
|
||||
source=data_volume,
|
||||
type="volume",
|
||||
subpath=table.game_table_link),
|
||||
docker.types.Mount(
|
||||
target="/data/container_cache",
|
||||
source=data_volume,
|
||||
type="volume",
|
||||
subpath="container_cache")
|
||||
]
|
||||
|
||||
container = client.containers.run(
|
||||
image=image,
|
||||
labels=labels,
|
||||
mounts=mounts,
|
||||
environment=environment,
|
||||
ports=ports,
|
||||
detach=True,
|
||||
network=networkName
|
||||
)
|
||||
|
||||
else:
|
||||
volumes = {
|
||||
"{data_bind}/{prefix}".format(
|
||||
data_bind=os.environ.get("FOUNDRY_DATA_BIND"),
|
||||
prefix=table.game_table_link,
|
||||
): {"bind": "/data", "mode": "rw"},
|
||||
"{data_bind}/container_cache".format(
|
||||
data_bind=os.environ.get("FOUNDRY_DATA_BIND")
|
||||
): {"bind": "/data/container_cache", "mode": "rw"},
|
||||
}
|
||||
|
||||
container = client.containers.run(
|
||||
image=image,
|
||||
labels=labels,
|
||||
volumes=volumes,
|
||||
environment=environment,
|
||||
ports=ports,
|
||||
detach=True,
|
||||
network=networkName
|
||||
)
|
||||
|
||||
return container.id
|
||||
|
||||
Reference in New Issue
Block a user