Skip to content
Merged
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
24 changes: 24 additions & 0 deletions .bintray_descriptor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"package": {
"name": "PostMaster",
"repo": "PostMaster",
"subject": "stackfocus",
"desc": "PostMaster is a beautiful web application to manage domains, users, and aliases on a Linux mail server ",
"website_url": "https://github.com/StackFocus/PostMaster",
"issue_tracker_url": "https://github.com/StackFocus/PostMaster/issues",
"vcs_url": "https://github.com/StackFocus/PostMaster.git",
"licenses": ["AGPL"],
"labels": ["Postmaster", "Stackfocus", "Flask"],
"public_download_numbers": true,
"public_stats": true
},
"version": {
"name": "1.0.0",
"desc": "Abbey Road"
},
"files":
[
{"includePattern": "*.deb" }
],
"publish": true
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Created by https://www.gitignore.io
site.retry

.vagrant
.idea
Expand Down Expand Up @@ -64,3 +65,6 @@ docs/_build/
target/

env/
*.deb


24 changes: 19 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
language: python
python:
language: python
python:
- "2.7"
install:
install:
- pip install -r requirements.txt
before_script:
- ./pylint-check.py
script:
script:
- py.test -v --cov postmaster --cov-report term-missing tests/
after_success:
after_success:
- coveralls

before_deploy:
- gem install fpm
- ./build_release.sh

deploy:
provider: bintray
file: .bintray_descriptor.json
user: thatarchguy
key:
secure: qoGnfUwsoajFoclGpmhTFj8rP6botEqdXHBOP8xG3EvdNMvF1FNhH6DjhKBF3bwQf7/VEczz/TqVaTsOgrdHJvVLTxYSckM569wbdFLn6/b1MohdBaxu1/mcXXw+RVTjep45cwlzaMQoe3aZn8KPtjfal5Bitc2U2cNepkoaj+nftNGpCZVh1pWI/uQXlKQK/CfzS8mQSKrdsRuBvko88R7Th8otqdSwx+dM+IwtimJsupAhlbpU5XlK01zNn++QVvZ3kkPGWVxRFLlPhDhWWxK/RmTBLZ/HqoE6oyHBsd+e8ydLvVovMjAdagBq4ABXPstSr9/vYfaS9o6RTaqWbt0MFdkUpQdpfUnFARay8rPYJkzkRdqRll5byRh9IHxZc34z+j3lVjbzKRyb0kfeCTDdidULJytWa3SWN4xdCMhyyjjpULsMI1X4RYYtO89Uc85BlD0AQrWCkmJ7rqpUPxkaSfBEuhotTi0PUyUIaU1xLpgtNQFf70Pf3bSEG6W3XDR3vy2k6yiZWWSRAQWSbxTA64DmW0wk/q9ePxso3uqzALYU1M5WflEEnCBkXGFQh8MqAmugHjP7BMjoe+vlJFt5ddoa7yNV14EkvbHY/rb1JVA2Oa4FgVVyt0JOYEnPIvD+NY0VjFHWrOAro3uKHNlOg5nUaMEddwIuKZpoZgo=
dry-run: true
on:
tags: true
21 changes: 17 additions & 4 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

$script = <<SCRIPT
#!/bin/bash
if [ ! -f /usr/bin/ansible-playbook ]; then
apt-get update
apt-get install -y software-properties-common
apt-add-repository ppa:ansible/ansible
apt-get update
apt-get install -y ansible
fi

ansible-playbook -i "localhost," -c local /opt/postmaster/git/ops/ansible/site.yml --extra-vars="remote_user=vagrant" --extra-vars="provision_type=dev"
SCRIPT

Vagrant.configure(2) do |config|
config.vm.box = "puphpet/ubuntu1404-x64"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.synced_folder "./", "/opt/postmaster/git"
config.vm.provision "shell", path: "ops/Vagrant.sh"
config.vm.box = "puphpet/ubuntu1404-x64"
config.vm.network "forwarded_port", guest: 8082, host: 8080
config.vm.synced_folder "./", "/opt/postmaster/git"
config.vm.provision "shell", inline: $script
end
3 changes: 3 additions & 0 deletions build_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
REVISION=`git describe --abbrev=0 --tags | cut -c 2-`
fpm -s dir -t deb -n "postmaster" -v $REVISION --prefix /opt/postmaster/git --description 'PostMaster is a beautiful web application to manage domains, users, and aliases on a Linux mail server' --url 'https://github.com/StackFocus/PostMaster' --after-install ops/ansible/run_ansible.sh -d git -d python -d python-pip -d python-dev -d python-virtualenv -d libldap2-dev -d libssl-dev -d libsasl2-dev -d libffi-dev -d apache2 -d libapache2-mod-wsgi -d libmysqlclient-dev ./
80 changes: 0 additions & 80 deletions ops/Vagrant.sh

