Skip to content

Latest commit

 

History

History
152 lines (132 loc) · 6.29 KB

File metadata and controls

152 lines (132 loc) · 6.29 KB

Contents

Note: If you only need to obtain player path images, please refer to the README.md file instead. Setting up the server is not necessary for this purpose.

Installation

** We followed this guide to set up the server.** This guide introduces how to deploy a micro Flask application using Gunicorn as the WSGI server and Nginx as the web server. It is recommended for those unfamiliar with deploying Flask applications, as it covers key steps like installing dependencies, setting up a virtual environment, and configuring Nginx.

Before starting, make sure the security permissions on the server are configured to allow all inbouind traffic. In other words, please ensure that the server's security settings (such as firewall rules or security group configurations) are adjusted to accept all incoming requests from all sources.

File structure

This project (and subsequent APIs) will live in /srv/whimc. This entire tutorial will be using the super user.

sudo su
mkdir /srv/whimc
cd /srv/whimc

These commands should be executed in a terminal or command line interface on the server where you are setting up your Flask application.

Cloning the repo

We need to clone the repo but since we are the super user right now, there is no SSH key. Generate an ssh key on the server and add it to your GitHub account. Replace /location/to/private_ssh_key with your path. Make sure the resulting directory is named path-generator (case sensitive)!

git clone git@github.com:whimc/Path-Generator.git --config core.sshCommand="ssh -i /location/to/private_ssh_key" path-generator

Note: This assumes you have already generated an SSH key. If you currently do not have this set up, please refer to the EC2 Setup Guide below before running the git clone command.

Python requirements

Recent versions of Ubuntu come with Python 3 pre-installed. Make sure the version is >= 3.10. Install/update Python if this is not the case. After fulfilling the python version requirement, we can enter the directory and install our requirements.

cd path-generator
apt install python3-venv
python3 -m venv venv # Create a virtual environment to install the required packages
source venv/bin/activate # Activate the virtual environment
pip install -r requirements.txt

Configure application

Creating the system service

The given path-generator.service can be copied to the system serviced directory without modification.

cp path-generator.service /etc/systemd/system
systemctl start path-generator
systemctl enable path-generator

This should create a file called path-generator.sock.

Nginx

Next we'll configure nginx.

apt-get update # Update packages and install Nginx
apt-get install nginx

Modify server_name within path-generator.conf to match the public DNS of the box.

vim path-generator.conf # Modify 'server_name'

Note: Navigate to the server_name line using the arrow keys. Press i to enter insert mode to edit the text. Press Esc to exit insert mode. After making your changes, type :wq and press Enter to save and exit Vim.

Modify server_names_hash_bucket_size within /etc/nginx/nginx.conf to be 128 instead of 32. This is necessary due to the length of EC2 public DNS addresses.

vim /etc/nginx/nginx.conf

Copy that modified file to nginx's enabled sites and reload Nginx.

cp path-generator.conf /etc/nginx/sites-enabled
systemctl restart nginx
ufw allow 'Nginx Full'

You are now done. The API should now be visible at http://[public DNS]/path-generator.

EC2 Setup Guide

Creating EC2 Instance

  1. Log into https://aws.illinois.edu and go to EC2
  2. Click to create a new EC2 instance
  3. Select the Ubuntu 64-bit (x86) AMI
  4. Select whichever type you'd like. I used the t2.micro type.
  5. You can leave all other settings as-is
  6. Create and download a new key pair if you do not have one
  7. When creating the box, create a new key (or select an existing one
  8. Go to the instance details

Accessing EC2

  1. Make note of the "Public IPv4 DNS" in the instance details

  2. SSH into the box using your key and the DNS

    ssh -i /path/my-key-pair.pem ubuntu@public-dns-name

    I would recommend adding an entry to your SSH config so you can simply enter ssh ec2

    Host ec2
    	Hostname public-dns-name
    	User ubuntu
    	IdentityFile /path/my-key-pair.pem
    
  3. Once on the system, update everything

    sudo apt update
    sudo apt upgrade
  4. Install python

    $ sudo apt install software-properties-common
    $ sudo add-apt-repository ppa:deadsnakes/ppa
    $ sudo apt update
    $ sudo apt install python3.8
    $ python3 --version
  5. Install PIP

    $ sudo apt install python3-pip
    $ pip3 --version
  6. Create your own SSH key on the EC2 instance

    $ ssh-keygen
    # Click enter until the key is generated
    $ cat ~/.ssh/id_rsa.pub

    Copy that output to your clipboard

  7. Add the SSH key to your GitHub account

    • Go to Settings -> SSH and GPG keys
    • Click "New SSH key"
    • Give the key a name and paste in your clipboard
    • Once the key is added, click the "Enable SSO" and select the WHIMC organization. You will be prompted to log in with SSO

Updating and Adding New Maps

  1. Use the Unmined map image export tool found under \Box\WHIMC\development\MC Tools and Assets\Tools\Unmined Map Tool to create a PNG with specific coordinates to add to the maps directory.
  2. ssh into the AWS ec2 instance
  3. Activate super user with sudo su
  4. Navigate to the path-generator directory cd /srv/whimc/path-generator
  5. Pull new files git pull
  6. Update config.json with the new entries that have been added from config-sample.json
  • Since this is all through the terminal, you'll have to use a tool like vim or emacs to edit the file
  • Make sure to update the coreprotect_id field for each new map that was added
  • After updating the file, if you run diff config.json config-sample.json, you should just see differences for coreprotect_id and database/Imgur credentials
  1. Run systemctl restart path-generator to restart the API