Skip to content

Set Up Local Dev Environment

tom meagher edited this page May 2, 2019 · 15 revisions

Install tools and dependencies (via homebrew):

> /usr/bin/ruby -e "$(curl -fsSL <https://raw.githubusercontent.com/Homebrew/install/master/install>)"
> brew tap homebrew/bundle
> brew bundle

Next, create a local Postgres database:

  1. Open postgres.app (just installed via brew)
  2. Open postico.app
  3. Create a database, named butter, through positico

Add environment variables:

# DJANGO APP KEYS

export DJANGO_ENV=dev
export DJANGO_DB_NAME=butter # database you just created
export DJANGO_DB_USER=tom # this is likely the user you use to login to your computer
export DJANGO_DB_PASSWORD=root
export DJANGO_DB_HOST=docker.for.mac.localhost # special docker set up
export DJANGO_DB_PORT=5432
export DJANGO_SECRET_KEY=+cg9iso$a55f3ay&)pdg3k&=lq_c*55j7oyuib=a(pi#2$oj^0

# PLAID APP KEYS

export PLAID_CLIENT_ID=5b9b1df200123c4672353c2c
export PLAID_PUBLIC_KEY=5f198f5da4f3be8da6ecaaadbdfd58
export PLAID_SECRET=5ea62a857d2361250eb7ed9358133c
export PLAID_ENV=sandbox

# REACT APP KEYS (Set in docker-compose.yml)

export REACT_APP_NGROK_ID=
export REACT_APP_PLAID_ENV=
export REACT_APP_PLAID_PUBLIC_KEY=

# NGINX

export SSL_CERTIFICATE=/etc/nginx/certs/butter.crt
export SSL_CERTIFICATE_KEY=/etc/nginx/certs/butter.key

If nginx/certs/local is empty, you need to generate a self-signed certificate.

  1. Go to zerossl.com.
  2. You should enter butter.local and *.butter.local.
  3. Download the key and certificate, and rename them: key.txt to butter.key and crt.txt to butter.crt. Move the files to a nginx/certs/local.

Update /etc/hosts by adding:

0.0.0.0 butter.local api.butter.local www.butter.local

Snag the repo, start Docker, and build the containers:

> git clone --recursive https://github.com/butterso/butter.git # grabs git submodules too
> cd butter
> docker-compose build

Apply database migrations, create superuser, and generate static files (for admin console, etc.):

> docker-compose run api python manage.py makemigrations
> docker-compose run api python manage.py migrate
> docker-compose run api python manage.py createsuperuser
> docker-compose run api python manage.py collectstatic
> docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q) # stop and remove all running containers

If everything worked as planned, you can fire everything up with docker-compose up:

> docker-compose up -d
> docker-compose ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                  PORTS                                      NAMES
6c2e871834bf        butter_nginx        "bash -c 'envsubst <…"   7 seconds ago       Up Less than a second   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   nginx
f427d34b5351        butter_api          "uwsgi --ini uwsgi.i…"   7 seconds ago       Up 6 seconds            8000/tcp                                   api
c4be8e628d86        butter_web          "uwsgi --ini uwsgi.i…"   7 seconds ago       Up 6 seconds            5000/tcp                                   web

And access the admin site or the actual site, butter.local.

🎉

If your browser blocks you from navigating to the site, you need to add butter.crt to System keychain (using keychain.app) and set Get Info > Trust > Secure Sockets Layer (SSL) to Always Trust.

You can also grab the certificate for use with cURL:

> echo quit | openssl s_client -showcerts -servername butter.local -connect butter.local:443 > nginx/certs/dev/butter.pem
> curl --cacert nginx/certs/dev/butter.pem https://api.butter.local/v1/

https://stackoverflow.com/questions/27611193/use-self-signed-certificate-with-curl

Clone this wiki locally