Skip to content

Commit 89ae3da

Browse files
author
Roey Darwish Dror
committed
Merge branch 'release/0.27.0'
2 parents d6cee1e + 082265a commit 89ae3da

File tree

35 files changed

+289
-327
lines changed

35 files changed

+289
-327
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ celerybeat.pid
5858
client_secret.json
5959
webapp/tmp
6060
conf.d
61+
tests/.cache

_lib/db.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ def ensure():
5858
elif match.group('db_type') == 'postgresql':
5959
_create_postgres(match)
6060

61-
with app.app_context():
62-
db.create_all()
6361
logbook.info("DB successfully created")
6462

6563

_lib/deployment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import os
2-
import sys
32
from multiprocessing import cpu_count
43

54
import click
65

7-
from .bootstrapping import from_env, from_env_bin, requires_env, from_project_root
6+
from .bootstrapping import from_env_bin, requires_env, from_project_root
87
from .params import APP_NAME
98

109
_UNIX_SOCKET_NAME = "/var/run/{}/wsgi.sock".format(APP_NAME)
@@ -13,6 +12,7 @@
1312
@click.command()
1413
@requires_env("app")
1514
def run_gunicorn():
15+
num_workers = (2 * cpu_count()) + 1
1616
gunicorn_bin = from_env_bin('gunicorn')
17-
cmd = [gunicorn_bin, '--log-syslog', '-b', 'unix://{}'.format(_UNIX_SOCKET_NAME), 'flask_app.wsgi:app', '--chdir', from_project_root('.')]
17+
cmd = [gunicorn_bin, '--log-syslog', '-b', 'unix://{}'.format(_UNIX_SOCKET_NAME), 'flask_app.wsgi:app', '--chdir', from_project_root('.'), '-w', str(num_workers)]
1818
os.execv(gunicorn_bin, cmd)

ansible/roles/db/handlers/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
- name: restart postgres
3+
service: name=postgresql state=restarted

ansible/roles/db/tasks/main.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,26 @@
4444
- name: enable local authentication in postresql
4545
lineinfile: dest=/var/lib/pgsql/data/pg_hba.conf regexp="^host.*::1/128" line="host all all ::1/128 md5" state=present
4646
when: ansible_distribution == 'CentOS'
47+
- name: config postgres local hosts
48+
lineinfile: dest=/etc/postgresql/{{postgres_version}}/main/pg_hba.conf regexp='^local.*all.*all.*[pm]' line="local all all md5"
49+
notify: restart postgres
50+
when: groups['db'][0] != groups['webapp'][0] and ansible_distribution == 'Debian'
51+
- name: enable remote authentication in postresql
52+
lineinfile: dest=/etc/postgresql/{{postgres_version}}/main/pg_hba.conf regexp='0\.0\.0\.0' line="host all all 0.0.0.0/0 md5"
53+
notify: restart postgres
54+
when: groups['db'][0] != groups['webapp'][0] and ansible_distribution == 'Debian'
55+
- name: config postgresql
56+
lineinfile: dest=/etc/postgresql/{{postgres_version}}/main/postgresql.conf regexp=^listen_addresses line="listen_addresses='*'"
57+
notify: restart postgres
58+
when: groups['db'][0] != groups['webapp'][0] and ansible_distribution == 'Debian'
4759
- service: name=postgresql state=started enabled=True
4860
- name: setup db
4961
action: postgresql_db name={{app_name}} encoding=utf8
50-
sudo_user: postgres
51-
sudo: true
62+
become: true
63+
become_user: postgres
5264
tags: db
5365
- name: setup db user
5466
action: postgresql_user name={{app_name}} password={{app_name}} db={{app_name}} priv=ALL role_attr_flags=SUPERUSER
55-
sudo_user: postgres
56-
sudo: true
67+
become: true
68+
become_user: postgres
5769
tags: db

ansible/roles/db/vars/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
postgres_version: 9.4

