Skip to content

Commit

Permalink
Add AIMMO_DJANGO_BASE_URL to settings (#310)
Browse files Browse the repository at this point in the history
* Add AIMMO_DJANGO_BASE_URL to settings

* Merge branch 'master' into add_aimmo_base_url_new

* Merge branch 'master' into add_aimmo_base_url_new

* Remove game creator step
  • Loading branch information
faucomte97 authored Oct 16, 2023
1 parent 31ba10c commit bb175e7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 120 deletions.
64 changes: 2 additions & 62 deletions clusters_setup/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,67 +86,14 @@ def create_fleet_yaml(module_name, aimmo_version):
return content


def create_creator_yaml(module_name, aimmo_version):
"""
Loads an aimmo-game-creator yaml into a dictionary.
Replaces the GAME_API_URL environment variable with the correct url for the
deployment environment we are in
:param module_name: The name of the environment we're in (ie. staging, dev).
:param aimmo_version: The game version we want to deploy.
:return: python object containing yaml with modified values.
"""

def _replace_game_api_url(content):
game_api_url = (
"https://"
+ module_name
+ "-dot-decent-digit-629.appspot.com/kurono/api/games/"
)
env_variables = content["spec"]["template"]["spec"]["containers"][0]["env"]
game_api_url_index = env_variables.index(
{"name": "GAME_API_URL", "value": "REPLACE_ME"}
)
env_variables[game_api_url_index]["value"] = game_api_url

def _replace_image_version(content):
env_variables = content["spec"]["template"]["spec"]["containers"][0]["env"]
image_suffix_index = env_variables.index(
{"name": "IMAGE_SUFFIX", "value": "latest"}
)
env_variables[image_suffix_index]["value"] = aimmo_version

def _replace_image_tag(content):
content["spec"]["template"]["spec"]["containers"][0][
"image"
] = "ocadotechnology/aimmo-game-creator:{}".format(aimmo_version)

path = os.path.join(CURR_DIR, "rs_aimmo_game_creator.yaml")
with open(path) as yaml_file:
content = yaml.safe_load(yaml_file.read())
_replace_game_api_url(content)
_replace_image_version(content)
_replace_image_tag(content)
return content


def restart_pods(game_creator_yaml, ingress_yaml, fleet_yaml):
def restart_pods(ingress_yaml, fleet_yaml):
"""
Restarts the kubernetes replication controllers, pods, services and ingresses
in the 'default' namespace
:param game_creator_yaml: The dict to create the aimmo game creator rc
:param ingress_yaml: The dict to create the ingress
:param fleet_yaml: The dict to create the fleet
"""
for rs in apps_api_instance.list_namespaced_replica_set("default").items:
if rs.metadata.name == game_creator_yaml["metadata"]["name"]:
apps_api_instance.delete_namespaced_replica_set(
body=kubernetes.client.V1DeleteOptions(),
name=rs.metadata.name,
namespace="default",
)
for service in api_instance.list_namespaced_service("default").items:
if service.metadata.name.startswith("game-"):
api_instance.delete_namespaced_service(
Expand Down Expand Up @@ -193,10 +140,6 @@ def restart_pods(game_creator_yaml, ingress_yaml, fleet_yaml):

networking_api_instance.create_namespaced_ingress("default", ingress_yaml)

apps_api_instance.create_namespaced_replica_set(
body=game_creator_yaml, namespace="default"
)

custom_objects_api_instance.create_namespaced_custom_object(
group="agones.dev",
version="v1",
Expand Down Expand Up @@ -225,12 +168,9 @@ def main(module_name):
aimmo_version = get_aimmo_version()

ingress = create_ingress_yaml(module_name=module_name)
game_creator_rs = create_creator_yaml(
module_name=module_name, aimmo_version=aimmo_version
)
fleet = create_fleet_yaml(module_name=module_name, aimmo_version=aimmo_version)

restart_pods(game_creator_rs, ingress, fleet)
restart_pods(ingress, fleet)


if __name__ == "__main__":
Expand Down
34 changes: 0 additions & 34 deletions clusters_setup/rs_aimmo_game_creator.yaml

This file was deleted.

39 changes: 15 additions & 24 deletions django_site/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

import json
# Build paths inside the project like this: rel(rel_path)
import os
import json

from .permissions import is_cloud_scheduler

Expand All @@ -29,25 +29,18 @@
DOTMAILER_MAIN_ADDRESS_BOOK_URL = os.getenv("DOTMAILER_MAIN_ADDRESS_BOOK_URL", "")
DOTMAILER_TEACHER_ADDRESS_BOOK_URL = os.getenv("DOTMAILER_TEACHER_ADDRESS_BOOK_URL", "")
DOTMAILER_STUDENT_ADDRESS_BOOK_URL = os.getenv("DOTMAILER_STUDENT_ADDRESS_BOOK_URL", "")
DOTMAILER_NO_ACCOUNT_ADDRESS_BOOK_URL = os.getenv(
"DOTMAILER_NO_ACCOUNT_ADDRESS_BOOK_URL", ""
)
DOTMAILER_NO_ACCOUNT_ADDRESS_BOOK_URL = os.getenv("DOTMAILER_NO_ACCOUNT_ADDRESS_BOOK_URL", "")
DOTMAILER_GET_USER_BY_EMAIL_URL = os.getenv("DOTMAILER_GET_USER_BY_EMAIL_URL", "")
DOTMAILER_DELETE_USER_BY_ID_URL = os.getenv("DOTMAILER_DELETE_USER_BY_ID_URL", "")
DOTMAILER_PUT_CONSENT_DATA_URL = os.getenv("DOTMAILER_PUT_CONSENT_DATA_URL", "")
DOTMAILER_SEND_CAMPAIGN_URL = os.getenv("DOTMAILER_SEND_CAMPAIGN_URL", "")
DOTMAILER_THANKS_FOR_STAYING_CAMPAIGN_ID = os.getenv(
"DOTMAILER_THANKS_FOR_STAYING_CAMPAIGN_ID", ""
)
DOTMAILER_THANKS_FOR_STAYING_CAMPAIGN_ID = os.getenv("DOTMAILER_THANKS_FOR_STAYING_CAMPAIGN_ID", "")
DOTMAILER_USER = os.getenv("DOTMAILER_USER", "")
DOTMAILER_PASSWORD = os.getenv("DOTMAILER_PASSWORD", "")
DOTMAILER_DEFAULT_PREFERENCES = json.loads(
os.getenv("DOTMAILER_DEFAULT_PREFERENCES", "[]") or "[]"
)
DOTMAILER_DEFAULT_PREFERENCES = json.loads(os.getenv("DOTMAILER_DEFAULT_PREFERENCES", "[]") or "[]")

REACT_APP_KURONO_BADGES_URL = os.getenv(
"REACT_APP_KURONO_BADGES_URL",
"https://development-kurono-badges-dot-decent-digit-629.appspot.com"
"REACT_APP_KURONO_BADGES_URL", "https://development-kurono-badges-dot-decent-digit-629.appspot.com"
)

SECURE_HSTS_SECONDS = 31536000 # One year
Expand Down Expand Up @@ -223,6 +216,16 @@
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True

AIMMO_DJANGO_BASE_URL = f"https://{os.getenv('GAE_SERVICE')}-dot-decent-digit-629.appspot.com"

AIMMO_GAME_SERVER_URL_FUNCTION = lambda game: (
f"{os.getenv('GAE_SERVICE')}-aimmo.codeforlife.education",
f"/game-{game}/socket.io",
)

AIMMO_GAME_SERVER_PORT_FUNCTION = lambda game: 0
AIMMO_GAME_SERVER_SSL_FLAG = True

EMAIL_ADDRESS = "[email protected]"

LOCALE_PATHS = ("conf/locale",)
Expand Down Expand Up @@ -261,18 +264,6 @@

CMS_TEMPLATES = (("portal/base.html", "Template One"),)


AIMMO_GAME_SERVER_URL_FUNCTION = lambda game: (
f"{os.getenv('GAE_SERVICE')}-aimmo.codeforlife.education",
f"/game-{game}/socket.io",
)


AIMMO_GAME_SERVER_PORT_FUNCTION = lambda game: 0


AIMMO_GAME_SERVER_SSL_FLAG = True

IS_CLOUD_SCHEDULER_FUNCTION = is_cloud_scheduler
CLOUD_STORAGE_PREFIX = "https://storage.googleapis.com/codeforlife-assets/"

Expand Down

0 comments on commit bb175e7

Please sign in to comment.