diff --git a/config/roles/integration_server.rb b/config/roles/integration_server.rb index 9a9603a..e286841 100644 --- a/config/roles/integration_server.rb +++ b/config/roles/integration_server.rb @@ -3,4 +3,4 @@ description "Application that manages user authentication, visual integration an # TODO colab and mailman-api should be able to run in separate hosts at some # point in the future -run_list 'recipe[mailman-api]', 'recipe[colab]' +run_list 'recipe[mailman-api]', 'recipe[colab]', 'recipe[basics::nginx]', 'recipe[colab::nginx]' diff --git a/cookbooks/basics/files/default/nginx.repo b/cookbooks/basics/files/default/nginx.repo new file mode 100644 index 0000000..3c6aa13 --- /dev/null +++ b/cookbooks/basics/files/default/nginx.repo @@ -0,0 +1,7 @@ +# nginx.repo + +[nginx] +name=nginx repo +baseurl=http://nginx.org/packages/centos/7/$basearch/ +gpgcheck=0 +enabled=1 diff --git a/cookbooks/basics/recipes/nginx.rb b/cookbooks/basics/recipes/nginx.rb new file mode 100644 index 0000000..0c22182 --- /dev/null +++ b/cookbooks/basics/recipes/nginx.rb @@ -0,0 +1,12 @@ +cookbook_file '/etc/yum.repos.d/nginx.repo' do + owner 'root' + group 'root' + mode 0644 +end + +package 'nginx' + +service 'nginx' do + action :start + supports :restart => true +end diff --git a/cookbooks/colab/recipes/nginx.rb b/cookbooks/colab/recipes/nginx.rb new file mode 100644 index 0000000..42d1ba0 --- /dev/null +++ b/cookbooks/colab/recipes/nginx.rb @@ -0,0 +1,6 @@ +template '/etc/nginx/conf.d/colab.conf' do + owner 'root' + group 'root' + mode 0644 + notifies :restart, 'service[nginx]' +end diff --git a/cookbooks/colab/templates/colab.conf.erb b/cookbooks/colab/templates/colab.conf.erb new file mode 100644 index 0000000..3f545e2 --- /dev/null +++ b/cookbooks/colab/templates/colab.conf.erb @@ -0,0 +1,29 @@ +upstream colab { + server 127.0.0.1:8001 fail_timeout=10s; +} + +server { + listen *:80; + + server_name <%= node['config']['external_hostname'] %> localhost; + + access_log /var/log/nginx/colab.access.log; + error_log /var/log/nginx/colab.error.log; + + location / { + root /usr/share/nginx/colab; + try_files $uri @colab-app; + } + + location @colab-app { + proxy_pass http://colab; + proxy_read_timeout 90; + proxy_connect_timeout 90; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} + +# vim: ft=nginx diff --git a/test/colab_test.sh b/test/colab_test.sh index 5e83727..cc7a022 100644 --- a/test/colab_test.sh +++ b/test/colab_test.sh @@ -16,4 +16,14 @@ test_colab_responds() { assertTrue 'colab responds' 'run_on integration curl --fail http://localhost:8001' } +test_nginx_responds() { + assertTrue 'nginx reponds' 'run_on integration curl --fail http://localhost' +} + +test_nginx_virtualhost() { + local ip="$(grep integration: nodes.yaml | cut -d : -f 2)" + local title="$(curl --silent --header 'Host: beta.softwarepublico.gov.br' http://$ip/dashboard | grep '