set up some initial work around starting a foundry container
This commit is contained in:
@@ -1,31 +1,66 @@
|
||||
import docker
|
||||
|
||||
|
||||
def build_container_routing_labels(prefix, strip_prefix=True):
|
||||
router_key = "traefik.http.routers.{prefix}.rule".format(prefix=prefix)
|
||||
middleware_key = (
|
||||
"traefik.http.middlewares.{prefix}-stripprefix.stripprefix.prefixes".format(
|
||||
prefix=prefix
|
||||
)
|
||||
)
|
||||
middleware_router_key = "traefik.http.routers.{prefix}.middlewares".format(
|
||||
prefix=prefix
|
||||
)
|
||||
|
||||
labels = {}
|
||||
labels[router_key] = "Host(`localhost`) && PathPrefix(`/{prefix}`)".format(
|
||||
prefix=prefix
|
||||
)
|
||||
if strip_prefix:
|
||||
labels[middleware_key] = "/{prefix}".format(prefix=prefix)
|
||||
labels[middleware_router_key] = "{prefix}-stripprefix".format(
|
||||
prefix=prefix
|
||||
)
|
||||
|
||||
return labels
|
||||
|
||||
|
||||
def start_container(table_name, prefix):
|
||||
client = docker.from_env()
|
||||
|
||||
router_key = "traefik.http.routers.{table_name}.rule".format(table_name=table_name)
|
||||
middleware_key = (
|
||||
"traefik.http.middlewares.{table_name}-stripprefix.stripprefix.prefixes".format(
|
||||
table_name=table_name
|
||||
)
|
||||
)
|
||||
middleware_router_key = "traefik.http.routers.{table_name}.middlewares".format(
|
||||
table_name=table_name
|
||||
)
|
||||
|
||||
labels = {}
|
||||
labels[router_key] = "Host(`localhost`) && PathPrefix(`/{prefix}`)".format(prefix=prefix)
|
||||
labels[middleware_key] = "/{prefix}".format(prefix=prefix)
|
||||
labels[middleware_router_key] = "{table_name}-stripprefix".format(table_name=table_name)
|
||||
labels = build_container_labels(prefix)
|
||||
|
||||
container = client.containers.run(
|
||||
image="crccheck/hello-world", detach=True, labels=labels, ports={8000:8000}
|
||||
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()
|
||||
|
||||
|
||||
def start_foundry_container(table_name, prefix, version=12):
|
||||
client = docker.from_env()
|
||||
|
||||
image = "felddy/foundryvtt:{version}".format(version=version)
|
||||
labels = build_container_routing_labels(prefix, False)
|
||||
volumes = {
|
||||
"/home/cow/Projects/dockertesting/server_data_mount/{prefix}".format(
|
||||
prefix=prefix
|
||||
): {"bind": "/data", "mode": "rw"},
|
||||
"/home/cow/Projects/dockertesting/server_data_mount/foundry_cache": {
|
||||
"bind": "/data/container_cache"
|
||||
},
|
||||
}
|
||||
environment = [
|
||||
"FOUNDRY_ROUTE_PREFIX={prefix}".format(prefix=prefix)
|
||||
]
|
||||
|
||||
container = client.containers.run(
|
||||
image=image, labels=labels, volumes=volumes, environment=environment, ports={"30000":"30000"}, detach=True
|
||||
)
|
||||
|
||||
return container.id
|
||||
|
||||
Reference in New Issue
Block a user