| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This repository contains the code for Imperial's Department of Computing's Coporate Partnership Programme (CPP) Connect platform. CPP Connect is a platform that allows students to connect with companies and find internships, placements and graduate roles.
The platform is built on:
The application allows students to sign-in using Microsoft Single Sign On, denying them permission if they are not in the Computing department. N.B. an intentional policy decision has been to deny access to EIE students.
Companies can sign-in using magic links sent to their email using SMTP.
Admins are set using the CPP_ALLOWED_ADMINS environment variable, which is a comma-separated list of email addresses. Note that if this is changed, the users in questions will need to log out and log back in again to see the changes.
If you haven’t already, read the React Quick Start tutorial so that you understand the key concepts of React, as well as the Next.js documentation to understand how Next.js works.
For ease of use, we recommend developing on Linux, macOS or Windows Subsystem for Linux (WSL).
Install Node.js from the Node.js website.
Install Docker from the Docker website. (note: if you're on WSL, install Docker Desktop for Windows instead of installing docker directly inside of linux)
Run this command to install all the necessary packages:
npm install
npm run db:generate # generate prisma clientTo get started, make a copy of .env.template as .env and fill it in as required (the comments give more info)
Note
For this, you will need to setup SSO with Microsoft Entra ID - steps below
Refer to this page for more info about what's going on under the hood.
Login to the Entra Admin Center.
In the Entra Admin Center, head to the App Registrations page ( Applications > App registrations in the sidebar). In the toolbar at the top, select “New registration”. (nowadays, an ASK ticket to ICT must be created because we no longer have the permission to create app registrations ourselves)
Fill in the name of your app and select your desired supported account types. If in doubt, select “Accounts in this organizational directory only”.
For the redirect URI, select the “Web” platform, and enter http://localhost:3000/api/auth/callback/microsoft-entra-id as the address.
Confirm the details and you will be redirected to your app’s Entra ID App Registration page which contains some IDs.
In the .env file, set:
From the app’s Entra ID App Registration, navigate to “Certificates & secrets”, then click on “New client secret”. Enter any description and set the expiration to x months (Note: this means you will have to generate a new client secret every x months). Click “Add”.
Copy the value from the secret into the MS_ENTRA_CLIENT_SECRET row in the .env file.
Ensure that NEXTAUTH_URL is set to the value "http://localhost:3000" in the .env file. Note "http" (not "https") is critical here, since this url is what the user will be redirected to after authentication with Entra ID. Since the development app can't have a TLS certificate, if the protocol is https, the user will be redirected to an invalid url after authenticating. Additionally, Entra ID will error since it is expecting a redirect url beginning with "http."
These variables are for Nodemailer and sending emails with magic links to company users.
Linking to the app registration from the previous step, follow this tutorial: https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/email/send-email-smtp/smtp-authentication. You will need to set up prerequisite resources on Azure (portal.azure.com), mentioned in the tutorial. You must have the role Owner in the subscription to do this. These resources include:
EMAIL_SERVER_HOST and EMAIL_SERVER_PORT from .env.template are correct as is, requiring no changes.
In the .env file, set:
The application expects certain directories to be present in UPLOAD_DIR (by default, UPLOAD_DIR is ./uploads).
In development, run these commands to create the required directories (assuming UPLOAD_DIR is ./uploads):
export UPLOAD_DIR=./uploads
mkdir $UPLOAD_DIR
mkdir $UPLOAD_DIR/banners $UPLOAD_DIR/cvs $UPLOAD_DIR/avatars $UPLOAD_DIR/logosWe've included a dev.docker-compose.yml files, which contains everything (including a database) you need to get started:
docker compose -f dev.docker-compose.yml up
docker exec $(docker ps -qf "name=cpp-connect-app" | head -n1) npm run db:migrate-dev
docker exec $(docker ps -qf "name=cpp-connect-app" | head -n1) npm run db:seedIf all goes well, the app should now be available at http://localhost:3000
npm run db:migrate-dev
npm run db:seed
npm run devRun npm run build to build the app for production.
You can also build a docker image:
docker build -t imperial/cpp-connect .The application will hot reload when you make changes to the code for everything except the database schema (prisma client).
If you make changes to the database schema, you will need to run npm run db:generate to regenerate the prisma client, and then restart the server for changes to take effect. Note that when generating migrations the client is generally regenerated for you.
To format all TypeScript source code files in the repo using prettier, run:
npm run formatTo lint all TypeScript source code files in the repo using eslint, run:
npm run lintThe application is setup to run commit linting on every commit. This is to ensure that all commits are in the correct format, and will also auto-format files for you. The commit message should be in the format, in lowercase:
<type>: <subject>
Where <type> is one of the following:
Email templates are stored in emails/. To see changes to email templates in the browser when you are working on them, run:
npm run dev:emailCaution
The below will delete all data in the database! Never run this in production!
Use npm run db:reset: this will clear the database, re-run the migrations and re-seed the database.
This is especially useful if you've changed the database seed data and need to re-seed the database - for the schema, you should use migrations instead.
Install Impaas as described here:
curl -fsSL "https://tsuru.io/get" | bash
echo "alias impaas='tsuru'" >> ~/.bashrc
source ~/.bashrcLogin to ImPaas:
impaas loginCreate a new team:
impaas team create <TEAM_NAME>Add members to the team as required:
impaas role-assign team-member <EMAIL_ADDRESS> <TEAM_NAME>Create a new app (make <APP_NAME> something suitable like cpp-connect):
impaas app create <APP_NAME> --team <TEAM_NAME>Note
See information about your app by running impaas app info -a <APP_NAME> to confirm that it was successfully created
CPP Connect allows file uploads, and these are by default saved to upload/. In production, you should use an impaas volume for persistent file storage. A volume must be mounted at a certain directory. To create a volume:
Note
You will likely want a higher capacity than 512MiB
impaas volume create <VOLUME_NAME> azurefile \
--team <TEAM_NAME> \
--opt capacity=512Mi \
--opt access-modes=ReadWriteMany \
--pool localNow bind your volume to the app, specifying the MOUNT_POINT_NAME (directory to store files - we recommend using uploads)
impaas volume bind <VOLUME_NAME> /<MOUNT_POINT_NAME> --app <APP_NAME>Finally, set the UPLOAD_DIR environment variable to the mount point:
impaas env set UPLOAD_DIR=/<MOUNT_POINT_NAME> --app <APP_NAME>Add a PostgreSQL database to the app using impaas.
Note
We'd put steps for this here, but we haven't tried this ourselves yet!
Follow the instructions in the development guide above to add SSO Authentication.
Add an additional redirectURI in the Azure portal with platform “Web” and address https://<APP_NAME>.impaas.uk/api/auth/callback/microsoft-entra-id.
Additionally, you might need to check https://authjs.dev/getting-started/deployment if you are having issues with our chosen auth library.
There are some environment variables that need to be set in order for the app to deploy properly (and function.)
Impaas manages environment variables through two commands.
To see what environment variables are currently set, run:
impaas env get -a cpp-connectTo set an environment variable for the cpp-connect app, run:
impaas env set -a cpp-connect VAR1=value1 VAR2=value2 ...Environment variables set in this way are automatically included in any container deployed under the cpp-connect app. N.B. all email-related services in production live in the cpp-prod resource group under the subscription DoC EdTech Lab Dev.
The following variables are required for the app to function properly:
To get the DATABASE_URL, run the following command:
impaas app run "echo postgres://\$PGUSER:\$PGPASSWORD@\$PGHOST:\$PGPORT/\$PGDATABASE" -a cpp-connectThen, with the output, run:
impaas env set -a cpp-connect DATABASE_URL={OUTPUT FROM PREVIOUS COMMAND}NEXTAUTH_URL should simply be "https://cpp-connect.impaas.uk/" or whatever the url of the deployed Impaas app is.
Note: variables such as $PGUSER, $PGPASSWORD, $TSURU_APPDIR, etc. are set by Impaas automatically (assuming the database has been set correctly in the previous steps)
Deploy the app on Impaas using:
impaas app deploy \
--app <APP_NAME> \
--dockerfile DockerfileIf you encounter a Request Entity Too Large error when deploying the app, ensure the .tsuruignore includes your development volumes directory (/<MOUNT_POINT_NAME>) as this should not be included in deployment.
To view logs for the deployed app, run the following:
Note
See logs for your deployed app: impaas app log -a <APP_NAME> -l 100 --follow
The repo has GitHub Actions setup. On push to main or any branch with a PR to main, the following happens:
On push to main, the built docker image is uploaded to the GitHub Container Registry under the name ghcr.io/imperial/cpp-connect
There are two secrets which need to be set manually. The first is the IMPAAS_DEPLOY_TOKEN, which allows the pipeline to authenticate with Impaas. This needs to be obtained from Impaas, but requires elevated permissions. If this needs to be set or changed, speak to someone who has these elevated permissions on Impaas.
The second is the DATABASE_URL, which allows the workflow to run migrations from the runner. This should be set to the exact same value as the DATABASE_URL Impaas environment variable.
| Back | FazBrowse Home | New Git URL |