Skip to content

Commit

Permalink
feat: set up basic educator mode deployment
Browse files Browse the repository at this point in the history
- set `SHARED_APP_MODE=educator` in `.env`
- set `DEPLOY_ENVIRONMENT=learn` in `config.mk`
  • Loading branch information
alee committed Oct 16, 2024
1 parent ff5812b commit a35dba8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions learn.yml
Original file line number Diff line number Diff line change
@@ -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'
3 changes: 2 additions & 1 deletion server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 17 additions & 2 deletions server/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -27,6 +27,7 @@ export interface AppSettings {
};
supportEmail: string;
isProduction: boolean;
isEducatorMode: boolean;
}

const dev: () => AppSettings = () => ({
Expand All @@ -45,6 +46,7 @@ const dev: () => AppSettings = () => ({
},
supportEmail: "[email protected]",
isProduction: false,
isEducatorMode: isEducatorMode(),
});

const staging: () => AppSettings = () => {
Expand All @@ -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 {
Expand Down

0 comments on commit a35dba8

Please sign in to comment.