Skip to content
forked from john/drive.vote

Drive the Vote arranges free rides to the polls on election day.

Notifications You must be signed in to change notification settings

jbizzle/drive.vote

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

Master: CircleCI Production: CircleCI

Drive the Vote helps people arrange free rides to the polls on election day. It consists of:

  • A text-based interface for voters to request rides on-demand--no smartphone required!
  • A scheduling app, so either voters or volunteers can pre-schedule rides.
  • An app for dispatchers to monitor voters and volunteer drivers in real-time.
  • A location-aware app for drivers, to notify them when a nearby voter has requested or scheduled a ride.

Here's what the Philadelphia dispatch and driver apps looked like on election morning 2016:

DtV screenshots

Running the app

Check out the repo

  1. git clone git@github.com:john/drive.vote.git
  2. cd drive.vote

Option 1: run with Docker (recommended)

  1. Install docker.
  2. Run docker-compose up. This will start three containers: one for postgres, one for redis and one that runs rails + the webpack dev server.
  3. On the first run, or after a schema or seed-data change, run docker-compose exec web bundle exec rails db:create db:schema:load db:seed to setup the database.
  4. To shut down the DtV containers: docker-compose stop

Your current directory will be mounted into the docker instances so changes to the files should go live immediately without restarting the environment. If you need to restart the rails server, just run docker-compose up again.

To get a bash shell on the current docker instance, run:

docker-compose exec web bash -l

To get a Rails console on the current docker instance, run:

docker-compose exec web bundle exec rails console

Option 2: run directly

  1. Create a .env file in the app root and add these variables, with the correct values for your local env:
  REDIS_URL=redis://localhost:6379
  SECRET_KEY_BASE=xxxxxxx
  1. Install postgresql
  2. Install Redis (to run: redis-server /usr/local/etc/redis.conf)
  3. Install bundler: gem install bundler
  4. Install gems: bundle install
  5. Run rake pg:first_run on the first run, and rake pg:start for subsequent runs to start the DB
  6. To set up the db: rake db:create; rake db:migrate; rake db:seed.
  7. bundle exec rails webpacker:install (I think?)
  8. Run bundle exec rake foreman:dev to start the server in dev mode. You can check Procfile.dev to see the servers this starts.

For production, instead of foreman:dev, run

  1. rake assets:precompile
  2. rake foreman:prod

If you don't want to use foreman, you have to run the rails server (Puma) and the webpack server in separate terminals: bundle exec rails server and bundle exec ./bin/webpack-dev-server, respectively.

Running specs

bundle exec rake spec executes all tests in the spec directory. Run locally before committing, the app won't deploy if specs don't pass.

Continuous deployment

When code is merged into master, CircleCI triggers an automatic deployment to https://dev.drive.vote. To deploy to production at https://drive.vote, merge master into the production branch.

Running the app locally

To use sms features, you need to create a .env file in the root app directory and add these env vars:

TWILIO_SID=xxxx
TWILIO_TOKEN=yyyy

You then need to create a Twilio number with sms capabilities, and update a the ride zone you want to work with to use it.

For features that send emails, run MailHog or MailCatcher locally. The development environment is configured to send email to the correct port. On macOS you can use brew to install and run Mailhog:

brew update && brew install mailhog
brew services start mailhog

Once started you can view the Mailhog client at http://localhost:8025/

(Note: it was previously recommended to alias local.drive.vote in your local /etc/hosts, but browser security has tightened, and Chrome, for one, disallows geolocation services on non-secure hosts. There is an exception for localhost, however.)

Go to http://localhost:3000 and log in as the generic admin with email seeds@drive.vote and password 1234abcd. Since this account has admin privileges, logging in with it takes you directly to the admin site. If it has only driver privileges, it would take you to the driver app, and if only dispatcher privileges, to the dispatch page for the ride zone attached to your account. If for some reason your account has no privileges at all, you'll end up at the homepage, but that shouldn't happen.

Useful URLs:

Note: browsers block geolocation APIs on http:// (insecure) websites except localhost. If you're working on features that require geolocation, such as /driving, you'll need to access the application at http://localhost:3000/.

Spoofing location in the browser

https://www.labnol.org/internet/geo-location/27878/ ?

Deployment

Setup

Config

You'll need to create these env vars: GOOGLE_API_KEY TWILIO_SID TWILIO_TOKEN SEND_GRID_USER_NAME SEND_GRID_PASSWORD

Deployment setup: Preparing for manual deployment

Code is typically deployed automatically, this documents manual deployment. Code is deployed using AWS Elastic Beanstalk CLI tool which is a python script. To execute a deploy, configure a python virtualenv, and run the Elastic Beanstalk CLI tool from there.

Deployment setup: Install virtualenv

  1. Install pip if it isn't there. If you're using macOS, it's likely already installed.
  2. Install virtual env. sudo pip install virtualenv

