Deploying ExVenture

Posted on 14 Dec 2018 by Eric Oestrich

Up until recently, how to deploy ExVenture has been a bit of a mystery. I have done it a few times, for MidMUD most notably, but it was fairly tricky to do and entirely done by hand.

I also relied on some parts of linux like /etc/profile.d/ to ensure environment variables were loaded, so starting the application could only be done by a login shell. It wasn’t the best, but hey, it worked.

This week however, a few more people were starting to get interested in ExVenture and asking about how to host it and I finally got embarassed enough to get something more formal around how to deploy it.

I also started a hosting service called ExVenture World if anyone is interested in having a game without having to deploy it. See the announcement post for ExVenture World on Patreon.

Vagrant

Vagrant is a tool for spinning up local VMs quickly, and being able to quickly recreate them from a base box. We’re going to use this to get a local install going. Install Vagrant before continuing.

vagrant up

After a few minutes, you’ll have a local machine you can ssh into. Vagrant will provision python for us on first boot so that we can run ansible on it in our next step.

Something I’ve tended to have issues with on Vagrant is SSH known host issues on recreating a VM. I just learned about this snippet you can place in ~/.ssh/config to ignore host checks. Do make sure it’s only enabled for 127.0.0.1 as this is very insecure.

Host 127.0.0.1
  HostName 127.0.0.1
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  IdentitiesOnly yes

Ansible

Ansible is a tool for configuring remote servers. They run playbooks to make sure a server is configured the same each time. See more information about it and how to install it on their site.

First install the roles you’ll be using to provision the server. This uses Ansible Galaxy to pull down remote roles.

ansible-galaxy install -r deploy/requirements.yml

Next, run the setup playbook on the local machine. This will configure the local VM to be provisioned for the next few steps. Make sure to update this line in the deploy/group_vars/all.yml line to include your GitHub user. It will download any keys you have associated to your account and let you into the deploy user.

ansible-playbook -l local deploy/setup.yml

Configure

There are now two files on the machine that need to be edited, /etc/exventure.config.exs and /etc/nginx/sites-enabled/exventure. The nginx config file just needs to know what it’s domain name is. The exventure.config.exs file needs more modification. Any empty string "" should be filled in with the required information.

You should set up SMTP so your game can send emails, this will also require setting the from address.

The endpoint and networking lines both need to know the new domain name for your game as well. You should also connect your game to Gossip. It’s more fun that way.

Certbot

Once you are configured, restart nginx and then configure SSL via certbot.

sudo systemctl restart nginx
sudo certbot --nginx

Follow the prompts for configuring your new domain. You should set the game to redirect any HTTP traffic to the HTTPS port.

Deploying

Next you can deploy your game, the first deploy you should seed as well. ExVenture comes with a simple deploy script that will handle most of this for you. The last argument should be the fully qualified domain name that you previously set up. It will try SSH’ing in as deploy.

Before deploying, make sure to generate a production release with the release.sh script. Note that this needs to be run on a linux system. You cannot deploy an erlang release built on a mac to a linux remote.

./release.sh
./deploy.sh --seed my-game.example.com

On future deploys, you only need to use

./deploy.sh my-game.example.com

A Remote Server

The previous steps got a local VM ready. Getting a remote machine is not that much harder. I recommend using Digital Ocean as your VPS of choice, ExVenture World is hosted there.

Once you create a droplet (using Ubuntu 18.04), SSH in and install python.

sudo apt install python

Next setup a new host file named deploy/host_remote with the following:

[remote]
the.ip.or.domain
ansible-playbook -i deploy/host_remote deploy/setup.yml

And the rest is the same. Configure the game, configure certbot, generate a release, and deploy it.

Conclusion

Hopefully this helps you get a remote ExVenture game set up and running. If you have any questions please come by the Discord group.

comments powered by Disqus
Creative Commons License
This site's content is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License unless otherwise specified. Code on this site is licensed under the MIT License unless otherwise specified.