-
Notifications
You must be signed in to change notification settings - Fork 0
Deployment guide
To begin, create a copy of .env.template called .env located at the root level of the project. Follow the instructions from the template and copy the values of the environment variables from the impaas app where needed.
For the DATABASE_URL environment variable, create a local PostgreSQL database and use its connection string.
- Set up environment variables as described before
-
npm install: install necessary packages -
npx prisma migrate reset: apply migrations and populate the database with seed data. To leave the database empty, use theskip-seedoption -
npm run dev: run the server - (optional, in another terminal)
npx prisma studio: nice, interactive web view of the database
- Visit the Microsoft Entra portal and move to tab Applications -> App registrations from the sidebar.
- Register a new app with New registration from the toolbar. Choose an application name and set the account types to Accounts in this organizational directory only. Set up 2 redirect URIs with type Web and the URLs
http://localhost:3000/api/auth/callback/microsoft-entra-idandhttps://ug-admissions.impaas.uk/api/auth/callback/microsoft-entra-id. - Confirm the details. Copy Application (client) ID into the environment variable
AUTH_MICROSOFT_ENTRA_ID_ID. Copy the value of Directory (tenant) ID intohttps://login.microsoftonline.com/<tenant_id>/v2.0for environment variableAUTH_MICROSOFT_ENTRA_ID_ISSUER. - Navigate to Certificates & secrets and click New client secret on the toolbar. Enter any description and set the expiration to 6 months (NB: a new client secret must therefore be generated in 6 months). The Add button will then generate a secret which is the value for environment variable
AUTH_MICROSOFT_ENTRA_ID_SECRET. - The last authentication environment variable,
AUTH_SECRET, is generated by runningnpx auth.
The pipeline can be found here. The steps are as follows: type checking, style checking, linting, building + pushing image, deploying to impaas and applying migrations.
There are 2 repository actions secrets which must be set manually on GitHub.
-
DATABASE_URLallows migrations to be executed by a GitHub runner. It should have the exact same value as the identically namedDATABASE_URLenvironment variable. -
TSURU_TOKENis for the pipeline to authenticate with impaas / tsuru. This must be obtained from impaas by someone with elevated permissions on impaas itself.
Note that impaas is an alias for tsuru so either can be used
- Install impaas as described here
curl -fsSL "https://tsuru.io/get" | bash
echo "alias impaas='tsuru'" >> ~/.bashrc
source ~/.bashrc
- Login:
impaas login - Create a new team:
impaas team create <team_name> - Add any members to the team as required:
impaas role-assign team-member <email_address> <team_name> - Create a new app within that team:
impaas app create <app_name> --team <team_name> - Create a token for the team with
impaas token create --id <token_name> --team <team_name> --description "CI token" - Assign the token the team-deployer role to give it sufficient permissions for deployment:
impaas role-assign team-deployer <token_name>
If using an impaas database, follow these additional instructions
- Create Postgres service:
impaas service-instance-add postgres <db_name> - Bind Postgres service to app:
impaas service-instance-bind postgres <db_name> -a <app_name>
- View app information:
impaas app info -a <app_name> - View logs of the app running:
tsuru app log -a <app_name>
When using impaas as the means of deploying the application, most environment variables found in .env will need to be manually injected.
The command tsuru env get -a <app_name> displays all the set environment variables in the application <app_name>. The postgres and tsuru environment variables are automatically set and managed.
Any missing environment variables should be set with the command tsuru env set <ENV_VAR_NAME>=<env_var_value> -a <app_name>.
The variables which will need to be set are AUTH_MICROSOFT_ENTRA_ID_ID, AUTH_MICROSOFT_ENTRA_ID_ISSUER, AUTH_MICROSOFT_ENTRA_ID_SECRET, AUTH_SECRET and NEXT_PUBLIC_UGA_ADMINS. The last environment variable is prefixed with NEXT_PUBLIC_ because it must be available to the browser.