This file was deleted.

3 changes: 3 additions & 0 deletions ops/ansible/group_vars/all/vars_file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
remote_user: "postmaster"
provision_type: ""
Empty file added ops/ansible/inventory
Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<VirtualHost *:80>
Listen 8082
<VirtualHost *:8082>
WSGIDaemonProcess postmaster user=www-data group=www-data threads=5
WSGIScriptAlias / /opt/postmaster/git/postmaster.wsgi

Expand Down
21 changes: 21 additions & 0 deletions ops/ansible/roles/postmaster_deploy/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: restart nginx
become: yes
service: name=nginx state=restarted

- name: validate nginx configuration
become: yes
command: nginx -t -c /etc/nginx/nginx.conf
changed_when: False

- name: reload nginx
become: yes
service: name=nginx state=reloaded

- name: reload apache
become: yes
service: name=apache2 state=reloaded

- name: restart apache
become: yes
service: name=nginx state=restarted
59 changes: 59 additions & 0 deletions ops/ansible/roles/postmaster_deploy/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---

- name: Create PostMaster User
user: name={{remote_user}} comment="PostMaster Service Account"

- name: Install main list of packages
apt: pkg={{item}} state=installed update_cache=true
become: yes
with_items:
- git
- python
- python-pip
- python-dev
- python-virtualenv
- libldap2-dev
- libssl-dev
- libsasl2-dev
- libffi-dev
- apache2
- libapache2-mod-wsgi
- libmysqlclient-dev
when: provision_type == "dev"

- name: Create virtualenv directory
file: path=/opt/postmaster/env state=directory owner={{remote_user}} group={{remote_user}} mode=0775 recurse=yes
become: yes

- name: Create logs directory
file: path=/opt/postmaster/logs state=directory owner={{remote_user}} group=www-data mode=0775 recurse=yes
become: yes

- pip: requirements=/opt/postmaster/git/requirements.txt virtualenv=/opt/postmaster/env

- include: mysql.yml
when: provision_type == "dev"

- name: Enable wsgi module for apache2
apache2_module: state=present name=wsgi

- name: Check whether to copy the apache2 vhost file
stat: path=/etc/apache2/sites-available/postmaster.conf
register: apache2_config

- name: Copy apache2 vhost config over
become: yes
copy: src=apache2/postmaster.conf dest=/etc/apache2/sites-available/postmaster.conf mode=0644
when: apache2_config.stat.exists == False

- name: Enable new vhost
command: a2ensite postmaster.conf
become: yes

- name: Ensure apache is started and enabled to start at boot.
become: yes
service: name=apache2 state=restarted enabled=yes

- name: Ensure apache is reloaded
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you reloading when it's restarted just above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because apache2 is fickle :P

become: yes
service: name=apache2 state=reloaded
33 changes: 33 additions & 0 deletions ops/ansible/roles/postmaster_deploy/tasks/mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# mysql setup

- name: Set MySQL root password before installing
become: yes
debconf: name='mysql-server' question='mysql-server/root_password' value='vagrant' vtype='password'

- name: Confirm MySQL root password before installing
become: yes
debconf: name='mysql-server' question='mysql-server/root_password_again' value='vagrant' vtype='password'

- name: Installing MySQL
become: yes
apt: pkg=mysql-server state=latest

- name: Install mysql-python globally for this next command :(
pip: name=MySQL-python
become: yes

- name: Create default database for mysql
mysql_db: name=servermail state=present login_user=root login_password=vagrant

- name: Cleans the migration scripts
command: /opt/postmaster/env/bin/python /opt/postmaster/git/manage.py clean
args:
chdir: /opt/postmaster/git
removes: /opt/postmaster/git/db

- name: Migrate tables
command: /opt/postmaster/env/bin/python /opt/postmaster/git/manage.py createdb
args:
chdir: /opt/postmaster/git
creates: /opt/postmaster/git/db/migrations
2 changes: 2 additions & 0 deletions ops/ansible/run_ansible.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
ansible-playbook -i "localhost," -c local /opt/postmaster/git/ops/ansible/site.yml
6 changes: 6 additions & 0 deletions ops/ansible/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This playbook deploys the whole application stack in this site.
- name: install postmaster
hosts: all

roles:
- postmaster_deploy
1 change: 1 addition & 0 deletions postmaster/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def add_default_configuration_settings():
except Exception:
db.session.rollback()


def add_ldap_user_to_db(username, display_name):
""" Adds an LDAP user stub in the Admins table of the database for flask_login
"""
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ def initialize():
return True

except Exception as e:
print "Unexpected error: {0}".format(e.message)
print("Unexpected error: {0}".format(e.message))
return False

return False

# Create a fresh database
initialize()


@pytest.fixture(scope='module')
def loggedin_client():
client = app.test_client()
Expand Down