-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtotransit.yml
112 lines (98 loc) · 3.73 KB
/
totransit.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
---
- hosts: production
remote_user: "{{ admin_user }}"
handlers:
- name: reload supervisor # without restarting other supervised apps
shell: "supervisorctl update; supervisorctl reread"
become: yes
- name: restart app
shell: "supervisorctl restart totransit"
become: yes
roles:
- role: chesterbr.nginx
nginx_sites:
- server:
file_name: totransit.chester.me
root: "{{ totransit_app_dir }}/public"
server_name: totransit.chester.me
location1: { name: '~ .*', proxy_pass: 'http://totransit_rails' }
- role: chesterbr.ruby
ruby_user: "{{ server_user }}"
tags: update_app
tasks:
- name: Install prereq packages
apt: name={{ packages }} state=present
become: yes
vars:
packages:
- git
- libsqlite3-dev
- supervisor
- libyaml-dev # required by ruby psych gem
- name: Add totransit upstream to server config
become: yes
lineinfile: dest=/etc/nginx/sites-enabled/totransit.chester.me insertbefore="BOF" line="upstream totransit_rails { server 127.0.0.1:3001; }"
notify:
- reload nginx
- name: Ensure code repository is at latest version
git: repo=https://github.com/chesterbr/toronto-transit-time.git
accept_hostkey=true
dest={{ totransit_checkout_dir }}
version=main
notify: restart app
become: yes
become_user: "{{ server_user }}"
tags:
- update_app
- name: Ensure we're always in production rails environment
lineinfile: dest=~/.profile line="export RAILS_ENV=production" regexp="^export RAILS_ENV"
become: yes
become_user: "{{ server_user }}"
- name: "Install ruby required by the code (e.g.: .ruby_version)"
shell: bash -lc "cd {{ totransit_app_dir }}; CONFIGURE_OPTS=\"--disable-install-rdoc\" yes \\n | rbenv install --skip-existing"
register: ruby_install_result
changed_when: "'Installed' in ruby_install_result.stderr"
failed_when: ruby_install_result.rc != 0 and not (ruby_install_result.stderr is search('^rbenv.*versions.*already exists$'))
notify: restart app
become: yes
become_user: "{{ server_user }}"
tags:
- update_app
- name: Ensure we have all gem dependencies
command: bash -lc "cd {{ totransit_app_dir }}; gem install bundler; bundle install --deployment"
register: bundler
changed_when: '"Installing" in bundler.stdout'
become: yes
become_user: "{{ server_user }}"
tags:
- update_app
- name: Configures totransit back-end to run under supervisor (from source dir)
template: src=templates/totransit.conf.supervisor.j2 dest=/etc/supervisor/conf.d/totransit.conf
become: yes
notify: reload supervisor
tags:
- configure_supervisor
- name: Initialize database
command: bash -lc "cd {{ totransit_app_dir }}; bundle exec rake db:create"
become: yes
become_user: "{{ server_user }}"
- name: Migrate database
command: bash -lc "cd {{ totransit_app_dir }}; bundle exec rake db:migrate"
become: yes
become_user: "{{ server_user }}"
tags:
- update_app
- name: Add crontab tasks from whenever
command: bash -lc "cd {{ totransit_app_dir }}; bundle exec whenever -i"
notify: restart app
become: yes
become_user: "{{ server_user }}"
tags:
- update_app
- name: Do a first load of the ttc data
command: bash -lc "cd {{ totransit_app_dir }}; DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bundle exec rake db:reset ttc:crawl"
notify: restart app
become: yes
become_user: "{{ server_user }}"
tags:
- load_ttc_data