- App resume and guide
- Requirements
- To clone & setup the project
- Deployment (Windows)
- To contribute to the project
This is the backend of the Cyber-Prepa app. It's a Django app that uses Django Rest Framework and Django Channels to provide a REST API and a WebSocket API.
Please look at the APP_GUIDE.md file for more information about how the app works.
- Python 3
- django
- python-dotenv
- djangorestframework
- django-cors-headers
- channels
- channels-redis
- daphne
- Nginx ❗
- Redis server
‼️
- Ubuntu 20.04
git clone https://github.com/Dev-Society-CCM/Cyber-Prepa.git
cd Cyber-Prepa
- Linux bash
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
- Linux bash
# This generates a secret key and prints it to the console
python3 -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
Then add the generated key to the environment (.env file) variables as SECRET_KEY
Example:
SECRET_KEY=2hb40lab4)zqt0zwt=m_q^q&m11ku)9ky0)-6hkh3@4uuwzm
# To automatically create the .env file and add the generated key to it
echo "SECRET_KEY=$(python3 -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())')" > .env
Also in case you want to debug the app, set the DEBUG environment variable to True.
DEBUG=True
And in case you want to use the react frontend, add the following environment variable to the .env file. Or if you want to use the frontend on a different server, add the server's address instead localhost.
CORS_ALLOWED_ORIGINS=http://localhost
ALLOWED_HOSTS=localhost
❗ Don't push the .env file to the repository, it's already ignored in the .gitignore file & it contains sensitive data ! That's why is called SECRET_KEY :)
- Linux bash
python3 manage.py migrate
python3 manage.py runserver
- Linux bash
# Install Redis server
sudo apt install redis-server
# Enable and start the Redis service
sudo systemctl enable redis-server
sudo systemctl start redis-server
- ❗ Only if redis server port is changed ❗
# The above command should have started the redis server at the default port 6379
# If you want to start it at a different port, use the following command
redis-server --port 6380
docker run --rm -p 6379:6379 redis:7
- Linux bash
# Install nginx
sudo apt install nginx
# Create a new configuration file > This will create a new file called
# myapp.conf in /etc/nginx/sites-available thourgh a curl request to a
# gist file located at the url below.
sudo curl -L https://gist.githubusercontent.com/Djmr5/19e2c8dd2480992500d12fd54a10913c/raw/1ee7a905d4be9816ae3d84a90709a153f8ee8ba8/myapp.conf -o /etc/nginx/sites-available/myapp.conf
# Create a symbolic link to sites-enabled
sudo ln -s /etc/nginx/sites-available/myapp.conf /etc/nginx/sites-enabled/
# Remove default configuration
sudo rm /etc/nginx/sites-enabled/default
sudo rm /etc/nginx/sites-available/default
# Test nginx configuration & restart nginx to apply changes
sudo nginx -t
sudo service nginx restart
- More instructions are missing but you can look on how to create a docker container for nginx and use the myapp.conf file as a configuration file.
git clone
cd Cyber-Prepa
python -m venv .venv
.venv\Scripts\activate.ps1
pip install -r requirements.txt
In the settings.py file, set DEBUG to False.
DEBUG = False
Then create a .env file and add the environment variables:
# This generates a secret key and prints it to the console
python -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"
The .env file should look like this:
SECRET_KEY=2hb40lab4)zqt0zwt=m_q^q&m11ku)9*ky0)-6hkh3@4*uuwzm
CORS_ALLOWED_ORIGINS=http://localhost,http://192.168.0.1
ALLOWED_HOSTS=localhost,192.168.0.1
python manage.py migrate
python manage.py createsuperuser
daphne -b 0.0.0.0 -p 8001 main.asgi:application
docker run --rm -p 6379:6379 redis:7
- Search for "Turn Windows features on or off" in the start menu and open it.
- Scroll down and find "Internet Information Services" and check the box.
- Click OK and wait for the installation to complete.
Add a virtual directory to the media folder in the IIS server. Right-click on the default website and select "Add Virtual Directory". Set the alias to "media" and the physical path to the media folder in the project.
It should look like this:
Alias: media
Physical path: C:\path\to\project\media
You can generate a self-signed certificate using openssl. I recommend to use the Git Bash terminal, as git installation comes with an openssl binary. Locate the directory where you want to generate the certificate and run the following command at that directory in the Git Bash terminal.
openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem
Then run the server with SSL
daphne -e ssl:8001:privateKey=key.pem:certKey=certificate.pem main.asgi:application
Change <branch-name> to the name of the branch you want to create.
git checkout -b <branch-name>
Please follow the following naming convention for your branches so the github actions can work properly and label the pull requests accordingly.
feature/user-authentication
or
feat/chat-groups
bug/fix-header-styling
or
hotfix/security-patch
or
fix/fix-login-redirect
docs/update-readme
or documentation/add-documentation
or doc/add-new-guide
style/update-styles
or frontend/add-styles
or ui/add-new-component
or ux/add-new-animation
enhancement/add-new-feature
or enhance/improve-feature
If already working on a remote branch, you can pull the latest changes from it and create your local branch.
git checkout -b <branch-name> origin/<branch-name>
Add your changes to the staging area, commit them with a meaningful message (try to relate your commits to an issue) and push them to the repo.
git add .
git commit -m "your message"
git push origin <branch-name>
- To address an issue on your commit message, use the following syntax.
git commit -m "partial progress on issue #<issue-number>"
- To close an issue on your commit message, use the following syntax.
- Reserved words are: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved
git commit -m "<reserved-word> #<issue-number>"
Then go to the repo and create a pull request, but wait for at least two reviews before merging your branch to the main branch.
If you have a request or believe something can be improved, feel free to open an issue and discuss it with the team. The project is still in its early stages, so we're open to any suggestions.