Skip to content
Permalink
Browse files
Add: deployment of TURN server
  • Loading branch information
TrueBrain committed Jul 19, 2021
1 parent 5409eba commit 07cbddb8dd87f53b129b241474503a3025358b17
Showing with 78 additions and 0 deletions.
  1. +10 −0 app.py
  2. +68 −0 openttd/stack/application/game_coordinator.py
10 app.py
@@ -29,6 +29,7 @@
from openttd.stack.application.game_coordinator import (
GameCoordinatorStack,
StunServerStack,
TurnServerStack,
)
from openttd.stack.application.master_server import (
MasterServerStack,
@@ -258,6 +259,15 @@
env=env,
)

turn_server_policy = PolicyStack(app, f"{prefix}TurnServer-Policy", env=env).policy
TurnServerStack(app, f"{prefix}TurnServer",
deployment=deployment,
policy=turn_server_policy,
cluster=ecs.cluster,
redis_url=redis.redis.attr_redis_endpoint_address,
env=env,
)

RedirectStack(app, f"{prefix}Redirect",
deployment=deployment,
env=env,
@@ -13,6 +13,7 @@
from openttd.construct.policy import Policy
from openttd.enumeration import Deployment
from openttd.stack.common import (
dns,
nlb_self as nlb,
parameter_store,
)
@@ -148,3 +149,70 @@ def __init__(self, scope: Construct, id: str, *, deployment: Deployment, policy:

self.container.add_port(stun_port)
nlb.add_nlb(self, self.container.service, Port.tcp(stun_port), self.nlb_subdomain_name, "STUN Server")


class TurnServerStack(Stack):
application_name = "TurnServer"
subdomain_name = "server.turn"
nlb_subdomain_name = "turn"

def __init__(self, scope: Construct, id: str, *, deployment: Deployment, policy: Policy, cluster: ICluster, redis_url, **kwargs) -> None:
super().__init__(scope, id, **kwargs)

Tags.of(self).add("Application", self.application_name)
Tags.of(self).add("Deployment", deployment.value)

policy.add_stack(self)

if deployment == Deployment.PRODUCTION:
desired_count = 2
priority = 65
turn_port = 3974
database = 1
else:
desired_count = 1
priority = 165
turn_port = 4974
database = 2

sentry_dsn = parameter_store.add_secure_string(f"/TurnServer/{deployment.value}/SentryDSN").parameter

for index in range(1, desired_count + 1):
container = ECSHTTPSContainer(
self,
f"{self.application_name}-{index}",
subdomain_name=f"{self.subdomain_name}-{index}",
deployment=deployment,
policy=policy,
application_name=f"{self.application_name}-{index}",
image_name="ghcr.io/openttd/game-coordinator",
port=80,
memory_limit_mib=64,
desired_count=1,
cluster=cluster,
priority=priority + index,
command=[
"--app",
"turn",
"--bind",
"0.0.0.0",
"--turn-port",
str(turn_port - index),
"--db",
"redis",
"--redis-url",
"redis://" + redis_url + "/" + str(database),
"--proxy-protocol",
"--turn-address",
dns.subdomain_to_fqdn(f"{self.nlb_subdomain_name}-{index}") + f":{turn_port - index}",
],
environment={
"GAME_COORDINATOR_SENTRY_ENVIRONMENT": deployment.value.lower(),
},
secrets={
"GAME_COORDINATOR_SENTRY_DSN": Secret.from_ssm_parameter(sentry_dsn),
},
)

container.add_port(turn_port - index)
nlb.add_nlb(self, container.service, Port.tcp(turn_port - index), f"{self.nlb_subdomain_name}-{index}", f"TURN Server #{index}")

0 comments on commit 07cbddb

Please sign in to comment.