Deployment setup: Create a venv in your checkout.

This creates a directory named venv which is a little self-consistent Python sandbox that you can install packages into without being root.

  1. virtualenv venv
  2. pip install -r requirements.pip

Each time you want to use the venv, run this in your terminal: source venv/bin/activate. You'll see the name of the current virtual env to the left of the prompt, eg, (venv) Your-computer: > .

Activate a venv to run DtV eb commands and rake deployment tasks.

Deployment setup: Creating a new Elastic Beanstalk environment

This is to stand up an entirely new environment, it's done infrequently and generally you don't have to worry about it.

If you define profile sections in your ~/.aws/credentials file for drivevote.prod (or dev), then you can set the AWS_EB_PROFILE env var before calling the following command in order to use the right set of credentials. Open a termal, start a venv, and run:

RAILS_ENV=production NODE_ENV=production  AWS_EB_PROFILE=drivevote.prod eb create drivevote-prod -db -p 'Ruby 2.3 (Puma)' -db.engine postgres -db.i db.t2.micro -i t2.micro --elb-type application -k aws-eb -r us-west-2 -db.user drivevoteprod --envvars SECRET_KEY_BASE=[somesecret],RAILS_SKIP_ASSET_COMPILATION=true,DTV_ACTION_CABLE_ORIGIN=www.drive.vote,PAPERTRAIL_HOST=logs4.papertrailapp.com,PAPERTRAIL_PORT=46774

This will configure the main web environment and database. After this, open up the RDS console to find the newly created database. Use the values there for [endpoint] in the command below in order to configure the database access. This is because Elastic Beanstalk has no sane way of sharing an RDS instance between envrionments (wtf?).

RAILS_ENV=production NODE_ENV=production  AWS_EB_PROFILE=drivevote.prod eb create drivevote-prod-worker -t worker -p 'Ruby 2.3 (Puma)' -s -k aws-eb -r us-west-2  --envvars "SECRET_KEY_BASE=$(rake secret),RAILS_SKIP_ASSET_COMPILATION=true,DTV_IS_WORKER=TRUE,PAPERTRAIL_HOST=logs4.papertrailapp.com,PAPERTRAIL_PORT=46774,RDS_DB_NAME=ebdb,RDS_HOSTNAME=[endpoint],RDS_PASSWORD=[password],RDS_USERNAME=drivevoteprod,DTV_ACTION_CABLE_ORIGIN=worker-[origin-for-papertrail-logging]"

Next, fix the RDS security group to allow writes from the worker. Open up the RDS console for the EB instance and modify its securtiy group's incoming rules to allow access from the worker.

Finally, do a deploy via

RAILS_ENV=production NODE_ENV=production  AWS_EB_PROFILE=drivevote.prod rake deploy:prod

to ensure the javascript bundle is built.

And finally, you need to update the enviornment to handle https with something like

aws elasticbeanstalk --profile drivevote.prod update-environment --environment-name drivevote-prod --option-settings file:///Users/awong/src/DevProgress/drive.vote/elb-prod-acm.json  --region us-west-2

Deploying code

Deploying: Run your elastic beanstalk commands

Per above make sure you have aws profiles defined in ~/.aws/credentials.

Command Description
rake deploy:dev Deploys to the dev environment in .elasticbeanstalk/config.yml from HEAD (yes! the last commit! not necessarily what's on your filesystem!). Command blocks until deploy is finished.
RAILS_ENV=production NODE_ENV=production rake deploy:prod Deploys to the prod environment in .elasticbeanstalk/config.yml from HEAD (yes! the last commit! not necessarily what's on your filesystem!). Command blocks until deploy is finished. Ensure rails and node to run in production mode so the webpack bundle is built with optimizations.
eb printenv Prints environment variables the running app is currently figured with. Warning: has secrets. All people that can deploy can see the secrets.
eb setenv A=1 B=2 Sets new environment variables. This will restart the webservers so combine multiple variable updates on one line. Command blocks until deploy is finished.

Contributing

  1. Fork it
  2. Create your feature branch: git checkout -b my-new-feature
  3. Follow rails core team coding conventions
  4. Provide test coverage/specs for your changes, and make sure all specs pass: bundle exec rake
  5. Commit your changes: git commit -am 'Add some feature'
  6. Push upstream: git push origin my-new-feature
  7. Create new Pull Request
  8. Request a code review
  9. After review and approval, merge your own work to master

License

This software is released under the MIT License. See the LICENSE.md file for more information.

About

Drive the Vote arranges free rides to the polls on election day.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 53.2%
  • HTML 25.8%
  • JavaScript 11.8%
  • CSS 8.3%
  • Python 0.5%
  • Shell 0.3%
  • Dockerfile 0.1%