Manual install of cobudget-api

Introduction

The server will be set up to use blue/green deployments. This will done by making two directories, incidentally named blue and green and set a symbolic link current that points to the current release in production.
A new release can then be prepared in the directory not currently in use and the change can happen almost instantanously.
Rollback to the previous version can happen equally fast (if there are no incompatible database changes).

First time install

Create directories, adjust permissions and clone the cobudget-api github repo.
1
cd /opt
2
sudo mkdir cobudget-api
3
sudo chown ubuntu cobudget-api
4
cd cobudget-api
5
mkdir green
6
git clone https://github.com/cobudget/cobudget-api.git blue
7
ln -s /opt/cobudget-api/blue current
Copied!
Get the env and start files and copy to the installed dir
1
cd
2
git clone https://github.com/greaterthan/aws-deploy.git
3
cp aws-deploy/env aws-deploy/start /opt/cobudget-api/current
Copied!
Now edit the env and env-vars file. The database variable could be
1
DATABASE_URL="postgres://cobudget:<password>@cobudget-prod.cird90svlmvv.us-west-2.rds.amazonaws.com:5432/cobudget_prod"
Copied!
Install missing Postgresql dev files and install all packages
1
sudo apt-get install postgresql-common libpq-dev
2
/usr/local/lib/ruby-2.4.0/bin/bundle install
Copied!

Brief notes on new deployment

  • Remove the unused blue of green dir
  • Clone the api repo into the unused blue or green dir
  • Copy env , env-vars , start and config/database.yml to the new dir
If there's a DB update, dumb the DB before the update, do the update and dump it again after. Just to be sure.
1
export PATH=$PATH:/usr/local/lib/ruby-2.4.0/bin
2
. ./env
3
pg_dump -h cobudget-prod.cird90svlmvv.us-west-2.rds.amazonaws.com -U cobudget -d cobudget_prod >cobudget-prod-<yymmdd>-before-update
4
bundle exec rake db:migrate
5
pg_dump -h cobudget-prod.cird90svlmvv.us-west-2.rds.amazonaws.com -U cobudget -d cobudget_prod >cobudget-prod-<yymmdd>-after-update
Copied!
And finally, change the symlink and restart the service
1
rm current; ln -s /opt/cobudget-api/blue/ current
2
sudo systemctl restart cobudget-api
Copied!

Running with systemd

Copy the systemd config files
1
sudo cp aws-deploy/cobudget-* /etc/systemd/system
Copied!
Get systemd to read the file, start the server and enable for automatic start at boot
1
sudo systemctl daemon-reload
2
sudo systemctl start cobudget-api
3
sudo systemctl start cobudget-dj
4
sudo systemctl start cobudget-digestemail.timer
5
sudo systemctl enable cobudget-api
6
sudo systemctl enable cobudget-dj
7
sudo systemctl enable cobudget-digestemail.timer
Copied!
You can check if the server has started with
1
sudo systemctl status cobudget-api.service
2
sudo systemctl status cobudget-dj.service
3
sudo systemctl status cobudget-digestemail.timer
Copied!
Last modified 3yr ago