-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #563 from lucyparsons/develop
OpenOversight 0.4.2
- Loading branch information
Showing
784 changed files
with
1,834 additions
and
44,740 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,7 @@ Use [PULL_REQUEST_TEMPLATE.md](/PULL_REQUEST_TEMPLATE.md) to create the descript | |
|
||
## Development Environment | ||
|
||
You can use our Docker or Vagrant/VirtualBox development environments. | ||
|
||
### Docker | ||
You can use our Docker-compose environment to stand up a development OpenOversight. | ||
|
||
You will need to have Docker installed in order to use the Docker development environment. | ||
|
||
|
@@ -39,61 +37,6 @@ $ docker exec -it openoversight_web_1 /bin/bash | |
|
||
Once you're done, `make stop` and `make clean` to stop and remove the containers respectively. | ||
|
||
### VirtualBox + Vagrant | ||
|
||
Our standard development environment is an Ubuntu 14 VM. We manage it with Vagrant, which means you'll need Vagrant and VirtualBox installed to start out. | ||
|
||
* Install Vagrant: https://www.vagrantup.com/downloads.html | ||
* Install VirtualBox: https://www.virtualbox.org/wiki/Downloads | ||
|
||
Make sure you've started VirtualBox, and then in your project directory, run: | ||
|
||
`vagrant up` | ||
|
||
This creates a new, pristine virtual machine and provisions it to be an almost-copy of production with a local test database. (Behind the scenes, this is all happening via the files in vagrant/puppet.) If everything works, you should get a webserver listening at `http://localhost:3000` that you can browse to on your host machine. | ||
|
||
In addition, you can now SSH into it: | ||
|
||
`vagrant ssh` | ||
|
||
The provisioning step creates a virtual environment (venv) in `~/oovirtenv`. If you will be running lots of python-related commands, you can 'activate' the virtual environment (override the built-in python and pip commands and add pytest and fab to your path) by activating it: | ||
```sh | ||
vagrant@vagrant-ubuntu-trusty-64:~$ source /home/vagrant/oovirtenv/bin/activate | ||
``` | ||
|
||
You can tell that your virtual environment is activated by seeing the addition of `(oovirtenv)` to your prompt: | ||
```sh | ||
(oovirtenv)vagrant@vagrant-ubuntu-trusty-64:~$ | ||
``` | ||
When this is done, you no longer need to preface python commands (as below) with `~/oovirtenv/bin`. | ||
|
||
In the VM instance, your code is copied to a folder inside of `/vagrant`, so you'll want to run this: | ||
```sh | ||
(oovirtenv)vagrant@vagrant-ubuntu-trusty-64:~$ cd /vagrant/OpenOversight | ||
``` | ||
|
||
*Note:* the photo upload functionality - which uses an S3 bucket - and the email functionality - which | ||
requires an email account - do not work in the development environment as they require some environment | ||
variables to be configured. | ||
|
||
## Server commands | ||
|
||
The app, as provisioned, is running under gunicorn, which means that it does not dynamically reload your changes. | ||
|
||
If you run the app in debug mode, you can see these changes take effect on every update, but certain changes will kill the server in a way some of us find really irritating. To do this: | ||
|
||
`vagrant ssh` (if you're not already there) | ||
```sh | ||
$ sudo service gunicorn stop | ||
* Stopping Gunicorn workers | ||
[oo] * | ||
(oovirtenv)vagrant@vagrant-ubuntu-trusty-64:~$ cd /vagrant/OpenOversight/ # (again, if you're not already there) | ||
(oovirtenv)vagrant@vagrant-ubuntu-trusty-64:/vagrant/OpenOversight$ python manage.py runserver | ||
* Running on http://127.0.0.1:3000/ (Press CTRL+C to quit) | ||
* Restarting with stat | ||
* Debugger is active! | ||
``` | ||
|
||
## Database commands | ||
|
||
You can access your PostgreSQL development database via psql using: | ||
|
@@ -105,16 +48,16 @@ psql -h localhost -d openoversight-dev -U openoversight --password | |
with the password `terriblepassword`. | ||
|
||
|
||
The provisioning step already does this, but in case you need it, in the `/vagrant/OpenOversight` directory, there is a script to create the database: | ||
In the Docker environment, you'll need to run the script to create the database: | ||
|
||
```sh | ||
~/oovirtenv/bin/python create_db.py | ||
$ python create_db.py | ||
``` | ||
|
||
In the event that you need to create or delete the test data, you can do that with | ||
`~/oovirtenv/bin/python test_data.py --populate` to create the data | ||
`$ python test_data.py --populate` to create the data | ||
or | ||
`~/oovirtenv/bin/python test_data.py --cleanup` to delete the data | ||
`$ python test_data.py --cleanup` to delete the data | ||
|
||
### Migrating the Database | ||
|
||
|
@@ -123,13 +66,13 @@ If you e.g. add a new column or table, you'll need to migrate the database. | |
You can use the management interface to first generate migrations: | ||
|
||
```sh | ||
(oovirtenv)vagrant@vagrant-ubuntu-trusty-64:/vagrant/OpenOversight$ python manage.py db migrate | ||
$ python manage.py db migrate | ||
``` | ||
|
||
And then you should inspect/edit the migrations. You can then apply the migrations: | ||
|
||
```sh | ||
(oovirtenv)vagrant@vagrant-ubuntu-trusty-64:/vagrant/OpenOversight$ python manage.py db upgrade | ||
$ python manage.py db upgrade | ||
``` | ||
|
||
You can also downgrade the database using `python manage.py db downgrade`. | ||
|
@@ -139,7 +82,7 @@ You can also downgrade the database using `python manage.py db downgrade`. | |
In addition to running the development server, `manage.py` (OpenOversight's management interface) can be used to do the following: | ||
|
||
```sh | ||
(oovirtenv)vagrant@vagrant-ubuntu-trusty-64:/vagrant/OpenOversight$ python manage.py | ||
$ python manage.py | ||
-------------------------------------------------------------------------------- | ||
INFO in __init__ [/vagrant/OpenOversight/app/__init__.py:57]: | ||
OpenOversight startup | ||
|
@@ -164,39 +107,10 @@ optional arguments: | |
In development, you can make an administrator account without having to confirm your email: | ||
|
||
```sh | ||
(oovirtenv)vagrant@vagrant-ubuntu-trusty-64:/vagrant/OpenOversight$ python manage.py make_admin_user | ||
$ python manage.py make_admin_user | ||
Username: redshiftzero | ||
Email: [email protected] | ||
Password: | ||
Type your password again: | ||
Administrator redshiftzero successfully added | ||
``` | ||
|
||
## Running Unit Tests | ||
|
||
Run tests with `pytest`: | ||
|
||
```sh | ||
(oovirtenv)vagrant@vagrant-ubuntu-trusty-64:/vagrant/OpenOversight/$ cd tests | ||
(oovirtenv)vagrant@vagrant-ubuntu-trusty-64:/vagrant/OpenOversight/tests$ pytest | ||
``` | ||
|
||
## Changing the Development Environment | ||
|
||
If you're making massive changes to the development environment provisioning, you should know that Vagrant and the Puppet modules that provision the box use Ruby, so you'll want some reasonably-modern Ruby. Anything in the 2.0-2.2 area should work. Puppet has some annoying interactions where puppet 3 doesn't work with ruby 2.2, though, so you might have to get creative on modern OSes. | ||
|
||
If you don't have bundler installed: | ||
|
||
`gem install bundler` | ||
|
||
If you don't have rake installed: | ||
|
||
`bundle install` | ||
|
||
Then provision the VM: | ||
|
||
`rake vagrant:provision` | ||
|
||
Puppet modules are dropped into place by librarian-puppet, and there's a rake task that'll do it without the headache of remembering all the paths and such: | ||
|
||
`rake vagrant:build_puppet` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,44 @@ | ||
.PHONY: default build run | ||
|
||
default: dev build start test stop clean | ||
|
||
dev: | ||
.PHONY: dev | ||
dev: ## Build and run containers | ||
make build | ||
make start | ||
|
||
build: | ||
.PHONY: build | ||
build: ## Build containers | ||
docker-compose build postgres | ||
docker-compose up -d postgres | ||
docker-compose build web | ||
docker-compose up -d web | ||
docker-compose run --rm web /usr/local/bin/python ../create_db.py | ||
docker-compose run --rm web /usr/local/bin/python ../test_data.py -p | ||
|
||
start: | ||
.PHONY: start | ||
start: ## Run containers | ||
docker-compose up -d | ||
|
||
clean: | ||
.PHONY: clean | ||
clean: ## Remove containers | ||
docker rm openoversight_web_1 | ||
docker rm openoversight_postgres_1 | ||
|
||
test: | ||
.PHONY: test | ||
test: ## Run tests | ||
docker-compose run --rm web /usr/local/bin/pytest -v tests/ | ||
|
||
stop: | ||
.PHONY: stop | ||
stop: ## Stop containers | ||
docker-compose stop | ||
|
||
.PHONY: docs | ||
docs: ## Build project documentation in live reload for editing | ||
make -C docs/ clean && sphinx-autobuild docs/ docs/_build/html | ||
|
||
.PHONY: help | ||
help: ## Print this message and exit | ||
@printf "OpenOversight: Makefile for development, documentation and testing.\n" | ||
@printf "Subcommands:\n\n" | ||
@awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z_-]+:.*?## / {printf "\033[36m%s\033[0m : %s\n", $$1, $$2}' $(MAKEFILE_LIST) \ | ||
| sort \ | ||
| column -s ':' -t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.