Skip to content
Sergio Marrocoli edited this page Sep 12, 2022 · 6 revisions

Deploying with capistrano

This has been tricky, and you need to complete several steps to do this:

  • rvm must be installed in your home folder (see "Single-User Install Location: ~/.rvm/" [https://rvm.io/rvm/install])
  • you need the secret_key_base in your .env

Apart from this you can try cap staging deploy and overcome errors one-by-one, e.g.:

  • Javascript error: install nodejs
  • database password error: change authentication methd to trust in the pg_hba.conf for your Postgres version (see "Example 21.1. Example pg_hba.conf Entries" [https://www.postgresql.org/docs/current/auth-pg-hba-conf.html])

please add other issues and solutions is you encounter them.

Nginx

We are using nginx as our webserver in conjunction with (phusion passenger)[https://www.phusionpassenger.com/] to serve Rails applications.

Files downloads

This application can serve very large CSV files, which when done with Ruby on Rails can cause memory leakage. Because of this we have decided to serve these files via nginx.

This required adding the following to the configuration of the site-available for the app:

passenger_set_cgi_param HTTP_X_ACCEL_MAPPING /home/rails/sapi/shared/public/downloads/=/downloads/;
passenger_pass_header X-Accel-Redirect;

location ~ ^/downloads/(.*)$ {
  alias /home/rails/sapi/shared/public/downloads/$1;
  internal;
}

And enabling the following option in both the staging and production environments in the app.

config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

CORS

CORS is used (for now) in the Checklist, which enables it to be deployed separately from the API backend.

For now we use the rack-cors middleware for the development environment:

http://blog.carbonfive.com/2012/02/27/supporting-cross-domain-ajax-in-rails-using-jsonp-and-cors/

Staging and production environments have the appropriate headers defined in Apache config:

<VirtualHost *:80>
  Header set Access-Control-Allow-Origin *
  Header set Access-Control-Allow-Methods "POST, GET, OPTIONS"
  Header set Access-Control-Allow-Headers "X-Requested-With, X-Prototype-Version"
  Header set Access-Control-Max-Age 1728000
  ...

Nginx:

server {
  add_header 'Access-Control-Allow-Origin' *;
  add_header 'Access-Control-Allow-Methods' "GET, POST, PUT, DELETE, OPTIONS";
  add_header 'Access-Control-Allow-Headers' "X-Requested-With, X-Prototype-Version";
  add_header 'Access-Control-Max-Age' 1728000;
  ....

Gems

Gems are packaged, following this article:

http://ryan.mcgeary.org/2011/02/09/vendor-everything-still-applies/

Job queue

  1. start redis redis-server
  2. start sidekiq bundle exec sidekiq
  3. create new download job curl --data "output_layout=alphabetical&level_of_listing=0&show_synonyms=1&show_english=1&show_spanish=1&show_french=1&scientific_name=pediocactus&page=0&per_page=20&locale=en&download[format]=pdf&download[doc_type]=index" http://localhost:3000/downloads

response: {"downloads":[{"id":2,"doc_type":"index","format":"pdf","status":"working","created_at":"2012-10-30T11:44:21Z","updated_at":"2012-10-30T11:44:21Z"}]} 3. get status of job curl http://localhost:3000/downloads/2

response: {"status":"completed"}

TODO

  • which directories need to be set up for the downloads / uploads to work
  • which workers need to by running and what for
  • which config is needed for the Checklist to connect to the right backend