Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Latest commit

 

History

History
154 lines (108 loc) · 5.24 KB

setup.md

File metadata and controls

154 lines (108 loc) · 5.24 KB

App Setup

Dependencies

  • Ruby 2.3.5
  • PostgreSQL 9.x
  • Elasticsearch 1.5+
  • A cloud.gov account
  • An SMTP server (production mode only)

Installation

C2 is a fairly typical Rails application, so the setup is straightforward:

  1. If you're installing on a development machine, we recommend using rbenv to manage your Ruby environment, especially since we've had problems with rvm. On a Mac, you can use Homebrew to install it (along with ruby-build).

    brew install rbenv postgresql
    rbenv init
    rbenv install 2.3.5
    gem install bundler
    bundle
  2. Run the setup script to create a user record for your email address, make that user an admin, and add a few records for that user.

    git clone https://github.com/18F/C2.git
    cd C2
    
    # Will print "DONE" if successful. NOTE: This will delete any existing records in your C2 database and add a few seed records.
    ./script/bootstrap YOUR_EMAIL@gsa.gov
  3. Per the Twelve-Factor guidelines, all necessary configuration should be possible through environment variables. (See .env.example for the full list.)

    Your configuration will go in the .env file that the bootstrap script creates. .env.example exists as an example.

  4. Register an application on cloud.gov.

    • Give the application a Name that gives cloud.gov admins a good idea of what it is and who set it up; e.g. c2-prod. Optionally create multiple instances: c2-prod, c2-staging, c2-dev, for example.
    • Set the Url field to the URL for your setup. If you're running the app locally, the default URL is http://localhost:3000/
    • Set the Redirect uri field to [your_C2_url]/auth/cg/callback . For example, with the default URL: http://localhost:3000/auth/cg/callback
  5. Once you've registered the application, cloud.gov will give you two consumer key strings for saving: the App ID and App Secret. Add these to your .env, setting CG_APP_ID to the App ID and CG_APP_SECRET to the App Secret.

  6. To test locally, you need to use fake-cloud.gov:

    • Download the binary for cg-fake-uaa
    • From the directory your binary is in, run chmod +x cg-fake-uaa
    • Run the binary, passing it the correct URL for your local instance's callback: ./cg-fake-uaa -callback-url http://localhost:3000/auth/cg/callback
    • When cg-fake-uaa is run it will print an OAuth2 authorize URL and a token URL. In your C2 .env file, add these as CG_URL and CG_TOKEN_URL respectively. (Note: At time of writing, using the full token URL suggested by cg-fake-uaa will cause errors when trying to log in with C2. For the moment, set CG_TOKEN_URL to just http://localhost:8080/ (or whichever port cg-fake-uaa is using)

    The fake version simply asks for an email address and redirects that email address back to your callback. It does not look like the actual cloud.gov login flow.

Troubleshooting

Can't create or connect to database

  • Check that PostgreSQL is running
  • Set the DATABASE_URL variable in .env to match your setup

Can't create or connect to Elasticsearch

  • To install a compatible Elasticsearch locally:
brew install elasticsearch@2.4
  • Note the TEST_CLUSTER_COMMAND in .env.example, you may need to un-comment it before tests will run.
  • Check that Elasticsearch is running (default is localhost:9200)
  • Set the ES_URL variable in .env to match your setup

If 'foreman' command not found, you may be using rbenv. If so, run the following...

rbenv rehash
gem install foreman

Starting the application

./script/start
open http://localhost:3000

Populating with data

The bootstrap script you ran during installation creates a user record for the email address passed in (which should be yours), makes that user an admin, and creates relevant records for that user.

If you'd like to generate more records, you can run the following rake task:

bin/rake populate:ncr:for_user[YOUR_EMAIL@gsa.gov]

Now you should see 25 pending purchase requests at http://localhost:3000/proposals.

Viewing the mailers

As emails are sent, they will be visible at http://localhost:3000/letter_opener.

If you are working on an email mailer/template, you can view all of them at http://localhost:3000/rails/mailers.

Running tests

PhantomJS

You will need to install PhantomJS and have it in your PATH. This is used for javascript and interface testing.

brew install phantomjs

Running the entire suite once

rake db:test:prepare
./bin/rake

Running tests as corresponding files are changed

bundle exec guard

Checking for security vulnerabilities

gem install brakeman
brakeman

or just visit the project on Gemnasium.

Re-indexing search

rake search:import NPROCS=2 FORCE=y