-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcruzalinhas.yml
104 lines (92 loc) · 3.51 KB
/
cruzalinhas.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
---
- hosts: production
remote_user: "{{ admin_user }}"
handlers:
- name: reload supervisor
shell: "service supervisor restart; supervisorctl reload"
become: yes
- name: restart app
shell: "supervisorctl restart cruzalinhas"
become: yes
roles:
- role: chesterbr.vault
- role: chesterbr.nginx
nginx_sites:
- server:
file_name: cruzalinhas.chester.me
root: "{{ cruzalinhas_checkout_dir }}/public"
server_name: cruzalinhas.chester.me
location1: { name: '~ .*', proxy_pass: 'http://cruzalinhas_rails' }
- server:
file_name: redirects.cruzalinhas.com
server_name: cruzalinhas.com www.cruzalinhas.com www.cruzalinhas.com.br cruzalinhas.com.br
return: 301 $scheme://cruzalinhas.chester.me$request_uri
- role: chesterbr.ruby
ruby_user: "{{ server_user }}"
tasks:
- name: Install prereq packages
apt: name={{ packages }} state=present
become: yes
vars:
packages:
- git
- libsqlite3-dev
- xvfb
- firefox
- python-pip
- default-jdk
- nodejs
- makepasswd
- supervisor
- name: Add cruzalinhas upstream to server config
become: yes
lineinfile: dest=/etc/nginx/sites-enabled/cruzalinhas.chester.me insertbefore="BOF" line="upstream cruzalinhas_rails { server 127.0.0.1:3000; }"
notify:
- reload nginx
- name: Ensure code repository is at latest version
git: repo=https://github.com/chesterbr/cruzalinhas.git
accept_hostkey=true
dest={{ cruzalinhas_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 {{ cruzalinhas_checkout_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 for cruzalinhas
command: bash -lc "cd {{ cruzalinhas_checkout_dir }}; gem install bundle; bundle install"
register: bundler
changed_when: '"Installing" in bundler.stdout'
become: yes
become_user: "{{ server_user }}"
tags:
- update_app
- name: Configures cruzalinhas back-end to run under supervisor (from source dir)
template: src=templates/cruzalinhas.conf.supervisor.j2 dest=/etc/supervisor/conf.d/cruzalinhas.conf
become: yes
notify: reload supervisor
tags:
- configure_supervisor
- name: Download and update SPTrans data
command: bash -lc "cd {{ cruzalinhas_checkout_dir }}; DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bundle exec rake sptrans:import"
notify: restart app
become: yes
become_user: "{{ server_user }}"
tags:
- update_sptrans_data
# # TODO:
# # config crontab with download & update sptrans