timberline-secondary / flex-site

Website for Timberline's Flex Activities
0 stars 1 forks source link

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

  1. Intall git for Windows: https://git-scm.com/download/win
  2. Install VS Code: https://code.visualstudio.com/
  3. 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

  1. Install Git: sudo apt install git.

Common Prep:

  1. Pick/create a location for the project, e.g: ~/Developer
  2. Install Postgresql: https://www.postgresql.org/download/

Fork the repository

  1. Create a Github account.
  2. Go to https://github.com/timberline-secondary/flex-site
  3. Click the "Fork" button on the top right corner.
  4. This will allow you to have your own copy of the project on your GitHub account.

Clone the repository

  1. In your terminal, move to the parent directory of the project: cd ~/Developer
  2. Go to your forked repository on github.
  3. Click "Clone or download" and copy the url.
  4. In the terminal: git clone yoururlhere
  5. This will download the project into ~/Developer/flex-site/

Python Virtual Environment

  1. If on Windows, open a GitBash prompt within VS Code.
  2. Move in to the directory of the project if you aren't already there: cd ~/Developer/flex-site
  3. Create a virtual environment within your project: python -m venv flex-venv --prompt flex
  4. Activate your virtual environment: Linux: source venv/bin/activate Windows: source venv/Scripts/activate
  5. You should now see "(flex)" appear before your prompt.
  6. Later (don't do it now), when you are finished you can leave the environment by typing: deactivate

Installing required python packages

  1. python -m pip install -r requirements.txt

Creating the SQLite database (Easy Option)

  1. 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
  2. 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 =)
  3. Create the tables in your database: ./src/manage.py migrate
  4. Create a cache table: ./src/manage.py createcachetable
  5. Populate the database with some default data: ./src/manage.py loaddata src/initial_data
  6. Create a superuser in the database (i.e.teacher/administrator account): ./src/manage.py createsuperuser

Creating the PostgreSQL database (Advanced Option)

  1. You can follow these instructions if you are on Linux (won't work on Windows). Use the Python3 options.

Running the server

  1. ./src/manage.py runserver
  2. Segmentation Fault? try running it again...
  3. In your browser go to 127.0.0.1:8000 to see if it worked!
  4. Log in as the superuser to see what a teacher/admin sees
  5. Sign up to create a student account.
  6. Stop running server (or any bash script in progress) with Ctrl + C

Setting up PyCharm IDE

  1. Install some version of PyCharmIDE
  2. File > Open, then choose the ~/Developer/flex-site directory
  3. Run > Edit Configurations
  4. it "+" and choose Django Server
  5. 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.
  6. Turn on Django support. Click "Fix" button at bottom
  7. Tick "Enable Django Support
  8. Set Django project root to: ~/Developer/flex-site/src
  9. Set Settings to: flex-site/settings (this is relative to the root above)
  10. OK, Apply, Close.
  11. Hit the green play button to test. Try logging in with the superuser account you created earlier.

Committing changes

  1. Move into your cloned directory. cd ~/Developer/flex-site
  2. Add the upstream remote: git remote add upstream git@github.com:timberline-secondary/flex-site.git
  3. Pull in changes from the upstream master: git fetch upstream
  4. Merge the changes: git merge upstream/master
  5. Create a new branch: git checkout -b yourbranchname
  6. Make your changes and them commit: git commit -am "yourchangeshere"
  7. Push your branch to your fork of the project: git push origin yourbranchname
  8. Go to your fork of the repository.
  9. Select your recently pushed branch and create a pull request.
  10. Complete pull request.

Server set up. Ubuntu 16.04

  1. apt-get update && apt-get upgrade
  2. (perl locales error? https://www.thomas-krenn.com/en/wiki/Perl_warning_Setting_locale_failed_in_Debian)
  3. adduser username --force-badname --ingroup sudo
  4. add public key authentication
  5. set up basic firewall (ufw) and allow OpenSSH, turn on rate limiting ufw limit ssh/tcp, install fail2ban
  6. disable password authentication and root login /etc/ssh/sshd_config
  7. time: set timezone sudo dpkg-reconfigure tzdata and install ntp.

Nginx Postrgres uWSGI Python/Django stack

  1. Install stack: this for postgresql, and this for the rest of the stack.
  2. Remove Apache2 from port 80 (if using)
  3. ...permissions of socket...

Additional Security

  1. Add SSL,
  2. redirect to https in mysite_nginx.conf, server 80 block (return 301 https://$server_name$request_uri;),
  3. Add forward secuirty
  4. Automatic security updates

Other

  1. Django DEBUG = False