Skip to content
Permalink
Browse files
Add: deployment of STUN server
  • Loading branch information
TrueBrain committed Jul 16, 2021
1 parent 2c97873 commit 5409eba103e8276c794788baf80e5ae683705cd1
Showing with 79 additions and 1 deletion.
  1. +13 −1 app.py
  2. +66 −0 openttd/stack/application/game_coordinator.py
14 app.py
@@ -26,7 +26,10 @@
from openttd.stack.application.eints import EintsStack
from openttd.stack.application.flyspray import FlysprayStack
from openttd.stack.application.installer import InstallerStack
from openttd.stack.application.game_coordinator import GameCoordinatorStack
from openttd.stack.application.game_coordinator import (
GameCoordinatorStack,
StunServerStack,
)
from openttd.stack.application.master_server import (
MasterServerStack,
MasterServerApiStack,
@@ -246,6 +249,15 @@
env=env,
)

stun_server_policy = PolicyStack(app, f"{prefix}StunServer-Policy", env=env).policy
StunServerStack(app, f"{prefix}StunServer",
deployment=deployment,
policy=stun_server_policy,
cluster=ecs.cluster,
redis_url=redis.redis.attr_redis_endpoint_address,
env=env,
)

RedirectStack(app, f"{prefix}Redirect",
deployment=deployment,
env=env,
@@ -59,6 +59,8 @@ def __init__(self, scope: Construct, id: str, *, deployment: Deployment, policy:
cluster=cluster,
priority=priority,
command=[
"--app",
"coordinator",
"--bind",
"0.0.0.0",
"--coordinator-port",
@@ -82,3 +84,67 @@ def __init__(self, scope: Construct, id: str, *, deployment: Deployment, policy:

self.container.add_port(coordinator_port)
nlb.add_nlb(self, self.container.service, Port.tcp(coordinator_port), self.nlb_subdomain_name, "Game Coordinator")


class StunServerStack(Stack):
application_name = "StunServer"
subdomain_name = "server.stun"
nlb_subdomain_name = "stun"

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 = 64
stun_port = 3975
database = 1
else:
desired_count = 1
priority = 164
stun_port = 4975
database = 2

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

self.container = ECSHTTPSContainer(
self,
self.application_name,
subdomain_name=self.subdomain_name,
deployment=deployment,
policy=policy,
application_name=self.application_name,
image_name="ghcr.io/openttd/game-coordinator",
port=80,
memory_limit_mib=64,
desired_count=desired_count,
cluster=cluster,
priority=priority,
command=[
"--app",
"stun",
"--bind",
"0.0.0.0",
"--stun-port",
str(stun_port),
"--db",
"redis",
"--redis-url",
"redis://" + redis_url + "/" + str(database),
"--proxy-protocol",
],
environment={
"GAME_COORDINATOR_SENTRY_ENVIRONMENT": deployment.value.lower(),
},
secrets={
"GAME_COORDINATOR_SENTRY_DSN": Secret.from_ssm_parameter(sentry_dsn),
},
)

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

0 comments on commit 5409eba

Please sign in to comment.