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:
Running the app
Check out the repo
git clone email@example.com:john/drive.vote.git; cd drive.vote
- Install docker.
docker-compose up. This will start three containers: one for postgres, one for redis and one that runs rails + the webpack dev server.
- If necessary, run
docker-compose exec web bundle exec rails db:create db:schema:load db:seedto setup the database. You'll need to do this on first run.
- To shut down the DtV containers:
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
- Create a .env file in the app root and add these variables, with the correct values for your local env:
- Install postgresql
- Install Redis (to run:
- Install bundler:
gem install bundler
- Install gems:
rake pg:first_runon the first run, and
rake pg:startfor subsequent runs to start the DB
- To set up the db:
rake db:create; rake db:migrate; rake db:seed.
- bundle exec rails webpacker:install (I think?)
bundle exec rake foreman:devto start the server in dev mode. You can check Procfile.dev to see the servers this starts.
For production, instead of
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.
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.
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:
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
firstname.lastname@example.org 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.
- http://local.drive.vote:3000/admin -- Admin console Default page shows all dev Ride Zones.
- http://local.drive.vote:3000/dispatch/[slug] -- Dispatch app. The slug should correspond to the ride zone attached to the logged in user. Linked to for each ride zone from the admin page.
- http://local.drive.vote:3000/driving -- Driver app. It'll be connected to the Ride Zone the account is driving for. If this URL redirects to /, it means the account logging in isn't a driver.
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
Spoofing location in the browser
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
- Install pip if it isn't there. If you're using macOS, it's likely already installed.
- 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.
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
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: Run your elastic beanstalk commands
Per above make sure you have aws profiles defined in ~/.aws/credentials.
||Deploys to the dev environment in
||Deploys to the prod environment in
||Prints environment variables the running app is currently figured with. Warning: has secrets. All people that can deploy can see the secrets.|
||Sets new environment variables. This will restart the webservers so combine multiple variable updates on one line. Command blocks until deploy is finished.|
- Fork it
- Create your feature branch:
git checkout -b my-new-feature
- Follow rails core team coding conventions
- Provide test coverage/specs for your changes, and make sure all specs pass:
bundle exec rake
- Commit your changes:
git commit -am 'Add some feature'
- Push upstream:
git push origin my-new-feature
- Create new Pull Request
- Request a code review
- After review and approval, merge your own work to master
This software is released under the MIT License. See the LICENSE.md file for more information.