This is used to deploy updates/changes to production as well as set up a development environment locally for use.
There are two machines defined in the Vagrantfile.template
. One for deploying to DigitalOcean using the Vagrant plugin vagrant-digitalocean as a provider to manage droplets on DigitalOcean. The other machine is for local development.
-
Before setting up Vagrant, you will need to install VirtualBox. Go to this page and pick the appropriate installation from version
5.1.30
. -
Install Vagrant by geting the installation here.
-
Get the
Ubuntu Xenial
box by runningvagrant box add ubuntu/xenial --box-version=20171116.0.0
in terminal -
Install the Vagrant plugins
vagrant-digitalocean
andvagrant-hostmaster
by running the following in terminal:vagrant plugin install vagrant-digitalocean vagrant plugin install vagrant-hostmanager
For more details on these plugins, visit their Github repositories:
-
Make a copy of
Vagrantfile.template
and rename itVagrantfile
-
(Optional) Modify
Vagrantfile
for managing DigitalOcean droplet (See Production for more details) -
Run
vagrant up ruhacks-local
to setup the vm for development
Once you have setup according to the instructions above then you can do the following:
- ssh into the machine by running
vagrant ssh ruhacks-local
- shut the machine down by running
vagrant halt ruhacks-local
- restart the machine by running
vagrant reload ruhacks-local
- access the application by going to http://ruhacks.local
- To add other applications for access on host, modify the
default.local
file in the.provision
folder. Then ssh into the machine and runfor the changes to appear.sudo cp /vagrant/.provision/default.local /etc/nginx/sites-available/default sudo nginx -s reload
- However there is one more step if you want to access it by domain name (i.e.
*.ruhacks.local
):- Go to the
Vagrantfile
and add the domain name toconfig.hostmanager.aliases
- Run
vagrant hostmanager ruhacks-local
to update your hosts file
- Go to the
- Now you should be able to access the application on host by visiting the new domain name
There is a known issue where when static files are updated they may not show up properly when served by NGINX. An example of this can be found here.
The solution is to go to the /etc/nginx/
directory and edit the nginx.conf
file by changing the sendfile
option to off
.
If you don't know how to configure nginx, please check out the docs
Currently we're using PM2 to keep applications running in the background as well as starting up on system startup.
When you ssh into the machine, you will notice that the pm2 processes are not run under the current user which you logged in as. When the machine was setup, it was done as root so to change to root user run sudo su
to change user to root.
The name of a process will be its filename unless the --name
option is provided. If the --name
option is provided then the process name will be whatever is provided to that option.
- To view current applications processes run
pm2 status
- To view output of applications run
pm2 logs
or to view a specific application output runpm2 logs <process name>
- To view pm2 status as a dashboard run
pm2 dash
- To start an application,
cd
to the application directory and runpm2 start <filename> [--name <process name>]
. - To restart an application run
pm2 restart [<process name>|all]
- To stop an application run
pm2 stop [<process name>|all]
- To remove an application from pm2 run
pm2 delete [<process name>|all]
- To make current pm2 processes start on startup run
pm2 startup
- note this will reboot the machine
- Update path to ssh file for
override.ssh.private_key_path
. This ssh file can be found by asking the droplet maintainer. - Add in token to
provider.token
forruhacks-droplet
machine. This can be found by asking the droplet maintainer or resetting the ruhacks token on DigitalOcean.
Before deploying make sure your changes work on the dev environment!
When deploying to droplet make sure to have all the files the server has under its /vagrant
directory. Then to update the server with your changes run vagrant rsync ruhacks-droplet
.
Currently rsyncing is not the best method if you only want to push your changes without having to setup and update the other applications
If the need arises we'll look into setting up FTP/SFTP or some other method on production server to push changes.
Submit an issue if anything does not behave as expected.
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-16-04 https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-redis-on-ubuntu-16-04 https://stackoverflow.com/questions/11192134/connect-to-a-db-using-psycopg2-without-password scp -r -i /c/.ssh/di_rsa admin/bower_components root@ruhacks.com:/vagrant/admin