Prerequisites: Linux knowledge, a Virtual Machine running Debian 9.8 (stretch)
These instructions will walk you through:
- Installing a text editor (vim) and version control system (git)
- Installing a web server (nginx)
- Setting up LetsEncrypt using certbot (for https, which is REQUIRED)
- Building and deploying
growbot-site - Setting up PostgreSQL
- Building and deploying
growbot-api
These instructions assume your virtual machine is running Debian 9.
- Run
$ apt update - Install vim and git using
$ apt install -y make vim git - Fix vim by following the vim-sensible instructions
These instructions assume that you already have DNS settings fully configured.
- Run
$ apt install -y nginx - Create the
growbotnginx config file inside/etc/nginx/sites-available $ vim /etc/nginx/sites-available/growbot- Paste the following content:
server { listen 80; server_name growbot.tardis.ed.ac.uk; location / { root /srv/growbot; } } server { listen 80; server_name api.growbot.tardis.ed.ac.uk; location / { proxy_pass http://localhost:8080; } location /stream { proxy_pass http://localhost:8080; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; proxy_set_header Origin ''; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
- Create a folder to store the GrowBot website,
mkdir /srv/growbot - Create a test file containing
<h1>Hello world</h1>at/srv/growbot/index.html - Navigate to the enabled sites directory,
cd /etc/nginx/sites-enabled - Create a symlink to the growbot config, and rename it
ln -s ../sites-available/growbotmv growbot growbot.conf- Run
$ nginx -s reloadto reload the nginx configuration - From your local machine, verify nginx is set up correctly by checking that
curl growbot.tardis.ed.ac.ukdisplays<h1>Hello world!</h1>
- On your local machine, clone the website,
git clone https://github.com/teamxiv/growbot-site.git $ cd growbot-site- Install dependencies,
npm install - Create an optimised production build of the website,
npm run build - Upload the website using
scp -r build/* remote:/srv/growbot/. Replaceremotewith the details of your remote server.
- On the remote machine, navigate to the source code directory (
cd ~/growbot-api) - Install PostgreSQL 11 (see these instructions)
- Edit
/etc/postgresql/11/main/pg_hba.conf(the exact path may be different depending on the PostgreSQL version) - Scroll down to the bottom
- Change the last column for
"local" Unix domain socket connectionstotrust - Change the last column for
127.0.0.1/32totrust - Change the last column for
::1/128totrust - Run
service postgresql restart - Create the default superuser account
- Switch to the postgres user,
$ su postgres - Create the
rootpostgres superuser,$ createuser -s root - Return back to the
rootuser, hitctrl+d - Run
psql postgresto open a postgres shell - Execute
create role growbot with login;to create agrowbot"role" that is able to log in (so it's basically a user). This user has no password for convenience. - Hit
ctrl+dto leave the postgres shell - Run
make reset_schemato create a database, give ourgrowbotuser admin permissions ondb growbot_dev, and load the database schema.
-
On your local machine, make sure Go is set up (you should have
GOROOTandGOPATHset up appropriately).Don't have Go? Please follow the Go installation instructions.
You should also add
$GOPATH/binto your$PATH. This is so that any self-built binaries (such asgoimports) are easy to run. -
Already have Go set up? Make sure
go versionsays you are running go 1.11 or later. -
Run
go get github.com/teamxiv/growbot-api. -
Navigate to
$GOPATH/src/github.com/teamxiv/growbot-api/cmd/growbot-apiand run$ GOOS=linux go buildto cross-compile a binary for your Linux VM. -
On the remote machine, run
git clone https://github.com/teamxiv/growbot-api.gitto clonegrowbot-apito~/growbot-api. -
On your local machine, use
scp growbot-api remote:growbot-api/to send the cross-compiled binary to~/growbot-api/growbot-apion the server namedremote. Replaceremotewith the details of your remote server. -
On your remote machine, within
~/growbot-api, copyconfig.example.ymltoconfig.yml -
In a screen session, run
config=config.yml ./growbot-api, and your API should be deployed onapi.growbot.tardis.ed.ac.ukvia nginx!
HTTPS is required for service workers and other web features (like camera access) to work correctly. You must set up HTTPS.
- Follow the installation instructions here: https://certbot.eff.org/lets-encrypt/debianstretch-nginx
- In your browser,
https://api.growbot.tardis.ed.ac.ukshould show a HTML webpage containing exactly "404 page not found" in the source, and nothing else. Your browser should not complain about HTTPS. - In your browser,
https://growbot.tardis.ed.ac.ukshould have the landing page. ClickRegisterand test out registration. Your browser should not complain about HTTPS. - If registration works correctly and you are logged in, everything is working correctly.