Skip to content

Commit

Permalink
- Adding ansible deployment mechanism
Browse files Browse the repository at this point in the history
- Updating service script to start/stop sockify
  • Loading branch information
Yauhen Yakimovich committed Aug 24, 2015
1 parent 9a0d239 commit 214cee0
Show file tree
Hide file tree
Showing 17 changed files with 367 additions and 2 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,16 @@ As a developer you may find *interactive mode* very handy:
./picostk -i -vvv daemon start
```

## Deploy with ansible

> Install `pip install ansible`
Edit `scripts/picostack-playbooks/hosts` and play a scenario.

```
cd scripts/picostack-playbooks
ansible-playbook playbooks/deploy-picostack.yml
```

---
wbr, yy
2 changes: 2 additions & 0 deletions picostk-sockify
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ if len(sys.argv) == 1:
sys.argv += ['--target-config',
os.path.expanduser('~/.picostack/vnc-targets'),
picostack.settings.NOVNC_PARAMS['real_websockify_port']]
if not picostack.settings.DEBUG:
sys.argv += ['-D']
websockify.websocketproxy.websockify_init()
4 changes: 4 additions & 0 deletions pstk
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ case "$1" in
start)
echo "Starting script pstk "
$SUDO $PICOSTACK daemon start
echo "Starting sockify" # DEBUG=False in django settings!
$SUDO ${PICOSTACK}-sockify
;;
stop)
echo "Cleaning state of the system"
$SUDO $PICOSTACK clean all
echo "Stopping script pstk"
$SUDO $PICOSTACK daemon stop
echo "Stopping sockify"
pkill picostk-sockify
;;
*)
echo "Usage: /etc/init.d/pstk {start|stop}"
Expand Down
4 changes: 4 additions & 0 deletions scripts/picostack-playbooks/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[defaults]
hostfile = hosts
roles_path = playbooks/roles
executable = /bin/bash
18 changes: 18 additions & 0 deletions scripts/picostack-playbooks/playbooks/deploy-picostack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Ansible-based provisioning script automating the deploy of the picostack
# on the linux (Ubuntu) host.
#
# @author: Yauhen Yakimovich <eugeny.yakimovitch@gmail.com>,
#
# @license: The MIT License (MIT). Read a copy of LICENSE distributed with
# this code.
---
- name: Deploy picostack application
hosts: targets
# vars_files:
# - roles/xxx/vars/xxx.yml
vars:
# overwrite roles/picostack_app/defaults/main.yml
deploy_user: pstk
app_domain: "{{ ansible_ssh_host }}"
roles:
- picostack_app
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Role Name
=========

A brief description of the role goes here.

Requirements
------------

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.

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

A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.

Dependencies
------------

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

- hosts: servers
roles:
- { role: username.rolename, x: 42 }

License
-------

BSD

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

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# defaults file for picostack_app
# turn off/on debug deploy
# deploy_debug: yes
# other vars
deploy_user: pstk
app_domain: picostack.mysite.org
admin_email: admin@{{ app_domain }}
app_dir: "/home/{{ deploy_user }}/picostack_app"
django_dir: /usr/local/lib/python2.7/dist-packages/picostack
django_wsgi_dir: "{{ django_dir }}/g0ph"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- name: restart apache2
service: name=apache2 state=restarted
sudo: yes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# handlers file for picostack_app
- include: apache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
galaxy_info:
author: your name
description:
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: license (GPLv2, CC-BY, etc)
min_ansible_version: 1.2
#
# Below are all platforms currently available. Just uncomment
# the ones that apply to your role. If you don't see your
# platform on this list, let us know and we'll get it added!
#
#platforms:
#- name: EL
# versions:
# - all
# - 5
# - 6
# - 7
#- name: GenericUNIX
# versions:
# - all
# - any
#- name: Fedora
# versions:
# - all
# - 16
# - 17
# - 18
# - 19
# - 20
# - 21
# - 22
#- name: Windows
# versions:
# - all
# - 2012R2
#- name: SmartOS
# versions:
# - all
# - any
#- name: opensuse
# versions:
# - all
# - 12.1
# - 12.2
# - 12.3
# - 13.1
# - 13.2
#- name: Amazon
# versions:
# - all
# - 2013.03
# - 2013.09
#- name: GenericBSD
# versions:
# - all
# - any
#- name: FreeBSD
# versions:
# - all
# - 8.0
# - 8.1
# - 8.2
# - 8.3
# - 8.4
# - 9.0
# - 9.1
# - 9.1
# - 9.2
#- name: Ubuntu
# versions:
# - all
# - lucid
# - maverick
# - natty
# - oneiric
# - precise
# - quantal
# - raring
# - saucy
# - trusty
# - utopic
# - vivid
#- name: SLES
# versions:
# - all
# - 10SP3
# - 10SP4
# - 11
# - 11SP1
# - 11SP2
# - 11SP3
#- name: GenericLinux
# versions:
# - all
# - any
#- name: Debian
# versions:
# - all
# - etch
# - jessie
# - lenny
# - squeeze
# - wheezy
#
# Below are all categories currently available. Just as with
# the platforms above, uncomment those that apply to your role.
#
#categories:
#- cloud
#- cloud:ec2
#- cloud:gce
#- cloud:rax
#- clustering
#- database
#- database:nosql
#- database:sql
#- development
#- monitoring
#- networking
#- packaging
#- system
#- web
dependencies: []
# List your role dependencies here, one per line.
# Be sure to remove the '[]' above if you add dependencies
# to this list.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
# Install Apache server

- name: install apache2
sudo: yes
apt: name=apache2

- name: install mod_wsgi
sudo: yes
apt: name=libapache2-mod-wsgi

- name: enabled mod_wsgi
sudo: yes
apache2_module: name=wsgi state=present
notify:
- restart apache2

- name: enabled mod_rewrite
sudo: yes
apache2_module: name=rewrite state=present
notify:
- restart apache2

- name: create virtual host file
sudo: yes
template: src=../templates/virtualhost.j2 dest="/etc/apache2/sites-available/{{ app_domain }}.conf"

- name: enable apache site
sudo: yes
command: a2ensite "{{ app_domain }}"
args:
creates: "/etc/apache2/sites-enabled/{{ app_domain }}"
notify:
- restart apache2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
# tasks file for picostack_app
- include: apache.yml
- include: python-django.yml
- include: picostack-git.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- name: Delete app folder if any
file: path="{{ app_dir }}" state=absent

- name: Get the latest code from github
git: repo="https://github.com/ewiger/picostack.git"
dest="{{ app_dir }}"
accept_hostkey=yes
update=yes
clone=yes
force=yes

- name: Install app in dev mode
shell: "sudo pip install -e ."
args:
chdir: "{{ app_dir }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Update packages every hour
- name: Update all packages to the latest version
sudo: yes
tags:
- update
apt: upgrade=safe update_cache=yes cache_valid_time=3600

- name: Install apt packages
sudo: yes
apt:
name: "{{ item }}"
state: installed
with_items:
- git
- python-setuptools
- python-dev
- build-essential
- libmysqlclient-dev
tags:
- python
- django

- name: Install pip packages
sudo: yes
pip:
name: "{{ item }}"
state: present
with_items:
- MySQL-python
- simplejson
- django
- django-nose
#- django-registration-redux
#- djangorestframework
tags:
- python
- django
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# picostack virtual host:
<VirtualHost *:80>
ServerAdmin {{ admin_email }}
DocumentRoot {{ django_wsgi_dir }}
ServerName {{ app_domain }}
ErrorLog ${APACHE_LOG_DIR}/picostack.error.log
CustomLog ${APACHE_LOG_DIR}/picostack.access.log combined

WSGIScriptAlias / {{ django_wsgi_dir }}/wsgi.py
WSGIDaemonProcess {{ app_domain }} python-path={{ django_dir }}:/usr/lib/python2.7/dist-packages/:/usr/local/lib/python2.7/dist-packages
WSGIProcessGroup picostack.mysite.org

<Directory "{{ django_wsgi_dir }}">
<Files wsgi.py>
Require all granted
# For apache <= 2.4 uncomment and use lines below instead
# Order allow,deny
# Allow from all
</Files>
</Directory>

Alias /static/admin/ /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin/

<Directory "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin/">
Require all granted
# For apache <= 2.4 uncomment and use lines below instead
# Order allow,deny
# Allow from all
</Directory>

Alias /static/ {{ django_wsgi_dir }}/static/

<Directory "{{ django_wsgi_dir }}/static/">
Require all granted
# For apache <= 2.4 uncomment and use lines below instead
# Order allow,deny
# Allow from all
</Directory>
</VirtualHost>
Loading

0 comments on commit 214cee0

Please sign in to comment.