app deployment notes

get application code

make ssh key for bitbucket

ssh-keygen (~/.ssh/bitbucket) is ssh-agent running? ps -e | grep [s]sh-agent start it if not eval ssh-agent $SHELL add the new key ssh-add ~/.ssh/bb list ssh identities ssh-add -l. bitbucket should be there now

upload the key to bitbucket

  • copy: cat ~/.ssh/
  • create bitbucket key at:{repo_name}/admin/access-keys/
  • create github ket at:

get the code

cd ~/apps
git clone{site_name}.git
cd {site_name}
git status
gem install bundler
bundle install

configure environment variables

  • get the output from rails secret
  • create file at /config/application.yml with the following:
  SMTP_PASSWORD: 3lf!naha7
  SECRET_KEY_BASE: <<output from `rails secret`>>

build the database

create a database user

sudo -u postgres createuser {db_user} -P

grant create db permission bash sudo -u postgres psql postgres postgres=# ALTER USER {db_user} CREATEDB; postgres=# \q

create config/database.yml

use this example or copy one from a fresh generation for a current version of rails:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000
  host: localhost

  <<: *default
  database: {database_name}
  username: {db_user_from_last_step}
  password: {db_password_from_last_step}

generate the database

RAILS_ENV=production rails db:setup

configure the nginx host

  • create a file at /etc/nginx/sites-available/{site_name} with the following:
server {
  listen 80 default_server;
  server_name {site_name};
  passenger_enabled on;
  passenger_app_env production;
  root /home/ubuntu/apps/{site_name}/public;
  • enable the new site sudo ln -s /etc/nginx/sites-available/{site_name} /etc/nginx/sites-enabled/{site_name}

  • retart nginx sudo service nginx restart

compile assets

there does not appear to be a javascript runtime installed on ubuntu. nodejs is installed (apt list | grep nodejs to confirm) but ruby doesn't seem to have access to it. - remove gem coffee-rails from the gemfile because we never use it anyhow. - bundle install and bundle list to make sure it's gone

RAILS_ENV=production rails tmp:cache:clear
RAILS_ENV=production rails assets:clobber
RAILS_ENV=production rails assets:precompile

app specific tasks


  • connect ssh -i "~/Development/rails/brainpad.pem"
  • edit /etc/nginx/nginx.conf to include client_max_body_size 200M; under the 'basic settings' section.
  • retart nginx sudo service nginx restart


  • connect ssh -i "~/Development/rails/brainpad.pem"
  • had to install libxml2 with sudo apt install libxml2 to get the libxml-ruby gem installed which is needed by the twilio-ruby gem