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.
** 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.
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/whimcThese commands should be executed in a terminal or command line interface on the server where you are setting up your Flask application.
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-generatorNote: 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.
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.txtThe 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-generatorThis should create a file called path-generator.sock.
Next we'll configure nginx.
apt-get update # Update packages and install Nginx
apt-get install nginxModify 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.confCopy 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.
- Log into https://aws.illinois.edu and go to EC2
- Click to create a new EC2 instance
- Select the Ubuntu 64-bit (x86) AMI
- Select whichever type you'd like. I used the
t2.microtype. - You can leave all other settings as-is
- Create and download a new key pair if you do not have one
- When creating the box, create a new key (or select an existing one
- Go to the instance details
-
Make note of the "Public IPv4 DNS" in the instance details
-
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 ec2Host ec2 Hostname public-dns-name User ubuntu IdentityFile /path/my-key-pair.pem -
Once on the system, update everything
sudo apt update sudo apt upgrade
-
$ sudo apt install software-properties-common $ sudo add-apt-repository ppa:deadsnakes/ppa $ sudo apt update $ sudo apt install python3.8 $ python3 --version
-
$ sudo apt install python3-pip $ pip3 --version
-
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
-
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
- Use the Unmined map image export tool found under
\Box\WHIMC\development\MC Tools and Assets\Tools\Unmined Map Toolto create a PNG with specific coordinates to add to the maps directory. - ssh into the AWS ec2 instance
- Activate super user with
sudo su - Navigate to the path-generator directory
cd /srv/whimc/path-generator - Pull new files
git pull - 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
- Run
systemctl restart path-generatorto restart the API