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
growbot
nginx 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/growbot
mv growbot growbot.conf
- Run
$ nginx -s reload
to reload the nginx configuration - From your local machine, verify nginx is set up correctly by checking that
curl growbot.tardis.ed.ac.uk
displays<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/
. Replaceremote
with 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 connections
totrust
- Change the last column for
127.0.0.1/32
totrust
- Change the last column for
::1/128
totrust
- Run
service postgresql restart
- Create the default superuser account
- Switch to the postgres user,
$ su postgres
- Create the
root
postgres superuser,$ createuser -s root
- Return back to the
root
user, hitctrl+d
- Run
psql postgres
to 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+d
to leave the postgres shell - Run
make reset_schema
to create a database, give ourgrowbot
user admin permissions ondb growbot_dev
, and load the database schema.
-
On your local machine, make sure Go is set up (you should have
GOROOT
andGOPATH
set up appropriately).Don't have Go? Please follow the Go installation instructions.
You should also add
$GOPATH/bin
to your$PATH
. This is so that any self-built binaries (such asgoimports
) are easy to run. -
Already have Go set up? Make sure
go version
says 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-api
and run$ GOOS=linux go build
to cross-compile a binary for your Linux VM. -
On the remote machine, run
git clone https://github.com/teamxiv/growbot-api.git
to clonegrowbot-api
to~/growbot-api
. -
On your local machine, use
scp growbot-api remote:growbot-api/
to send the cross-compiled binary to~/growbot-api/growbot-api
on the server namedremote
. Replaceremote
with the details of your remote server. -
On your remote machine, within
~/growbot-api
, copyconfig.example.yml
toconfig.yml
-
In a screen session, run
config=config.yml ./growbot-api
, and your API should be deployed onapi.growbot.tardis.ed.ac.uk
via 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.uk
should 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.uk
should have the landing page. ClickRegister
and test out registration. Your browser should not complain about HTTPS. - If registration works correctly and you are logged in, everything is working correctly.