lukeaus / stockspot-demo

Technical test for Stockspot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get started

Get latest docker & docker-compose first:

https://www.docker.com/

https://docs.docker.com/compose/

Next

./bin/setup.sh

Stop

control + c If you get impatient after waiting more than 30 seconds, press control + c again (and again)

Start the server again

./bin/develop.sh

Urls

Don't forget the trailing backslash

Django Admin

http://0.0.0.0:8000/admin/

API

http://0.0.0.0:8000/api/

Frontend

Please give this a while to boot up. Make sure you wait til webpack_dev is listening. http://0.0.0.0:8000

Testing

Backend

./bin/django.sh test

Frontend

./bin/npm.sh run test

Troubleshooting

Inconsistent database state

Shut down all existing containers for this app using control-c

Then run this

./bin/django.sh reset_db
./bin/setup.sh

Boilerplate kindly provided by https://github.com/domasx2/docker-django-webpack-starter.git with some hacks to get it running!

docker-django-webpack-starter

This is a starter project for a django app with webpack built frontend that uses docker for dev enironment. Docker and docker-compose is all you need to develop, build & deploy, run development or production mode with a single command.

stack

python 3.5 node 5.10 Postgres 9.5 Django 1.10.5 Webpack Stylus Nginx Gunicorn

get started

Get latest docker & docker-compose: https://www.docker.com/ https://docs.docker.com/compose/

Pull seed to your project:

git init
git remote add starter https://github.com/domasx2/docker-django-webpack-starter.git
git pull starter master

Start dev server:

./bin/develop.sh

Wait for docker to set up container, then open http://localhost:8000

production mode

# build production images, create db backup & start
./bin/deploy.sh

# stop server
./bin/stop_production.sh

# start srever
./bin/start_production.sh

In prod mode sources are added to docker image rather than mounted from host. Nginx serves static files, proxy pass to gunicorn for django app. Logs in logs dir.

enable ssl

Copy your .key and .crt files to nginx/ssl and run ./bin/deploy.sh.

install dependencies

# frontend
./bin/npm.sh install [package] --save-dev

# backend
./bin/pipinstall.sh [pacakge] #will also add entry to backend/requirements.txt

backup & restore database

# create a backup in backups dir
./bin/backup.sh

# restore from a backup in backups dir (server must be stopped)
./bin/restore.sh backups/somebackup.bak

run django management commands

#dev mode
./bin/django.sh [command]

#create migration
./bin/django.sh makemigrations myapp

#prod mode
./bin/django_prod.sh [command]

#start django shell in prod mode
./bin/django_prod.sh shell

layout

bin/                          - various utility scripts

docker-compose.yml            - base docker compose config
docker-compose.overrides.yml  - development docker compose config
docker-compose.production.yml - production docker compose config

frontend/                     - frontend stuff
frontend/package.json         - npm package file with frotnend dependencies
frontend/src/js/              - javascript code
frontend/src/js/index.js      - js entry point. include other js deps here
frontend/src/style/           - stylesheets
frontend/src/style/index.styl - stylesheet entry point. include other styl files here

backend/                      - backend stuff
backend/apps/                 - django apps
backend/conf/                 - django settings files
backend/conf/settings.py      - default config
backend/conf/settings_prod.py - production config
backend/templates/            - django global templates
backend/requirements.txt      - python dependencies
backend/gunicorn.conf.py      - gunicorn conf for production
backend/media/                - user uploads

logs/                         - in prod mode app, gunicorn, nginx, postgres logs go here
nginx/                        - nginx stuff for prod mode
nginx/ssl/                    - put key & cert here if you use ssl
nginx/nginx_nossl.conf        - nginx conf if no ssl is used
nginx/nginx_ssl.conf          - nginx conf for deploy with ssl

tests

For e2e tests, use app.testutils.SeleniumTestCase class it comes with chrome driver configure at self.driver. See apps.home.tests for an example. See http://selenium-python.readthedocs.io/ for selenium driver api

#run tests
For some reason the command ./bin/test.sh is not working as documented
./bin/test.sh

# skip frontend build (eg, running tests repeatedly)
./bin/test.sh --skipbuild


To debug tests it's possible to vnc into selenium container while its running at localhost:5900 and view the browser. Password is `secret`.

```sh
sudo apt-get install vinagre # vnc client

vinagre localhost:5900

About

Technical test for Stockspot


Languages

Language:Python 63.1%Language:JavaScript 26.5%Language:Shell 8.3%Language:CSS 1.2%Language:HTML 1.0%