Welcome to the Mentorpunten repository. This repository includes the application that can be used to set up an online scavenger hunt. The application can be used to create Tournaments and Teams of Users for these Tournaments. Challenges can be created for each Tournament. The Challenges can be solved by the Teams by uploading a photo after which an administrator needs to approve (or decline) a Submission for a Challenge. If a Submission is approved, the Challenge is closed for that Team and points are awarded.
This project is built using both Django (for the backend) and VueJS (for the frontend). Both need to be set up (and connected) for development to work.
- First install at least Python 3.11 on your system.
- If
pip3
is not installed on your system, executeapt install python3-pip
to install it. - Also make sure
python3-dev
is installed on your system, executeapt install python3-dev
. - Install Poetry by following the steps on
their website. Make sure
poetry
is added toPATH
before continuing. - Clone this repository.
- Go to the
backend
directory. - Run
poetry install
to install the backend dependencies. - Run
poetry shell
to start a shell with the dependencies loaded. This command needs to be run every time you open a new shell and want to run the development server. - Go to the
website
directory. - Run
./manage.py migrate
to initialize the database and load all migrations. - Run
./manage.py createsuperuser
to create an administrator user. - Run
./manage.py runserver
to start the development server locally.
Now your backend server is setup and running on localhost:8000
. The administrator interface can be accessed by going
to localhost:8000/admin
.
- Install at least version 17 of NodeJS.
- Clonse this repository (or if you have done that in the previous steps, skip this step).
- Go to the
frontend
directory. - Use
npm install
to install the required packages. - Use
npm run dev
to run the development server.
Now that both the frontend and the backend server are up and running, we need to supply the frontend with credentials such that it can connect to the backend service.
- Log in on the administrator dashboard of the backend by going to
localhost:8000/admin
and logging in with your administrator account. - Under
Django OAuth Toolkit
, add anApplication
. - Provide the following settings:
- Redirect uris: http://localhost:5173/auth/callback
- Client type: Public
- Authorization grant type: Implicit
- Name: VueJS Frontend
- Skip Authorization: True
- Before saving the application, make sure to copy over the Client ID and Client Secret to some other location.
- Now save the application.
- Create a
.env
file in thefrontend
folder of the repository. The.env
file should have the following content:
VITE_API_BASE_URI=http://localhost:8000
VITE_API_AUTHORIZATION_ENDPOINT=/oauth/authorize/
VITE_API_ACCESS_TOKEN_ENDPOINT=/oauth/token/
VITE_API_OAUTH_CLIENT_ID=[Client ID you copied over]
VITE_API_OAUTH_CLIENT_SECRET=[Client Secret you copied over]
VITE_API_OAUTH_REDIRECT_URI=http://localhost:5173/auth/callback
VITE_API_LOGOUT_URL=/users/logout
VITE_DEBUG=true
- Reload the development server (
npm run dev
) and you are good to go!
This project can be deployed by using Docker. For deployment you can follow the following steps. These steps assume that you have a working server that runs Ubuntu which faces the Internet and a domain name pointing to the IP address of the server.
- First install Docker by following the steps on their website.
- Make sure to also install the Rootless version of Docker.
- Run
loginctl enable-linger ubuntu
to enable the background services for theubuntu
user (such that the container do not stop when you log out of the server). - Run
sudo nano /etc/sysctl.conf
and add the following line:net.ipv4.ip_unprivileged_port_start=80
. This enables privileged ports for theubuntu
user. - Now copy all the contents inside the
deployment
directory of this repository to a different location. - In the newly copied over
deployment
directory, create the following directory structure:
data
| - backend
| | - log
|
| - database
| | - data
|
| - shared
| | - static
| | - media
|
| - reverse-proxy
| | - conf.d
- Also create a
repository
folder in thedeployment
directory. Clone this repository inside therepository
folder (so the repository should be inrepository/mentorpunten
). - Create an OAuth application on the Thalia website. The OAuth application should have the following settings:
- Redirect uris: https://[Your server hostname]/thalia/callback
- Client type: Confidential
- Authorization grant type: Authorization code
- Name: Mentorpunten
- Skip Authorization: False
- Make sure to copy over the Client ID and Client Secret before saving the application. When you are done, save the application.
- Now copy over
docker-compose.yml.example
todocker-compose.yml
. Fill the following environment variables:
- Postgres Password: Create a random password.
- Django Secret key: Create a random secret key.
- Mentorpunten hostname: The domain pointing to the server running the deployment.
- Thalia OAuth Client ID: The Client ID for the Thalia OAuth application from the previous steps.
- Thalia OAuth Client Secret: The Client Secret for the Thalia OAuth application from the previous steps.
- Client ID from mentorpunten Django host: Leave empty for now.
- Client Secret from mentorpunten Django host: Leave empty for now.
- Run
docker compose build
to build both the containers. - Run
docker compose pull
to pull thenginx
andpostgres
container. - Run
docker compose up -d
to start the Docker containers. - Run
docker exec -it mentorpunten-backend /bin/bash
to start a shell in the backend container. - Go to the
website
directory inside the container by runningcd website
. - Run
./manage.py collectstatic
and./manage.py createsuperuser
to collect static files and create the first administrator user. Exit the shell by runningexit
. - Now head on over to the Django admin on your domain. You should be able to log in to the
admin by using
http://[Your domain]/admin-login
and the login credentials of the previous step. - Once again create an OAuth application with the following settings:
- Redirect uris: http://[Your server hostname]/auth/callback
- Client type: Public
- Authorization grant type: Implicit
- Name: VueJS Frontend
- Skip Authorization: True
- Before saving, copy over the Client ID and Client Secret. Now save the OAuth application.
- Run
docker compose down
to stop the containers from running. - Edit the
docker-compose.yml
file and enter the following variables:
- Client ID from mentorpunten Django host: The Client ID we got previously.
- Client Secret from mentorpunten Django host: The Client Secret we got previously.
- Run
docker compose up -d
to start the containers again, the website should now be in working condition. - It might be nice to also enable SSL and HTTPS. You can do this by adding a
certbot
container to thedocker-compose.yml
file and enabling port 443 on thereverse-proxy
container. Also make sure to edit the nginx config indata/reverse-proxy/conf.d
.
This section will explain some of the development steps that you have to take or were taken during development of the application.
Normally, environment variables are included during build and can not be changed afterwards. This is a problem when
building a docker container which can be applied to different scenarios (e.g. with different API servers). Because of
this fact, environment variables can be either included during build with a .env
file in the root directory or with
docker environment variables. Using docker environment variables will overwrite the environment variables included
during build.
Environment variables that are available and should be overwritable by docker environment variables later should be
included in the docker.blueprint.env
file. Note that this file must use '
for indicating strings and the format
is as follows:
'[NAME_OF_VARIABLE_IN_VUE]': '${NAME_OF_ENV_VARIABLE}'
Before starting the nginx
process, the docker environment variables will be set under the window.__env__
variable
in the index.html
file.
To use environment variables that can be set during runtime (with docker environment variables), add the variable to
the docker.blueprint.env
file as explained above. Then use the getEnvVar
function in
src/common/general.service.ts
for getting the value of an environment variable. This function will first check
whether it is set in the window.__env__
variable and will then look if it is an environment variable.