From 309df8b802b1da75e9f363d63c5f840e6c5b4b21 Mon Sep 17 00:00:00 2001 From: Michael Warkentin Date: Mon, 9 Nov 2015 14:32:39 -0500 Subject: [PATCH 1/5] Initial work on #42 * Configure vagrant to set up a sample project w/ django-watchman installed * Provisioned w/ Ansible * Set up 2 sqlite databases * Update .gitignore / .editorconfig --- .editorconfig | 4 + .gitignore | 6 ++ Vagrantfile | 19 ++++ provisioning/playbook.yml | 30 ++++++ sample_project/manage.py | 10 ++ sample_project/requirements.txt | 4 + sample_project/sample_project/__init__.py | 0 sample_project/sample_project/settings.py | 107 ++++++++++++++++++++++ sample_project/sample_project/urls.py | 7 ++ sample_project/sample_project/wsgi.py | 16 ++++ 10 files changed, 203 insertions(+) create mode 100644 Vagrantfile create mode 100644 provisioning/playbook.yml create mode 100755 sample_project/manage.py create mode 100644 sample_project/requirements.txt create mode 100644 sample_project/sample_project/__init__.py create mode 100644 sample_project/sample_project/settings.py create mode 100644 sample_project/sample_project/urls.py create mode 100644 sample_project/sample_project/wsgi.py diff --git a/.editorconfig b/.editorconfig index 2f5e583..8ec085a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,3 +13,7 @@ indent_size = 4 [*.yml] indent_style = space indent_size = 2 + +[Vagrantfile] +indent_style = space +indent_size = 2 diff --git a/.gitignore b/.gitignore index 7b4f7ec..0a490b8 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,9 @@ docs/_build # Coverage.py htmlcov/ + +# Sqlite databases +*.sqlite3 + +# Vagrant boxes +.vagrant/ diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..53dcd8c --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,19 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure(2) do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + config.vm.box = "ubuntu/trusty64" + config.vm.network "forwarded_port", guest: 8000, host: 8000 + + config.vm.provision "ansible" do |ansible| + ansible.playbook = "provisioning/playbook.yml" + end +end diff --git a/provisioning/playbook.yml b/provisioning/playbook.yml new file mode 100644 index 0000000..647bd9f --- /dev/null +++ b/provisioning/playbook.yml @@ -0,0 +1,30 @@ +- hosts: all + tasks: + - name: install git + apt: + name: git + state: latest + sudo: yes + + - name: download pip installer + get_url: + url: https://bootstrap.pypa.io/get-pip.py + dest: /tmp + + - name: install pip + command: python /tmp/get-pip.py + sudo: yes + + - name: install global python packages + pip: + name: "{{ item }}" + state: present + with_items: + - virtualenv + - virtualenvwrapper + sudo: yes + + - name: install sample project requirements + pip: + requirements: /vagrant/sample_project/requirements.txt + virtualenv: ~/venv diff --git a/sample_project/manage.py b/sample_project/manage.py new file mode 100755 index 0000000..9c651f3 --- /dev/null +++ b/sample_project/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sample_project.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/sample_project/requirements.txt b/sample_project/requirements.txt new file mode 100644 index 0000000..ddeae69 --- /dev/null +++ b/sample_project/requirements.txt @@ -0,0 +1,4 @@ +django<1.9 + +# django-watchman +-e /vagrant/ diff --git a/sample_project/sample_project/__init__.py b/sample_project/sample_project/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sample_project/sample_project/settings.py b/sample_project/sample_project/settings.py new file mode 100644 index 0000000..656430d --- /dev/null +++ b/sample_project/sample_project/settings.py @@ -0,0 +1,107 @@ +""" +Django settings for sample_project project. + +Generated by 'django-admin startproject' using Django 1.8.6. + +For more information on this file, see +https://docs.djangoproject.com/en/1.8/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.8/ref/settings/ +""" + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'h%n@34@2nst!bm-ilj$3tfyq4-*iq@q@0_jjquu4$0g61ep-vy' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'watchman', +) + +MIDDLEWARE_CLASSES = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'django.middleware.security.SecurityMiddleware', +) + +ROOT_URLCONF = 'sample_project.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'sample_project.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.8/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + }, + 'secondary': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db_secondary.sqlite3'), + }, +} + + +# Internationalization +# https://docs.djangoproject.com/en/1.8/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.8/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/sample_project/sample_project/urls.py b/sample_project/sample_project/urls.py new file mode 100644 index 0000000..3efcb2e --- /dev/null +++ b/sample_project/sample_project/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls import include, url +from django.contrib import admin + +urlpatterns = [ + url(r'^admin/', include(admin.site.urls)), + url(r'^watchman/', include('watchman.urls')), +] diff --git a/sample_project/sample_project/wsgi.py b/sample_project/sample_project/wsgi.py new file mode 100644 index 0000000..d32b7ee --- /dev/null +++ b/sample_project/sample_project/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for sample_project project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sample_project.settings") + +application = get_wsgi_application() From 6dbd52f75f5630e11074ba6563f1ea59a689e5c9 Mon Sep 17 00:00:00 2001 From: Michael Warkentin Date: Mon, 9 Nov 2015 15:09:00 -0500 Subject: [PATCH 2/5] More updates for #42 * Manage .bashrc and configure virtualenvwrapper * Configure .project for easy workon directory switching --- provisioning/playbook.yml | 14 +++- provisioning/templates/.bashrc.j2 | 122 ++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 provisioning/templates/.bashrc.j2 diff --git a/provisioning/playbook.yml b/provisioning/playbook.yml index 647bd9f..1b44dde 100644 --- a/provisioning/playbook.yml +++ b/provisioning/playbook.yml @@ -1,5 +1,12 @@ - hosts: all + vars: + - virtualenv_path: ~/.virtualenvs/watchman tasks: + - name: configure .bashrc + template: + src: templates/.bashrc.j2 + dest: ~/.bashrc + - name: install git apt: name: git @@ -27,4 +34,9 @@ - name: install sample project requirements pip: requirements: /vagrant/sample_project/requirements.txt - virtualenv: ~/venv + virtualenv: "{{ virtualenv_path}}" + + - name: configure virtualenv project + copy: + content: /vagrant/sample_project + dest: "{{ virtualenv_path}}/.project" diff --git a/provisioning/templates/.bashrc.j2 b/provisioning/templates/.bashrc.j2 new file mode 100644 index 0000000..18551a6 --- /dev/null +++ b/provisioning/templates/.bashrc.j2 @@ -0,0 +1,122 @@ +# {{ ansible_managed }} + +# ~/.bashrc: executed by bash(1) for non-login shells. +# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) +# for examples + +# If not running interactively, don't do anything +case $- in + *i*) ;; + *) return;; +esac + +# don't put duplicate lines or lines starting with space in the history. +# See bash(1) for more options +HISTCONTROL=ignoreboth + +# append to the history file, don't overwrite it +shopt -s histappend + +# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) +HISTSIZE=1000 +HISTFILESIZE=2000 + +# check the window size after each command and, if necessary, +# update the values of LINES and COLUMNS. +shopt -s checkwinsize + +# If set, the pattern "**" used in a pathname expansion context will +# match all files and zero or more directories and subdirectories. +#shopt -s globstar + +# make less more friendly for non-text input files, see lesspipe(1) +[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" + +# set variable identifying the chroot you work in (used in the prompt below) +if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then + debian_chroot=$(cat /etc/debian_chroot) +fi + +# set a fancy prompt (non-color, unless we know we "want" color) +case "$TERM" in + xterm-color) color_prompt=yes;; +esac + +# uncomment for a colored prompt, if the terminal has the capability; turned +# off by default to not distract the user: the focus in a terminal window +# should be on the output of commands, not on the prompt +#force_color_prompt=yes + +if [ -n "$force_color_prompt" ]; then + if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then + # We have color support; assume it's compliant with Ecma-48 + # (ISO/IEC-6429). (Lack of such support is extremely rare, and such + # a case would tend to support setf rather than setaf.) + color_prompt=yes + else + color_prompt= + fi +fi + +if [ "$color_prompt" = yes ]; then + PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' +else + PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' +fi +unset color_prompt force_color_prompt + +# If this is an xterm set the title to user@host:dir +case "$TERM" in +xterm*|rxvt*) + PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" + ;; +*) + ;; +esac + +# enable color support of ls and also add handy aliases +if [ -x /usr/bin/dircolors ]; then + test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" + alias ls='ls --color=auto' + #alias dir='dir --color=auto' + #alias vdir='vdir --color=auto' + + alias grep='grep --color=auto' + alias fgrep='fgrep --color=auto' + alias egrep='egrep --color=auto' +fi + +# some more ls aliases +alias ll='ls -alF' +alias la='ls -A' +alias l='ls -CF' + +# Add an "alert" alias for long running commands. Use like so: +# sleep 10; alert +alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' + +# Alias definitions. +# You may want to put all your additions into a separate file like +# ~/.bash_aliases, instead of adding them here directly. +# See /usr/share/doc/bash-doc/examples in the bash-doc package. + +if [ -f ~/.bash_aliases ]; then + . ~/.bash_aliases +fi + +# enable programmable completion features (you don't need to enable +# this, if it's already enabled in /etc/bash.bashrc and /etc/profile +# sources /etc/bash.bashrc). +if ! shopt -oq posix; then + if [ -f /usr/share/bash-completion/bash_completion ]; then + . /usr/share/bash-completion/bash_completion + elif [ -f /etc/bash_completion ]; then + . /etc/bash_completion + fi +fi + +# Configure virtualenvwrapper +if [ -f /usr/local/bin/virtualenvwrapper.sh ]; then + export WORKON_HOME=$HOME/.virtualenvs + source /usr/local/bin/virtualenvwrapper.sh +fi From 272241e94394aed3db5ee00c27ec5ddfca2074e3 Mon Sep 17 00:00:00 2001 From: Michael Warkentin Date: Mon, 9 Nov 2015 15:27:03 -0500 Subject: [PATCH 3/5] Add docs for #42 Explain how to use the vagrant box. --- README.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.rst b/README.rst index 774a08c..6bd2f79 100644 --- a/README.rst +++ b/README.rst @@ -241,3 +241,26 @@ Paid checks Currently there is only one "paid" check - ``watchman.checks.email``. You can enable it by setting the ``WATCHMAN_ENABLE_PAID_CHECKS`` to ``True``, or by overriding the ``WATCHMAN_CHECKS`` setting. + +Trying it out with Vagrant +-------------------------- + +A sample project is available along with a Vagrantfile to make it easy to try +out django-watchman. + +Requirements +************ + +* Vagrant +* Virtualbox +* Ansible + +Instructions +************ + +1. Launch vagrant box: ``vagrant up`` +2. SSH into vagrant: ``vagrant ssh`` +3. Activate the virtualenv: ``workon watchman`` +4. Launch the development server: ``python manage.py runserver 0.0.0.0:8000`` +5. Visit watchman json endpoint in your browser: http://127.0.0.1:8000/watchman/ +6. Visit watchman dashboard in your browser: http://127.0.0.1:8000/watchman/dashboard/ From edce58190f6c09647901b9ed45e4643a20bf1413 Mon Sep 17 00:00:00 2001 From: Michael Warkentin Date: Mon, 9 Nov 2015 15:31:40 -0500 Subject: [PATCH 4/5] Link requirements for #42 --- README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 6bd2f79..4ad5f36 100644 --- a/README.rst +++ b/README.rst @@ -251,9 +251,9 @@ out django-watchman. Requirements ************ -* Vagrant -* Virtualbox -* Ansible +* `Vagrant `_ +* `Virtualbox `_ +* `Ansible `_ Instructions ************ From 3800b45c78d40f162f6cc737933859a1cfad2c80 Mon Sep 17 00:00:00 2001 From: Michael Warkentin Date: Mon, 9 Nov 2015 16:24:29 -0500 Subject: [PATCH 5/5] landscape.io: Ignore secret key in sample project --- .landscape.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .landscape.yml diff --git a/.landscape.yml b/.landscape.yml new file mode 100644 index 0000000..f6806ce --- /dev/null +++ b/.landscape.yml @@ -0,0 +1,2 @@ +ignore-paths: + - sample_project/sample_project/settings.py