Skip to content

Setting up an environment on the server

ReubenRosenberg edited this page Oct 3, 2022 · 7 revisions

If you don't want to set up a full stack on your own computer (instructions here), then developing on the server is a viable alternative. It is also useful for testing your changes in the dev environment (which uses a copy of the production database) before pushing them to production.

Clone the repository

git clone https://github.com/VenerableHouse/VenerableWebsite ~/VenerableWebsite

Set up your virtualenv

See setting up an environment locally for why a virtualenv is recommended.

mkdir ~/virtualenvs && cd ~/virtualenvs
virtualenv ruddweb
source ~/virtualenvs/ruddweb/bin/activate
cd ~/VenerableWebsite
pip install -r requirements.txt

Running the test environment

python run_server.py --port 5000 --env (dev|test|prod)

When running Flask's built in test server, you can only connect to it from localhost (don't change this; opening up the test server to the internet is a huge security risk!). To get around this, you will need to do port forwarding:

ssh -L 9001:localhost:5000 <host>

Then, when you make a request to localhost:9001 on your own computer, it forwards the request to the host's localhost:5000 port. So if the Flask application is listening on port 5000 (the default), then browsing localhost:9001 on your computer will send requests to the test application.

Mounting your server directory locally

In the past you may have used a 'shared' folder to edit files located on a virtual machine from your normal development environment. A similar setup can be performed to edit your server directory locally. You'll need to install sshfs. Create a local mountpoint directory to mirror the remote directory. Then mount the remote directory with:

sshfs username@venerable.caltech.VenerableWebsite/ mountpoint

(this assumes that you have the VenerableWebsite repo cloned on your server directory).

At the end of your development session you can unmount with:

umount mountpoint