Drive the Vote arranges free rides to the polls on election day.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.circleci get circleci to refer to latest tagged image Sep 6, 2018
.ebextensions Merge branch 'master' into websocket-upgrade Oct 19, 2016
.elasticbeanstalk Fix deploy to handle worker tier. Update docs. Oct 25, 2016
app Merge branch 'master' of github.com:john/drive.vote into schedule_and… Sep 22, 2018
bin Midterms reboot. Webpack updates to get it running Aug 9, 2018
config Merge branch 'master' of github.com:john/drive.vote into schedule_and… Sep 22, 2018
data Issue #140 scaled simulation using parallel threads Sep 2, 2016
db Merge branch 'master' of github.com:john/drive.vote into schedule_and… Sep 22, 2018
docs update copy, rename 'doc' to 'docs' Sep 18, 2018
lib update gems, add bunder-audit Oct 8, 2016
log First commit (fb login) Jun 22, 2016
public Disable Philadelphia volunteer, fix select width Nov 5, 2016
spec Merge branch 'master' of github.com:john/drive.vote into schedule_and… Sep 22, 2018
tmp First commit (fb login) Jun 22, 2016
vendor/assets First commit (fb login) Jun 22, 2016
.babelrc WIP Setup Jest snapshot testing Sep 11, 2018
.dockerignore Set up docker development environment. Sep 28, 2016
.eslintrc.js WIP Setup Jest snapshot testing Sep 11, 2018
.foreman Integrate skeletal webpack-rails into build. Sep 12, 2016
.gitignore Ruby to 2.5.1, new Dockerfile to alpine3.7 Aug 12, 2018
.prettierignore WIP, update depndencies and config tweaks Aug 17, 2018
.rspec First commit (fb login) Jun 22, 2016
.ruby-gemset Using rvm, with .ruby-version also need .ruby-gemset Aug 8, 2016
.ruby-version update ruby version Aug 16, 2018
.travis.yml add env var to .travis.yml Mar 17, 2017
Dockerfile Upgrade city-state gem Sep 6, 2018
Gemfile remove sendgrid gem, move email conf up Sep 19, 2018
Gemfile.lock remove sendgrid gem, move email conf up Sep 19, 2018
Procfile Integrate skeletal webpack-rails into build. Sep 12, 2016
Procfile.dev webpack-dev-server on https Apr 1, 2017
README.md Scheduled ride email, MailHog Sep 8, 2018
Rakefile fix webpacker compile task, hp copy Aug 22, 2018
app.json Squashed chatty app.json Aug 6, 2016
config.ru First commit (fb login) Jun 22, 2016
cron.yaml Add crontab for worker tier in dev. Oct 24, 2016
deploy.sh Fix deploy to handle worker tier. Update docs. Oct 25, 2016
docker-compose.yml Scheduled ride email, MailHog Sep 8, 2018
eb-shell.sh Add helper script for accessing rails console. Sep 27, 2016
elb-dev-acm.json Make dev deploy based with commit to master Sep 28, 2016
elb-prod-acm.json Use aws CLI instead of eb to update ssl config. Sep 21, 2016
package.json Test app reducer state Sep 20, 2018
requirements.pip Add instructions for elastic beanstalk. Sep 8, 2016
yarn.lock Add testing for async utilities and actions Sep 20, 2018

README.md

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; cd drive.vote
  2. cd drive.vote

Docker

  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. If necessary, run docker-compose exec web bundle exec rails db:create db:schema:load db:seed to setup the database. You'll need to do this on first run.
  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 envrionment. 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

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)[https://github.com/mailhog/MailHog] or (MailCatcher)[https://mailcatcher.me/] locallly. 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/)[http://localhost:8025/]

It's recommended to create an entry in /etc/hosts for local.drive.vote, associated with 127.0.0.1. If you do, go to http://local.drive.vote:3000 to log in (or http://localhost:3000 if you don't). To log in as the generic admin use seeds@drive.vote as you login email, with 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.