Skip to content

Latest commit

 

History

History
78 lines (64 loc) · 4.4 KB

README.md

File metadata and controls

78 lines (64 loc) · 4.4 KB

Installation instructions

Set up Ubuntu

  1. Make sudoer account if needed.
  2. Stay authenticated as root from sudoer account: sudo -s
  3. Lock root account: passwd -l root
  4. Edit SSH config: nano /etc/ssh/sshd_config
    1. Disable RootLogin and change SSH port if desired.
    2. Setup an SSH key and disable PasswordAuthentication.
  5. Install Nginx: apt install -y nginx
  6. Configure firewall: ufw allow [YOUR-SSH-PORT]; ufw allow 'Nginx Full'
  7. Start firewall: ufw enable
  8. Install dependencies needed to compile uWSGI later: apt install build-essential gcc python3-dev
  9. Make user account for the app: adduser --system --home /srv/website website

Install app

  1. Switch to website user and directory: sudo -su website && cd ~website
  2. Clone repo from GitHub: git clone https://github.com/tassaron/muffin-shop
  3. Install nvm
  4. Install latest NodeJS: nvm install node
  5. Run npm install to create a gigantic node_modules directory because ya gotta have a gigantic node_modules directory
  6. Run npm run build to compile the React components into static/js/dist/bundle.js
  7. Make Python virtual environment: python3 -m venv env
  8. Activate virtual environment: source env/bin/activate
  9. Install using Pip: pip install .

Configure app

  1. Be the website user with venv active
  2. Copy template for .env file: cp .env.example .env
  3. Edit .env to set SITE_NAME
  4. Each instance has a config and static tree which is decided by CONFIG_PATH in .env
  5. Example: CONFIG_PATH=config/client/<instance_name>
  6. Create instance directories by copying config/client/skel to the aforementioned config dir
  7. Create static/client/<instance_name> for static assets
  8. Customize config/client/<instance_name>/modules.json, config/client/<instance_name>/markdown/about.md, etc. as needed
  9. Set any other variables in .env as needed for the modules enabled
    • For example, you need to set STRIPE_ variables to take payments for a shop module
    • The security of your .env file is very important. It should not be readable by anonymous Unix users nor be committed to source control
  10. Customize HTML inside config/client/<instance_name>/templates as needed.

Run tests

  1. Be the website user with venv active
  2. Install pytest with pip install pytest.
  3. Run tests without hitting APIs: pytest -k 'not payment and not email'
    • If your EMAIL_API_KEY is undefined/empty, it is safe to run the email tests (emails will be printed in the log instead of being sent)
    • If you have a testing API key or STRIPE_API_KEY is undefined/empty, then payment tests can be included.
    • Do not run payment tests with a production API key.

Create database

  1. Be the website user with venv active
  2. Initialize app with python3 scripts/manage.py init (optional; this creates a secret key but the app also creates one if it's missing)
  3. Make database: python3 scripts/database.py new. Copy the admin user's password (change it later using the website)

Create services

  1. Be the sudo user again (exit from website user if following chronologically)
  2. Edit your domain name into this file: nano install/website.nginx
  3. Edit install/website.service and install/huey.service if the website directory is not /srv/website/
  4. Set permissions: chown -R website:nogroup /srv/website; chmod -R 644 /srv/website
  5. Place Nginx config: cp install/website.nginx /etc/nginx/sites-available/<instance_name>.nginx
    • Standard practice is to name Nginx config files after the domain name, so you may want to do that instead
  6. Enable Nginx config: ln -s /etc/nginx/sites-available/website.nginx /etc/nginx/sites-enabled/website.nginx
  7. Delete default Nginx config: rm /etc/nginx/sites-enabled/default
  8. Place Systemd units: cp install/*.service /etc/systemd/system
  9. Start uWSGI service: systemctl start website.service
  10. Start Huey consumer service: systemctl start huey.service
  11. Restart Nginx: systemctl restart nginx
  12. Enable the services to start at boot: systemctl enable website.service huey.service

Enabling HTTPS

  1. Use Certbot to get an SSL cert that renews automatically, which also has a handy option to convert the Nginx config for you.
  2. If you get a 500 error, double-check that /srv/website/website.sock is owned by the www-data group