claudinec / demsausage

Democracy Sausage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Democracy Sausage

Installing and building

Requirements:

  • Docker 18.09.0+
  • Docker Compose 1.23.2+

First Time

If this is the first time you're running Democracy Sausage you'll need to:

Hosts file

Add the following to your hosts file.

127.0.0.1 public.test.democracysausage.org
127.0.0.1 admin.test.democracysausage.org

Generate self-signed SSL certs

Install mkcert and generate self-signed certs for local dev.

brew install mkcert
mkcert -install
mkdir keys && cd $_
mkcert public.test.democracysausage.org
mkcert admin.test.democracysausage.org

.env files

Use the template .env files in secrets-tmpl to create corresponding files under secrets/ for:

  1. sausage-web.dev.env
  2. sausage-web-db.dev.env
  3. sausage-db.dev.env
  4. sausage-public-frontend.dev.env
  5. sausage-admin-frontend.dev.env

Load data

If you're starting from scratch:

Load electoral boundaries data

Follow the instructions in data/federal_2019/electoral_boundaries/README.md to load in the 2019 Federal electoral boundaries.

Load production database dump

Alternatively, if you have access to the production database you can use the scripts in this repo to initialise your environment with its current state.

docker-compose up db

docker exec -i -t demsausage_db_1 /bin/bash
cd /var/lib/postgresql/scripts
./replace-dev-with-prod.sh

Admin Site

  1. Add yourself to the app_allowedusers table before trying to login
  2. Load initial_data/polling_place_facility_types.csv into app_pollingplacefacilitytype
  3. Create a test election for yourself and load some polling places into it via the UI (contact the project maintainers for a sample)

Run both sites

docker-compose up Then navigate to the URLs given below

Public site

Navigate to https://test.democracysausage.org

Admin site

Navigate to https://admin.test.democracysausage.org

Development

Browser Testing

Cross browser testing thanks to BrowserStack.

BrowserStack logo

Memcached

Memcached is used to cache public-facing API endpoints to lighten the load on the backend Django service. For debugging purposes we can retrieve a list of currently set memcached key by:

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' demsausage_memcached_1

telnet 172.27.0.5 11211

> Show general stats
stats

> Show all of the "slabs" in memcached (groups of keys)
stats slabs
STAT 18:chunk_size 4544
STAT 18:chunks_per_page 230
...

> Dump a list of all items stored in a given slab (in this case, slab 18)
stats cachedump 18 0
ITEM demsausage_:1:elections_list [4321 b; 0 s]

Deploy

  • AWS S3 hosts the Public and Admin sites.
  • CloudFlare sits in front and handles caching and gives us HTTPS.
  • Travis CI handles automatic deploys from GitHub for us.
  • Duck CLI to ftp sync the legacy PHP API.
  1. S3 bucket setup for static website hosting, bucket policy set to public, and error document set to index.html to let React Router work. 1.1 A second www.democracysausage.org bucket is setup to redirect requests to https://democracysausage.org
  2. CloudFlare just has default settings except for these Page Rules: 2.2 api.democracysausage.org/* Cache Level: Bypass 2.3 democracysausage.org/static/* Cache Level: Standard, Edge Cache TTL: A Month (Because S3 sends No Cache headers by default.) 2.3 democracysausage.org/icons/* Cache Level: Standard, Edge Cache TTL: A Month (Because S3 sends No Cache headers by default.)
  3. Travis CI setup with default settings to pull from .travis.yml with environment variables AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION, CF_ZONE_ID, CF_EMAIL, CF_API_KEY, FTP_USERNAME, FTP_PASSWORD, FTP_PATH, REACT_APP_MAPBOX_API_KEY_PROD
{
  "Version": "2012-10-17",
  "Id": "PublicBucketPolicy",
  "Statement": [
    {
      "Sid": "Stmt1482880670019",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::BUCKET_NAME_HERE/*"
    }
  ]
}

Encrypting Secrets for Travis

Per Travis-CI's documentation on encrypting multiple files containing secrets.

tar cvf secrets.tar secrets/travis.env secrets/demsausage-frontends.prod.env
travis encrypt-file --force secrets.tar

Resources

About

Democracy Sausage

License:MIT License


Languages

Language:TypeScript 73.8%Language:Python 20.9%Language:CSS 1.8%Language:HTML 1.1%Language:Shell 1.1%Language:JavaScript 0.9%Language:Dockerfile 0.2%Language:PHP 0.2%