|
| 1 | +--- |
| 2 | +# I prefer that my hosts are unaware of the code repo, and for that reason |
| 3 | +# I don't pull code from a remote git repo, but rather archive it, and |
| 4 | +# extract the archive on the remote. |
| 5 | +- name: Create latest code archive |
| 6 | + local_action: shell cd "../" && |
| 7 | + git archive --format=tar {{ git_branch }} | gzip >{{ webapp_name }}-{{ git_branch }}.tar.gz |
| 8 | + |
| 9 | + |
| 10 | +- name: Extract archive on remote |
| 11 | + unarchive: src=../{{ webapp_name }}-{{ git_branch }}.tar.gz dest={{ webapp_dir }}/ |
| 12 | + |
| 13 | + |
| 14 | +# We may not always want to run bootstrap, but the method below with never |
| 15 | +# run again after it was first bootstrapped. We may do something about this |
| 16 | +# in future. Maybe a variable or flag to force bootstrap to run? |
| 17 | +- name: Bootstrap webapp |
| 18 | + command: python2.7 -S bootstrap.py |
| 19 | + args: |
| 20 | + chdir: "{{ webapp_dir }}" |
| 21 | + creates: "{{ webapp_dir }}/bin/buildout" |
| 22 | + |
| 23 | + |
| 24 | +- name: Run buildout and install dependencies |
| 25 | + command: bin/buildout |
| 26 | + args: |
| 27 | + chdir: "{{ webapp_dir }}" |
| 28 | + tags: run_buildout |
| 29 | + |
| 30 | + |
| 31 | +- name: Collect django app static media |
| 32 | + command: bin/{{ webapp_name }} collectstatic --noinput |
| 33 | + args: |
| 34 | + chdir: "{{ webapp_dir }}" |
| 35 | + |
| 36 | + |
| 37 | +- name: Create database tables |
| 38 | + command: bin/{{ webapp_name }} syncdb --noinput |
| 39 | + args: |
| 40 | + chdir: "{{ webapp_dir }}" |
| 41 | + |
| 42 | + |
| 43 | +- name: Migrate database |
| 44 | + command: bin/{{ webapp_name }} migrate |
| 45 | + args: |
| 46 | + chdir: "{{ webapp_dir }}" |
| 47 | + notify: |
| 48 | + - Restart webapp |
| 49 | + |
| 50 | + |
| 51 | +- name: Create webapp nginx config |
| 52 | + template: src=nginx.conf.j2 |
| 53 | + dest=~/local/nginx/sites-enabled/{{ webapp_name }}.conf |
| 54 | + mode=0644 |
| 55 | + notify: |
| 56 | + - Restart nginx |
| 57 | + |
| 58 | + |
| 59 | +- name: Create supervisor config for our webapp |
| 60 | + template: src=webapp_supervisor.ini.j2 |
| 61 | + dest=~/local/etc/supervisord/{{ webapp_name }}.ini |
| 62 | + mode=0644 |
| 63 | + notify: |
| 64 | + - Reload supervisord |
| 65 | + - Restart webapp |
| 66 | + |
| 67 | + |
| 68 | +## Set up our cron jobs |
| 69 | +# The examples here is because I normally use django mailer as a simple |
| 70 | +# mail Queue |
| 71 | +# - name: <your_app_name> - Send mail cron job |
| 72 | +# cron: name="send mail" |
| 73 | +# job="{{ webapp_dir }}/bin/{{ webapp_name }} send_mail >> {{ webapp_logs }}/cron_mail.log 2>&1" |
| 74 | + |
| 75 | +# - name: <your_app_name> - Retry mail cron job |
| 76 | +# cron: name="retry deferred mail" minute="0,20,40" |
| 77 | +# job="{{ webapp_dir }}/bin/{{ webapp_name }} retry_deferred >> {{ webapp_logs }}/cron_mail_deferred.log 2>&1" |
0 commit comments