Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into logging-handler
Browse files Browse the repository at this point in the history
  • Loading branch information
antoviaque committed Sep 26, 2015
2 parents 798a6c2 + ea909a0 commit 8fc9bd3
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DEBUG=true
SECRET_KEY='tests'
DATABASE_URL='postgresql:///opencraft-test'
DATABASE_URL='postgres://localhost/opencraft'
HUEY_ALWAYS_EAGER=true
OPENSTACK_USER='test'
OPENSTACK_PASSWORD='pass'
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ target/
# Local configuration
.env
.env.integration

# Vagrant
.vagrant/
49 changes: 44 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,35 @@ OpenCraft
Install
-------

### Vagrant install

You can use [vagrant][] to set up a virtual machine for local development and
testing. This is useful to keep your development environment isolated from the
rest of your system.

First, install [virtualbox][] and [vagrant][]. Then run:

vagrant up

This will provision a virtual machine running Ubuntu 14.04, set up local
postgres and redis, install the dependencies and run the tests.

Once the virtual machine is up and running, you can ssh into it with this
command:

vagrant ssh

Vagrant will set up a virtualbox share mapping your local development directory
to `/vagrant` inside the virtual machine. Any changes you make locally will be
reflected inside the virtual machine automatically.

Vagrant will map port 5000 inside the virtual machine to port 5000 on the host,
so you can access the development server using your web browser.


### Local install

If you prefer not to install vagrant, you can install OpenCraft manually.
Instructions based on Ubuntu 14.04.

Install the system package dependencies & virtualenv:
Expand Down Expand Up @@ -33,8 +62,14 @@ $ pip install -r requirements.txt
Configure
---------

Create an `.env` file at the root of the repository or set environment variables, customizing the
settings from `opencraft/settings.py` which are loaded via `env()`.
Honcho will set up environment variables defined in the `.env` file at the root
of your repository. If you are using vagrant for development, a basic `.env`
file will already have been created for you, but you will need to add
credentials for third-party services manually in order to run the development
server or the integration tests.

The environment variables in `.env` customize the settings from
`opencraft/settings.py` which are loaded via `env()`.


Migrations
Expand Down Expand Up @@ -141,9 +176,9 @@ $ make test_unit
$ make test_integration
```

Note that the integration tests aren't run by default, as they require a working OpenStack cluster
configured. To run them, create a `.env.test` file - your development environment is likely a good
starting point:
Note that the integration tests aren't run by default, as they require a working
OpenStack cluster configured. To run them, create a `.env.integration` file -
your development environment is likely a good starting point:

```
$ ln -s .env .env.integration
Expand All @@ -168,3 +203,7 @@ You can also access the Django `manage.py` command directly, using honcho to loa
```
$ honcho run ./manage.py config
```


[virtualbox]: https://www.virtualbox.org/
[vagrant]: https://www.vagrantup.com/
61 changes: 61 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# This script provisions a vagrant development environment with local
# postgres and redis servers for development and testing.
PROVISION = <<SCRIPT
set -e
# cd to /vagrant on login
cd /vagrant
grep -Fq 'cd /vagrant' ~/.bashrc || echo 'cd /vagrant' >> ~/.bashrc
# Install system packages
sudo apt-get update --quiet
sudo apt-get install -y $(cat debian_packages.lst) postgresql
# Set up a virtualenv
sudo pip3 install virtualenv
mkdir -p ~/.virtualenvs
virtualenv -p python3 ~/.virtualenvs/opencraft
source ~/.virtualenvs/opencraft/bin/activate
# Activate virtualenv on login
grep -Fq 'source ~/.virtualenvs/opencraft/bin/activate' ~/.bashrc ||
echo 'source ~/.virtualenvs/opencraft/bin/activate' >> ~/.bashrc
# Install python dependencies
pip install -r requirements.txt
# Create postgres user
sudo -u postgres createuser -d vagrant
# Allow access to postgres from localhost without password
cat << EOF | sudo tee /etc/postgresql/9.3/main/pg_hba.conf
local all postgres peer
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
EOF
sudo service postgresql restart
# Create postgres database
createdb --encoding utf-8 --template template0 opencraft
# Use test configuration for local development, excluding the line that
# disables logging to the console.
[ -e .env ] || grep -v '^BASE_HANDLERS' .env.test > .env
# Run unit tests
make test_unit
SCRIPT

Vagrant.configure(2) do |config|
config.vm.box = 'ubuntu/trusty64'
config.vm.network 'forwarded_port', guest: 2001, host: 2001
config.vm.network 'forwarded_port', guest: 5000, host: 5000
config.vm.provision 'shell',
inline: PROVISION,
privileged: false,
keep_color: true
end
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# OpenCraft -- tools to aid developing and hosting free software projects
Expand Down
6 changes: 3 additions & 3 deletions opencraft/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
# Django-extensions ###########################################################

SHELL_PLUS = "ipython"
RUNSERVERPLUS_SERVER_ADDRESS_PORT = env('RUNDEV_SERVER_ADDRESS_PORT', default='localhost:5000')
RUNSERVERPLUS_SERVER_ADDRESS_PORT = env('RUNDEV_SERVER_ADDRESS_PORT', default='0.0.0.0:5000')


# Grappelli ###################################################################
Expand Down Expand Up @@ -208,8 +208,8 @@
SWAMP_DRAGON_REDIS_HOST = REDIS_URL_OBJ.hostname
SWAMP_DRAGON_REDIS_PORT = REDIS_URL_OBJ.port
SWAMP_DRAGON_CONNECTION = ('swampdragon.connections.sockjs_connection.DjangoSubscriberConnection', '/data')
DRAGON_SERVER_ADDRESS_PORT = env('DRAGON_SERVER_ADDRESS_PORT', default='localhost:2001')
DRAGON_URL = env('DRAGON_URL', default='http://{}/'.format(DRAGON_SERVER_ADDRESS_PORT))
DRAGON_SERVER_ADDRESS_PORT = env('DRAGON_SERVER_ADDRESS_PORT', default='0.0.0.0:2001')
DRAGON_URL = env('DRAGON_URL', default='http://localhost:2001/')


# OpenStack ###################################################################
Expand Down
2 changes: 1 addition & 1 deletion websocket.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# OpenCraft -- tools to aid developing and hosting free software projects
Expand Down

0 comments on commit 8fc9bd3

Please sign in to comment.