Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add setup using vagrant and virtualbox and support for python 2.7 #9

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,14 @@ tramp
# Windows
Thumbs.db
Desktop.ini

# Vagrant private files
.vagrant/*

# Supervisor files
supervisord.log
supervisord.pid
supervisord.conf

# Static files in developement/local environment
static/
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# deployment
env=development

configure:
@ansible-playbook devops/start.yml -i devops/inventory/$(env) --limit=all

deploy:
@ansible-playbook devops/launch.yml -i devops/inventory/$(env) --limit=all -vvvvvvv

# for dev debugging.
run2:
@sudo killall -9 supervisord | echo
@sudo killall -9 gunicorn | echo
@python manage.py validate --settings=settings.development &
@python manage.py collectstatic --noinput --settings=settings.development &
@python manage.py migrate --settings=settings.development &
@python manage.py runserver 0.0.0.0:8000 --settings=settings.development

shell:
@python manage.py shell_plus --settings=settings.development
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,13 @@ Take a look at the docs for a detailed instructions guide.

[0]: https://www.python.org/
[1]: https://www.djangoproject.com/


## Setup Using Vagrant
* You will need to have [vagrant](https://www.vagrantup.com/), [virtualbox](https://www.virtualbox.org/) and [ansible](www.ansible.com/) installed.
* change into this projects directory and:
`vagrant up`
* point your browser to; [localhost:8050](http://localhost:8050/)

## python 2.X compatibility
[This fork](https://github.com/komuW/edge) works with python 2.7
31 changes: 31 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env ruby
# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.network :forwarded_port, guest: 8000, host: 8050
config.ssh.forward_agent = true
config.vm.synced_folder './devops', '/vagrant/devops',
:mount_options => ['fmode=666']

#config.vm.provision :shell, :path => "devops/boot.sh"

config.vm.provision "ansible" do |ansible|
ansible.playbook = "devops/start.yml"
ansible.inventory_path = "devops/inventory/development"
ansible.limit = "localhost"
#ansible.verbose = "v"
end

# Cache apt-get package downloads to speed things up
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :box
config.cache.enable :generic, { :cache_dir => "/var/cache/pip" }
end

end
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/accounts/forms.py → apps/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class LoginForm(AuthenticationForm):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
super(LoginForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-inline navbar-form pull-right'
self.helper.form_id = 'signin-form'
Expand All @@ -24,7 +24,7 @@ def __init__(self, *args, **kwargs):
class SignupForm(UserCreationForm):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
super(SignupForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_id = 'signup-form'
#self.helper.form_class = 'form-inline navbar-form pull-right'
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/accounts/views.py → apps/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get(self, request, *args, **kwargs):
kwargs["signin_form"] = self.signin_form_class()
if "signup_form" not in kwargs:
kwargs["signup_form"] = self.signup_form_class()
return super().get(request, *args, **kwargs)
return super(SignInAndSignUp, self).get(request, *args, **kwargs)

def post(self, request, *args, **kwargs):
if 'sign_in' in request.POST:
Expand All @@ -29,7 +29,7 @@ def post(self, request, *args, **kwargs):
messages.ERROR,
"Unable login! "
"Check username/password")
return super().get(request,
return super(SignInAndSignUp, self).get(request,
signup_form=self.signup_form_class(),
signin_form=form)
username = form.cleaned_data["username"]
Expand All @@ -47,7 +47,7 @@ def post(self, request, *args, **kwargs):
messages.ERROR,
"Unable to register! "
"Please retype the details")
return super().get(request,
return super(SignInAndSignUp, self).get(request,
signin_form=self.signin_form_class(),
signup_form=form)
form.save()
Expand All @@ -70,7 +70,7 @@ def get(self, request, *args, **kwargs):
logout(request)
messages.add_message(request, messages.INFO,
"Logout successful!")
return super().get(request, *args, **kwargs)
return super(LogoutView, self).get(request, *args, **kwargs)


class AboutView(generic.TemplateView):
Expand Down
4 changes: 0 additions & 4 deletions dev-requirements.txt

This file was deleted.

1 change: 1 addition & 0 deletions devops/ansible.cfg
19 changes: 19 additions & 0 deletions devops/boot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
#
# Set up Ansible on a Vagrant Ubuntu Precise box, then run the
# development playbook.

echo "provisioning...."

if [[ ! $(ansible --version 2> /dev/null) =~ 1\.6 ]]; then
sudo rm -rf /var/lib/apt/lists/* && \
sudo apt-get update && \
sudo apt-get -y install python-software-properties && \
sudo add-apt-repository -y ppa:rquillo/ansible && \
sudo apt-get update && \
sudo apt-get -y install ansible
fi

PYTHONUNBUFFERED=1 ansible-playbook /vagrant/devops/start.yml \
--inventory-file=/vagrant/devops/inventory/development \
--connection=local
6 changes: 6 additions & 0 deletions devops/configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- {hosts: all, sudo: yes, roles: [ ansible-role-apt-sources ], tags: [apt_sources] }

- { hosts: all, sudo: yes, roles: [ ansible-locale ], tags: [ locale ] }

- { hosts: app_servers, sudo: yes, roles: [ app_server ], tags: [ app_server ]}
13 changes: 13 additions & 0 deletions devops/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---

APP_NAME: edge
APP_REPOSITORY: [email protected]:komuW/edge.git
APP_USER: "{{ ansible_ssh_user }}"

APP_HOME: "/home/{{ APP_USER }}"
APP_DIR: "{{ APP_HOME }}/{{ APP_NAME }}"
APP_VIRTUALENV: "{{ APP_HOME }}/.virtualenvs/{{ APP_NAME }}"

APP_VERSION: develop

GUNICORN_PORT: 8000
5 changes: 5 additions & 0 deletions devops/group_vars/development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
APP_ENVIRONMENT: development
APP_DIR: /vagrant
APP_VERSION: develop

2 changes: 2 additions & 0 deletions devops/group_vars/production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
APP_ENVIRONMENT: production
2 changes: 2 additions & 0 deletions devops/group_vars/staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
APP_ENVIRONMENT: staging
11 changes: 11 additions & 0 deletions devops/inventory/development
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
localhost ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 ansible_ssh_user=vagrant

[app_servers]
localhost

[db_servers]
localhost

[development:children]
app_servers
db_servers
1 change: 1 addition & 0 deletions devops/inventory/production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# producction servers here
1 change: 1 addition & 0 deletions devops/inventory/staging
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# staging servers here
82 changes: 82 additions & 0 deletions devops/launch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
- hosts: app_servers
gather_facts: yes
sudo: no

tasks:

- name: Check out code on app server
git: >
repo={{ APP_REPOSITORY }}
dest={{ APP_DIR }}
version={{ APP_VERSION }}
accept_hostkey=yes
when: APP_ENVIRONMENT != "development"
notify: restart app

- name: Ensure runtime directories
file: path={{ APP_DIR }}/{{ item }} state=directory
with_items:
- log

- name: Install application requirements
# bug: set sudo to yes
pip: >
requirements={{ APP_DIR }}/requirements/{{ APP_ENVIRONMENT }}.txt
virtualenv={{ APP_VIRTUALENV }}
sudo: yes

- name: Sync and migrate DB
django_manage: >
app_path={{ APP_DIR }}
virtualenv={{ APP_VIRTUALENV }}
settings=settings.{{ APP_ENVIRONMENT }}
command={{ item }}
with_items:
- validate
- collectstatic
- migrate

- name: Configure supervisord
template: src=templates/supervisord.app.conf.j2
dest={{ APP_DIR }}/supervisord.conf
notify:
- restart supervisord

- name: Kill all supervisord
command: killall supervisord
ignore_errors: yes
sudo: yes
sudo_user: root

- name: Wait for supervisor to clean up and exit
pause: seconds=5

- name: Start supervisord
command: supervisord -c {{ APP_DIR }}/supervisord.conf
sudo: yes
sudo_user: root

- name: source virtualenv
lineinfile: line="source {{APP_VIRTUALENV}}/bin/activate"
backup=yes
dest=~/.profile
when: APP_ENVIRONMENT == "development"
sudo: yes
sudo_user: "{{ansible_ssh_user}}"

handlers:

- name: restart app
command: supervisorctl restart {{ APP_NAME }}:*
sudo: yes
sudo_user: root
tags:
- restart

- name: restart supervisord
service: name=supervisor state=restarted enabled=yes
sudo: yes
sudo_user: root
tags:
- restart_supervisor
1 change: 1 addition & 0 deletions devops/roles/ansible-locale/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
29 changes: 29 additions & 0 deletions devops/roles/ansible-locale/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
locale
========

Set locales in Debian-like systems.

Role Variables
--------------

* *locale_lang* - $LANG
* *locale_all* - $LC_ALL
* *locale_numeric* - $LC_NUMERIC
* *locale_time* - $LC_TIME
* *locale_monetary* - $LC_MONETARY
* *locale_paper* - $LC_PAPER
* *locale_identification* - $LC_IDENTIFICATION
* *locale_name* - $LC_NAME
* *locale_address* - $LC_ADDRESS
* *locale_telephone* - $LC_TELEPHONE
* *locale_measurement* - $LC_MEASUREMENT

License
-------

MIT

Author Information
------------------

Sergey Korolev (<[email protected]>)
3 changes: 3 additions & 0 deletions devops/roles/ansible-locale/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# defaults file for locale
locale_lang: en_US.UTF-8
17 changes: 17 additions & 0 deletions devops/roles/ansible-locale/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
galaxy_info:
author: Sergey Korolev
description: Set locales in Debian-like systems.
license: MIT
min_ansible_version: 1.2
platforms:
- name: Ubuntu
versions:
- all
- name: Debian
versions:
- all
categories:
- system
dependencies: []

9 changes: 9 additions & 0 deletions devops/roles/ansible-locale/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# tasks file for locale
- name: set locale.gen file
locale_gen: name={{locale_lang}} state=present
when: ansible_os_family == "Debian"

- name: set locale to en_US.UTF-8
template: src=default.j2 dest=/etc/default/locale
when: ansible_os_family == "Debian"
Loading