Skip to main content
Skip table of contents

Native Setup - vets-api

Introduction

This doc details how to run the rails app in a native fashion (vs running via a docker based setup)

Developer Setup

Vets API requires:

  • Ruby 3.2.2

  • PostgreSQL 11.x (including PostGIS 2.5)

  • Redis 5.0.x

    The most up-to-date versions of each key dependency will be specified in the docker-compose.yml file and the Dockerfile.

    We suggest using a Ruby version manager such as rbenvasdfrvm, or chruby to install and maintain your version of Ruby.

Base Setup

  1. Follow the common base setup.

  2. Install Bundler to manage dependencies

    CODE
    gem install bundler
  3. Follow the platform specific notes below for OSX or Ubuntu to get dependencies installed.

  4. Install gem dependencies:

    CODE
    cd vets-api; bundle install

    More information about installing with Sidekiq Enterprise as well as our credentials are on the internal system here

  5. Install overcommit

    CODE
    overcommit --install --sign
  6. Make sure you have the vets-api-mockdata repo locally installed, preferably in a sibling directory to vets-api.

  7. Go to the file config/settings/development.yml and make sure the cache-dir points to the local installation of vets-api-mockdata from the previous step.

    CODE
    cache_dir: ../vets-api-mockdata # via rails; e.g. bundle exec rails s or bundle exec rails c
    # cache_dir: /cache # via docker; e.g. make up or make console
  8. Add this key in config/settings.local.yml pointing to your vets-api-mockdata directory.

    CODE
    # settings.local.yml
    betamocks:
      cache_dir: ../vets-api-mockdata
  9. Run bin/setup to setup the database and start the server.

pg_stat_statements

If you have trouble enabling query stats from the PgHero dashboard, try enabling it manually

Add the lines below to your main postgresql.conf file

On Mac it should be located somewhere similiar to the following:

~/Library/Application Support/Postgres/var-12/postgresql.conf

CODE
shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.track = all
pg_stat_statements.max = 10000
track_activity_query_size = 2048

Make sure to migrate your database to enable the pg_stat_statements extension

Settings and configuration

We use the config gem to manage settings in the application. Local settings for each developer should be managed in your own local config/settings.local.yml file, which by default can override the standard configuration and is excluded from source control so the settings can persist.

This file has the necessary configuration settings for local development as well as comments outlining some additional configuration that some developers may wish to use.

Configuring ClamAV antivirus

BRD

In many cases, there in no need to run ClamAV for local development, even if you are working with uploaded files since the scanning functionality is already built into our CarrierWave and Shrine file upload base classes.

If you would like to run a fake ClamAV "scanner" that will quickly produce a virus-free scan, you can configure the application to use the executable bash script bin/fake_clamd. This configuration is commented out in config/settings.local.yml

CODE
binaries:
  # For NATIVE and DOCKER installation
  # A "virus scanner" that always returns success for development purposes
  # NOTE: You may need to specify a full path instead of a relative path
  clamdscan: ./bin/fake_clamdscan

If you wish to run ClamAV, you'll need to check the platform specific notes.

EKS

Prior to EKS, ClamAV (the virus scanner) was deployed in the same process as Vets API. With EKS, ClamAV has been extracted out into it’s own service. Locally you can see the docker-compose.yml config for clamav here. To run this locally, just run the make up command (see Makefile).

Platform Specific Notes

Specific notes for our most common native installation platforms are in this section. Note that most Windows users tend to use Docker instead of a native installation.

OSX

All of the OSX instructions assume homebrew is your package manager

  1. Install Redis

    • brew install redis

  2. Install Postgresql & PostGIS

    • It is MUCH easier to use the Postgres.app which installs the correct combination of Postgresql and PostGIS versions.

    • Download the Postgres.app with PostgreSQL 10, 11 and 12

    • Install Instructions here: https://postgresapp.com/

    • sudo mkdir -p /etc/paths.d && echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp

    • ARCHFLAGS="-arch x86_64" gem install pg -v 1.2.3

    • Alternatively Postgresql 11 & PostGIS 2.5 can be installed with homebrew

      • brew install postgresql@11

      • brew services start postgresql@11

      • Install the pex manager to add your Postgresql 11 extensions from here

      • Install the postgis extension along with a number of patches using the instructions summarized here:

      • CODE
         PG_CPPFLAGS='-DACCEPT_USE_OF_DEPRECATED_PROJ_API_H -I/usr/local/include' CFLAGS='-DACCEPT_USE_OF_DEPRECATED_PROJ_API_H -I/usr/local/include' pex install postgis
  3. Install ImageMagick

    • brew install imagemagick

  4. Install Poppler

    • brew install poppler

  5. Install ClamAV or use the fake scanner for development

    CODE
    brew install clamav # Take note of the the post-install instructions "To finish installation & run clamav you will need to edit the example conf files at `${conf_files_dir}`", which will be displayed as part of the installation process. Recent installations have been to `/usr/local/etc/clamav/`
    cd ${conf_files_dir}
    touch clamd.sock
    echo "LocalSocket ${conf_files_dir}" > clamd.conf
    echo "DatabaseMirror database.clamav.net" > freshclam.conf
    freshclam -v

    NOTE: Run with /usr/local/sbin/clamd -c /usr/local/etc/clamav/clamd.conf and you will also have to override (temporarily) the config/clamd.conf file with -LocalSocket /usr/local/etc/clamav/clamd.sock

  6. Install pdftk

    • curl -o ~/Downloads/pdftk_download.pkg https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg

    • sudo installer -pkg ~/Downloads/pdftk_download.pkg -target /

  7. continue with Base setup

Alternative (Ubuntu 20.04 LTS)

  1. Install Postgres and enable on startup

    CODE
    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
    echo "deb http://apt.postgresql.org/pub/repos/apt/ focal"-pgdg main | sudo tee  /etc/apt/sources.list.d/pgdg.list
    sudo apt update
    sudo apt install postgresql-11
    sudo systemctl start postgresql
    
    sudo -i -u postgres
    createuser --superuser YOURNAME
    exit
  2. Install PostGIS

    CODE
    sudo apt install -y postgresql-11-postgis-2.5
    sudo -i -u postgres
    
    createuser postgis_test
    createdb postgis_db -O postgis_test
    psql -d postgis_db
    
    CREATE EXTENSION postgis;
    SELECT PostGIS_version();
    \q
  3. Install Redis

    CODE
    sudo apt install -y redis-server
    sudo sed -i 's/^supervised no/supervised systemd/' /etc/redis/redis.conf
    sudo systemctl restart redis.service
    sudo systemctl status redis # ctrl+c to exit
  4. Install ImageMagick

    • sudo apt install -y imagemagick

  5. Install Poppler

    • sudo apt install -y poppler-utils

  6. Install ClamAV

    • sudo apt install -y clamav

  7. Install pdftk

    • sudo apt install -y pdftk

  8. continue with Base setup


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.