Hackerspace test environment installation (instructions for students)
This guide assumes you are running Linux. If not, then you can use the Windows subsystem for Linux if you have Windows 10. Another option is Git Bash
Prep if using Windows
- Intall git for Windows: https://git-scm.com/download/win
- Install VS Code: https://code.visualstudio.com/
- Install Python 3: https://www.python.org/downloads/ (Note, to access Python3, you may need to provide a full path such as
../../../../AppData/Local/Programs/Python/Python312/python.exe
)
Preparation if using Ubuntu
- Install Git:
sudo apt install git
.
Common Prep:
- Pick/create a location for the project, e.g:
~/Developer
- Install Postgresql: https://www.postgresql.org/download/
Fork the repository
- Create a Github account.
- Go to https://github.com/timberline-secondary/flex-site
- Click the "Fork" button on the top right corner.
- This will allow you to have your own copy of the project on your GitHub account.
Clone the repository
- In your terminal, move to the parent directory of the project:
cd ~/Developer
- Go to your forked repository on github.
- Click "Clone or download" and copy the url.
- In the terminal:
git clone yoururlhere
- This will download the project into ~/Developer/flex-site/
Python Virtual Environment
- If on Windows, open a GitBash prompt within VS Code.
- Move in to the directory of the project if you aren't already there:
cd ~/Developer/flex-site
- Create a virtual environment within your project:
python -m venv flex-venv --prompt flex
- Activate your virtual environment: Linux:
source venv/bin/activate
Windows: source venv/Scripts/activate
- You should now see "(flex)" appear before your prompt.
- Later (don't do it now), when you are finished you can leave the environment by typing:
deactivate
Installing required python packages
python -m pip install -r requirements.txt
Creating the SQLite database (Easy Option)
- A basic database to get started. You can move to a more advanced PostgreSQL database later if you like, or try now (see next section)
./src/manage.py migrate
This will create your database and create tables for all the thrid-party apps/requirements
- Now prepare tables for all of the flex-site models:
./src/manage.py makemigrations profiles events excuses utilities
(you might get an error later on if I forget to keep this list of apps updated =)
- Create the tables in your database:
./src/manage.py migrate
- Create a cache table:
./src/manage.py createcachetable
- Populate the database with some default data:
./src/manage.py loaddata src/initial_data
- Create a superuser in the database (i.e.teacher/administrator account):
./src/manage.py createsuperuser
Creating the PostgreSQL database (Advanced Option)
- You can follow these instructions if you are on Linux (won't work on Windows). Use the Python3 options.
Running the server
./src/manage.py runserver
- Segmentation Fault? try running it again...
- In your browser go to 127.0.0.1:8000 to see if it worked!
- Log in as the superuser to see what a teacher/admin sees
- Sign up to create a student account.
- Stop running server (or any bash script in progress) with
Ctrl + C
Setting up PyCharm IDE
- Install some version of PyCharmIDE
- File > Open, then choose the ~/Developer/flex-site directory
- Run > Edit Configurations
- it "+" and choose Django Server
- Defaults should be good, but "Run Browser" option is handy, tick it if you want to auto open a browser when you run the server.
- Turn on Django support. Click "Fix" button at bottom
- Tick "Enable Django Support
- Set Django project root to: ~/Developer/flex-site/src
- Set Settings to:
flex-site/settings
(this is relative to the root above)
- OK, Apply, Close.
- Hit the green play button to test. Try logging in with the superuser account you created earlier.
Committing changes
- Move into your cloned directory.
cd ~/Developer/flex-site
- Add the upstream remote:
git remote add upstream git@github.com:timberline-secondary/flex-site.git
- Pull in changes from the upstream master:
git fetch upstream
- Merge the changes:
git merge upstream/master
- Create a new branch:
git checkout -b yourbranchname
- Make your changes and them commit:
git commit -am "yourchangeshere"
- Push your branch to your fork of the project:
git push origin yourbranchname
- Go to your fork of the repository.
- Select your recently pushed branch and create a pull request.
- Complete pull request.
Server set up. Ubuntu 16.04
apt-get update && apt-get upgrade
- (perl locales error? https://www.thomas-krenn.com/en/wiki/Perl_warning_Setting_locale_failed_in_Debian)
adduser username --force-badname --ingroup sudo
- add public key authentication
- set up basic firewall (ufw) and allow OpenSSH, turn on rate limiting
ufw limit ssh/tcp
, install fail2ban
- disable password authentication and root login
/etc/ssh/sshd_config
- time: set timezone
sudo dpkg-reconfigure tzdata
and install ntp.
Nginx Postrgres uWSGI Python/Django stack
- Install stack: this for postgresql, and this for the rest of the stack.
- Remove Apache2 from port 80 (if using)
- ...permissions of socket...
Additional Security
- Add SSL,
- redirect to https in mysite_nginx.conf, server 80 block (
return 301 https://$server_name$request_uri;
),
- Add forward secuirty
- Automatic security updates
Other
- Django DEBUG = False