ansible/roles/webapp/tasks/install_sources.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
- name: untar to temporary location
22
shell: cd /tmp/ && rm -rf {{webapp_archive_location}}.untarred && mkdir {{webapp_archive_location}}.untarred && cd {{webapp_archive_location}}.untarred && tar xzf {{webapp_archive_location}}
3-
- name: rsync to src dir
4-
shell: rsync -avP --delete {{webapp_archive_location}}.untarred/ {{src_root}}/
3+
- synchronize: src="{{webapp_archive_location}}.untarred/" dest="{{src_root}}/"
4+
delegate_to: "{{ inventory_hostname }}"
55
- name: bootstrap
66
shell: python {{src_root}}/manage.py bootstrap --app
77
- name: ensure private config
88
shell: python {{src_root}}/manage.py ensure-secret {{deploy_root}}/conf.d/000-private.yml
99
- name: migrate db
1010
shell: cd {{src_root}} && python manage.py db upgrade
1111
- name: fix permissions
12-
shell: chown -R {{user_name}}:{{group_name}} {{deploy_root}}
12+
file: path={{deploy_root}} owner={{user_name}} group={{group_name}} recurse=true
1313
- name: fix permissions of static folder
1414
file: path={{src_root}}/static owner={{nginx_user}} group={{nginx_group}} recurse=true state=directory
1515
- name: ensure that nginx sites directory exists

ansible/roles/webapp/tasks/main.yml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,13 @@
5252
- name: ensure /var/run/{{app_name}} directory on boot
5353
template: src=../templates/tmpfiles.d.conf.j2 dest=/etc/tmpfiles.d/{{app_name}}.conf
5454
- file: path=/var/run/{{app_name}} state=directory mode=0770 owner={{app_name}} group={{nginx_group}}
55-
- name: install systemd service
56-
action: template src=../templates/gunicorn.service.j2 dest=/lib/systemd/system/{{app_name}}-wsgi.service
57-
when: sources.changed or configuration.changed
58-
register: systemd_change
59-
- name: install systemd service (Celery worker)
60-
action: template src=../templates/celery-worker.service.j2 dest=/lib/systemd/system/{{app_name}}-celery-worker.service
61-
when: sources.changed or configuration.changed
62-
register: systemd_change
63-
- name: install systemd service (Celery beat)
64-
action: template src=../templates/celery-beat.service.j2 dest=/lib/systemd/system/{{app_name}}-celery-beat.service
65-
when: sources.changed or configuration.changed
66-
register: systemd_change
55+
56+
- name: Configure systemd services
57+
include: systemd_services.yml
58+
register: systemd_services
6759
- name: reload systemd daemon
6860
action: shell systemctl daemon-reload
69-
when: systemd_change.changed
61+
when: systemd_services.changed
7062
- name: enable the services
7163
action: service name={{item}} enabled=true state=started
7264
with_items:
@@ -79,6 +71,6 @@
7971
- "{{app_name}}-wsgi"
8072
- "{{app_name}}-celery-worker"
8173
- "{{app_name}}-celery-beat"
82-
when: systemd_change.changed or sources.changed or configuration.changed
74+
when: systemd_services.changed or sources.changed or configuration.changed
8375
- name: try to get local page
8476
shell: curl http://localhost/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- name: install systemd service
2+
action: template src=../templates/gunicorn.service.j2 dest=/lib/systemd/system/{{app_name}}-wsgi.service
3+
when: sources.changed or configuration.changed
4+
- name: install systemd service (Celery worker)
5+
action: template src=../templates/celery-worker.service.j2 dest=/lib/systemd/system/{{app_name}}-celery-worker.service
6+
when: sources.changed or configuration.changed
7+
- name: install systemd service (Celery beat)
8+
action: template src=../templates/celery-beat.service.j2 dest=/lib/systemd/system/{{app_name}}-celery-beat.service
9+
when: sources.changed or configuration.changed
10+

ansible/roles/webapp/templates/deployment_conf.yml.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
SQLALCHEMY_DATABASE_URI: "postgresql://{{app_name}}:{{app_name}}@localhost/{{app_name}}"
1+
SQLALCHEMY_DATABASE_URI: "postgresql://{{app_name}}:{{app_name}}@{% if groups['db'][0] != groups['webapp'][0] %}{{groups['db'][0]}}{% else %}localhost{% endif %}/{{app_name}}"
2+
23
STORAGE_PATH: /var/scotty
34
SENTRY_DSN: "{{sentry_dsn}}"
45

0 commit comments

Comments
 (0)