From a35dba88522e760dd304010def5c1c935d2c1291 Mon Sep 17 00:00:00 2001 From: Allen Lee Date: Wed, 16 Oct 2024 15:24:04 -0700 Subject: [PATCH] feat: set up basic educator mode deployment - set `SHARED_APP_MODE=educator` in `.env` - set `DEPLOY_ENVIRONMENT=learn` in `config.mk` --- Makefile | 4 ++-- learn.yml | 12 ++++++++++++ server/src/index.ts | 3 ++- server/src/settings.ts | 19 +++++++++++++++++-- 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 learn.yml diff --git a/Makefile b/Makefile index 4ab1471b4..89a21813a 100644 --- a/Makefile +++ b/Makefile @@ -68,8 +68,8 @@ release-version: .env docker-compose.yml: base.yml $(DEPLOY_ENVIRONMENT).yml config.mk $(DB_DATA_PATH) $(DATA_DUMP_PATH) $(LOG_DATA_PATH) $(DYNAMIC_SETTINGS_PATH) secrets $(PGPASS_PATH) release-version case "$(DEPLOY_ENVIRONMENT)" in \ - dev|staging|prod) docker compose -f base.yml -f "$(DEPLOY_ENVIRONMENT).yml" config > docker-compose.yml;; \ - *) echo "invalid environment. must be either dev, staging or prod" 1>&2; exit 1;; \ + dev|staging|prod|learn) docker compose -f base.yml -f "$(DEPLOY_ENVIRONMENT).yml" config > docker-compose.yml;; \ + *) echo "invalid environment. must be either dev, staging, prod, or learn" 1>&2; exit 1;; \ esac .PHONY: build diff --git a/learn.yml b/learn.yml new file mode 100644 index 000000000..a024ff364 --- /dev/null +++ b/learn.yml @@ -0,0 +1,12 @@ +services: + redis: + volumes: + - ./docker/redis:/data + server: + build: + dockerfile: server/Dockerfile.prod + args: + NODE_ARG: production + image: port-of-mars/server:learn + ports: + - '8998:2567' diff --git a/server/src/index.ts b/server/src/index.ts index 316faa4d2..c52588ba1 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -221,9 +221,10 @@ async function createApp() { })(); logger.info( - "starting (%s) server: [release version: %s, settings.host %s]", + "starting (%s) server: [release version: %s, educator mode: %s, settings.host %s]", NODE_ENV, sharedSettings.RELEASE_VERSION, + settings.isEducatorMode, settings.host ); const port = Number(process.env.PORT || 2567); diff --git a/server/src/settings.ts b/server/src/settings.ts index f18babb2a..d6ca1c145 100644 --- a/server/src/settings.ts +++ b/server/src/settings.ts @@ -4,7 +4,7 @@ import { MailgunEmailer, } from "@port-of-mars/server/services/email/emailers"; import { LogService, DevLogging, Logging } from "@port-of-mars/server/services/logging"; -import { BASE_URL, SERVER_URL_HTTP } from "@port-of-mars/shared/settings"; +import { BASE_URL, SERVER_URL_HTTP, isEducatorMode } from "@port-of-mars/shared/settings"; import * as fs from "fs"; const readSecret = (filename: string): string => { @@ -27,6 +27,7 @@ export interface AppSettings { }; supportEmail: string; isProduction: boolean; + isEducatorMode: boolean; } const dev: () => AppSettings = () => ({ @@ -45,6 +46,7 @@ const dev: () => AppSettings = () => ({ }, supportEmail: "portmars@asu.edu", isProduction: false, + isEducatorMode: isEducatorMode(), }); const staging: () => AppSettings = () => { @@ -69,14 +71,27 @@ const prod: () => AppSettings = () => { }; }; +const learn: () => AppSettings = () => { + const prodSettings = prod(); + return { + ...prodSettings, + host: BASE_URL || "https://learn.portofmars.asu.edu", + serverHost: BASE_URL || "https://learn.portofmars.asu.edu", + isProduction: true, + }; +}; + function getSettings(): AppSettings { const env = process.env.NODE_ENV; if (["development", "test"].includes(env || "")) { return dev(); } else if (env === "staging") { return staging(); + } else if (isEducatorMode()) { + return learn(); + } else { + return prod(); } - return prod(); } export function getLogger(filename: string): LogService {