Download:
child 3:862a025e0e2b
parent 1:028ca57b372d
2:88933f6c62bd
Anton Shestakov <engored@ya.ru>, Sat, 20 Feb 2016 15:57:54 +0800
import hgweb role

11 файлов изменено, 182 вставок(+), 0 удалений(-) [+]
roles/hgweb/files/.hgrc file | annotate | diff | comparison | revisions
roles/hgweb/files/requirements.txt file | annotate | diff | comparison | revisions
roles/hgweb/handlers/main.yml file | annotate | diff | comparison | revisions
roles/hgweb/tasks/appinstall.yml file | annotate | diff | comparison | revisions
roles/hgweb/tasks/main.yml file | annotate | diff | comparison | revisions
roles/hgweb/templates/etc/nginx/sites-available/hgweb file | annotate | diff | comparison | revisions
roles/hgweb/templates/etc/supervisor/conf.d/hgweb.conf file | annotate | diff | comparison | revisions
roles/hgweb/templates/gunicorn.conf file | annotate | diff | comparison | revisions
roles/hgweb/templates/hgweb.conf file | annotate | diff | comparison | revisions
roles/hgweb/templates/hgweb.py file | annotate | diff | comparison | revisions
roles/hgweb/vars/main.yml file | annotate | diff | comparison | revisions
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/files/.hgrc Sat Feb 20 15:57:54 2016 +0800
@@ -0,0 +1,2 @@
+[hostfingerprints]
+selenic.com = f0:40:cc:b9:46:62:b6:69:48:c5:1a:65:d0:34:35:22:b6:e0:1b:87
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/files/requirements.txt Sat Feb 20 15:57:54 2016 +0800
@@ -0,0 +1,3 @@
+eventlet
+gunicorn
+pygments
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/handlers/main.yml Sat Feb 20 15:57:54 2016 +0800
@@ -0,0 +1,9 @@
+---
+- name: make local
+ command: make --directory /home/{{ user }}/hg/ local
+ become: yes
+ become_user: '{{ user }}'
+
+- name: restart hgweb
+ supervisorctl: name=hgweb state=restarted
+...
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/tasks/appinstall.yml Sat Feb 20 15:57:54 2016 +0800
@@ -0,0 +1,40 @@
+---
+- name: Ensure required directories exist
+ file: path=/home/{{ user }}/{{ item }}/ state=directory
+ with_items:
+ - hgwebfiles
+ - repos
+
+- name: Add .hgrc
+ copy: src=.hgrc dest=/home/{{ user }}/.hgrc
+
+- name: Pull Mercurial {{ mercurial_rev }}
+ hg: repo={{ mercurial_url }} dest=/home/{{ user }}/hg/ revision={{ mercurial_rev }}
+ notify:
+ - make local
+ - restart hgweb
+ tags: [inert]
+
+- name: Pull Evolve {{ evolve_rev }}
+ hg: repo={{ evolve_url }} dest=/home/{{ user }}/evolve/ revision={{ evolve_rev }}
+ notify:
+ - restart hgweb
+ tags: [inert]
+
+- name: Add config files
+ template: src={{ item }} dest=/home/{{ user }}/hgwebfiles/{{ item }}
+ with_items:
+ - hgweb.py
+ - hgweb.conf
+ - gunicorn.conf
+ notify:
+ - restart hgweb
+
+- name: Copy requirements.txt
+ copy: src=requirements.txt dest=/home/{{ user }}/hgwebfiles/requirements.txt
+
+- name: Set up venv for gunicorn
+ pip: requirements=/home/{{ user }}/hgwebfiles/requirements.txt state=latest virtualenv=/home/{{ user }}/hgwebfiles/venv/
+ notify:
+ - restart hgweb
+...
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/tasks/main.yml Sat Feb 20 15:57:54 2016 +0800
@@ -0,0 +1,37 @@
+---
+- name: Create user
+ user: name={{ user }}
+
+- name: Install packages
+ apt: pkg={{ item }} state=present
+ with_items:
+ - build-essential
+ - mercurial
+ - python-dev
+ - python-virtualenv
+ tags: [packages, inert]
+
+- name: Install virtualenv
+ apt: pkg=virtualenv state=present
+ when: ansible_distribution_release == 'jessie'
+ tags: [packages, inert]
+
+- include: appinstall.yml
+ become: yes
+ become_user: '{{ user }}'
+
+- name: Add supervisor app
+ template: src=etc/supervisor/conf.d/hgweb.conf dest=/etc/supervisor/conf.d/hgweb.conf
+ notify:
+ - reload supervisor
+
+- name: Add {{ subdomain }}.{{ hostname }} Nginx site
+ template: src=etc/nginx/sites-available/hgweb dest=/etc/nginx/sites-available/{{ subdomain }}.{{ hostname }}
+ notify:
+ - restart nginx
+
+- name: Enable {{ subdomain }}.{{ hostname }} Nginx site
+ file: src=/etc/nginx/sites-available/{{ subdomain }}.{{ hostname }} dest=/etc/nginx/sites-enabled/50{{ subdomain }}.{{ hostname }} state=link
+ notify:
+ - restart nginx
+...
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/templates/etc/nginx/sites-available/hgweb Sat Feb 20 15:57:54 2016 +0800
@@ -0,0 +1,37 @@
+upstream hgweb {
+ server unix:/home/{{ user }}/hgwebfiles/socket fail_timeout=0;
+}
+
+server {
+ server_name {{ subdomain }}.{{ hostname }};
+
+ listen 80;
+ listen [::]:80;
+
+ access_log /var/log/nginx/{{ subdomain }}.{{ hostname }}.access.log;
+ error_log /var/log/nginx/{{ subdomain }}.{{ hostname }}.error.log;
+
+ root /home/{{ user }}/hg/mercurial/templates/;
+
+ location / {
+ limit_except GET {
+ deny all;
+ }
+
+ proxy_pass http://hgweb;
+ proxy_redirect off;
+ proxy_buffering off;
+
+ proxy_set_header Host $host;
+ proxy_set_header X-Scheme $scheme;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ proxy_set_header X-Real-Ip $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ }
+
+ location /static {
+ gzip on;
+ gzip_types text/plain text/css application/javascript text/javascript;
+ expires 30d;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/templates/etc/supervisor/conf.d/hgweb.conf Sat Feb 20 15:57:54 2016 +0800
@@ -0,0 +1,8 @@
+[program:hgweb]
+command = /home/{{ user }}/hgwebfiles/venv/bin/gunicorn --config=/home/{{ user }}/hgwebfiles/gunicorn.conf hgweb:application
+directory = /home/{{ user }}/hgwebfiles/
+process_name = hgweb
+user = {{ user }}
+stopsignal = INT
+numprocs = 1
+autorestart = true
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/templates/gunicorn.conf Sat Feb 20 15:57:54 2016 +0800
@@ -0,0 +1,6 @@
+bind = 'unix:/home/{{ user }}/hgwebfiles/socket'
+workers = {{ workers }}
+worker_class = 'eventlet'
+accesslog = '-'
+errorlog = '-'
+timeout = 30 # set to bigger values for serving bigger repos
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/templates/hgweb.conf Sat Feb 20 15:57:54 2016 +0800
@@ -0,0 +1,15 @@
+[paths]
+/ = /home/{{ user }}/repos/*
+
+[extensions]
+highlight =
+simple4server = /home/{{ user }}/evolve/hgext/simple4server.py
+
+[web]
+baseurl = http://{{ subdomain }}.{{ hostname }}/
+logourl = http://{{ subdomain }}.{{ hostname }}/
+contact = {{ contact }}
+staticurl = /static
+pygments_style = tango
+highlightfiles = size('<100k')
+highlightonlymatchfilename = True
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/templates/hgweb.py Sat Feb 20 15:57:54 2016 +0800
@@ -0,0 +1,15 @@
+# Path to repo or hgweb config to serve (see 'hg help hgweb')
+config = "/home/{{ user }}/hgwebfiles/hgweb.conf"
+
+# Uncomment and adjust if Mercurial is not installed system-wide
+# (consult "installed modules" path from 'hg debuginstall'):
+import sys; sys.path.insert(0, "/home/{{ user }}/hg/")
+
+# Uncomment to send python tracebacks to the browser if an error occurs:
+#import cgitb; cgitb.enable()
+
+# enable demandloading to reduce startup time
+from mercurial import demandimport; demandimport.enable()
+
+from mercurial.hgweb import hgweb
+application = hgweb(config)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/vars/main.yml Sat Feb 20 15:57:54 2016 +0800
@@ -0,0 +1,10 @@
+---
+contact: 'Me Myself <me@mydomain>'
+subdomain: hg
+user: hguser
+mercurial_url: https://selenic.com/hg
+mercurial_rev: stable
+evolve_url: http://42.netv6.net/evolve-main
+evolve_rev: stable
+workers: 1
+...