Multipurpose Online Coding Assessment Platform (MOCAP) is a web-based platform that aims to eliminate the need for students to individually configure their coding environments when completing course coding assignments.
To complete course coding assignments, students need to set up a coding environment on their local machines. However, issues might arise when setting up the environment due to discrepancies in libraries, dependencies, operating systems, and hardware. These differences can lead to problems when running assignments in markers' environments, resulting in disputes between students and teachers.
To address this problem, MOCAP provides a solution by hosting a web platform that offers a customizable coding environment using Docker. Docker ensures environment consistency and replicability, thereby eliminating the problems arising from discrepancies in libraries, dependencies, and operating systems.
mocap-keycloak is the Identity and access management (IAM) system of our MOCAP system. It is written in Keycloak, Typescript, and React.
Warning
The mocap-dev-realm.json
is for development / demonstration only. DO NOT use this configuration in production.
[!INFO]
If you are using Windows, you need to use Docker for WSL2.
Our server cannot build the theme jar
file when building the image because of insufficient memory. Therefore, we need to build the jar
file in local and pass it into the docker image.
-
Install maven locally.
sudo wget https://archive.apache.org//dist/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz -P /tmp sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt sudo update-alternatives --install /usr/bin/mvn mvn /opt/apache-maven-3.9.6/bin/mvn 363 sudo update-alternatives --config mvn
-
Install packages.
npm install
-
Build the theme
jar
.npm run build && npm run build-theme-jar
-
Build the image.
docker-compose build
-
Create a docker network
mocap
if you haven't already.docker network create mocap
-
Create a copy of
.env.production
and rename it as.env.production.local
. -
Fill in all required environment variables.
-
Start the container.
docker-compose up
-
Access the keycloak admin console with URL =
KEYCLOAK_HOST_URL
. Click Adminstration Console. The username and password areKEYCLOAK_ADMIN
andKEYCLOAK_ADMIN_PASSWORD
respectively. -
Choose
mocap-dev
realm from the dropdown in the navigation bar on the left. -
You can now configure the realm!
-
Build the image.
TARGET=main docker-compose build
-
Create a docker network
mocap
if you haven't already.docker network create mocap
-
Create a copy of
.env.production
and rename it as.env.production.local
. -
Fill in all required environment variables.
-
Start the container.
docker-compose up
-
Access the keycloak admin console with URL =
KEYCLOAK_HOST_URL
. Click Adminstration Console. The username and password areKEYCLOAK_ADMIN
andKEYCLOAK_ADMIN_PASSWORD
respectively. -
Choose
mocap-dev
realm from the dropdown in the navigation bar on the left. -
You can now configure the realm!
There are some default users that has already been created:
admin
,lecturer
,tutor
, andstudent
. They have a role equals to their name.eddie
,harry
,john
, andedmond
. They have no role.
Note
Their passwords are equal to their username.
- Go to Users -> Users list.
- Click the target user.
- Click Role mapping.
- Click Assign role.
- Click
admin
,lecturer
,tutor
, or/andstudent
.
-
Open terminal in the docker container. Type:
/opt/keycloak/bin/kc.sh export --dir /opt/keycloak/data/import --realm mocap-dev --users realm_file
Now the realm data is in /opt/keycloak/data/import/mocap-dev-realm.json
-
To copy the file from the container to local machine, type the following on your local machine:
docker cp mocap-keycloak:/opt/keycloak/data/import/mocap-dev-realm.json <local_destination>
-
Copy the file to
./realms
. -
Run
cd src/scripts && py removeRealmSensitiveData.py
to replace all sensitive data with environment variables.
Warning
When importing data (in Dockrerfile
), some data would be replaced by the environment variables. For example, smtpServer.password
uses SMTP_PASSWORD
.
Therefore, when you export the realm data, you will export secrets. DO NOT PUSH THOSE SECRETS TO THE REPOSITORY. Please replace those secrets with the enironment
variable with the script above.
Note
You can check which values are replaced in ./realms/sensitive-data-map.json
.
To build the custom theme, maven is needed.
Warning
Do not download maven with apt package manager because it does not work for some reason.
-
Install maven locally.
sudo wget https://archive.apache.org//dist/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz -P /tmp sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt sudo update-alternatives --install /usr/bin/mvn mvn /opt/apache-maven-3.9.6/bin/mvn 363 sudo update-alternatives --config mvn
-
Install all dependencies.
npm install
-
Build the React app.
npm run build
-
Creating a
.jar
file for keycloak theme using keycloakify.npm run build-theme-jar
Currently not all the pages has custom theme. When developing the page, you need to know its structure. You can find the structure of the page here or here.
-
Install all dependencies.
npm install
-
Clone all keycloak resources. You would see a folder
keycloak-resources
inpublic
folder.npm run clone-resources
-
Start the React app.
npm run start
-
Change the
mockPageId
insrc/keycloak-theme/login/kcContext.ts
based on which page you want to edit. For example, if you want to edit the login page, change themockPageId
tologin.ftl
.export const { kcContext } = getKcContext({ // Uncomment to test the login page for development. mockPageId: "login.ftl", });
-
Please fork this repository and create a pull request if you want to contribute.
-
Please follow conventional commits when you commit!
-
If you are using VSCode, you can install ESLint, Prettier, Prettier ESLint, Tailwind CSS IntelliSense extensions.
-
For ESLint, you can add these to your
settings.json
in VSCode:"[javascript]": { "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.codeActionsOnSave": { "source.fixAll.eslint": true } }, "[typescript]": { "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.codeActionsOnSave": { "source.fixAll.eslint": true } }, "[typescriptreact]": { "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.codeActionsOnSave": { "source.fixAll.eslint": true } }, "[json]": { "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.codeActionsOnSave": { "source.fixAll.eslint": true } }, "eslint.validate": ["javascript", "typescript", "typescriptreact"]
-
For Tailwind CSS IntelliSense, please add these to your
settings.json
in VSCode:"files.associations": { "*.css": "tailwindcss" }, "editor.quickSuggestions": { "strings": "on" }
-
You can run
npm run format
to format your code.