diff --git a/Rakefile b/Rakefile index 97276f4..3592db9 100644 --- a/Rakefile +++ b/Rakefile @@ -33,4 +33,5 @@ task :bootstrap_common => '.ssh_config' unless ENV['nodeps'] task 'converge:integration' => 'converge:database' + task 'converge:social' => 'converge:database' end diff --git a/config/roles/database_server.rb b/config/roles/database_server.rb index 1d63a19..1e7118d 100644 --- a/config/roles/database_server.rb +++ b/config/roles/database_server.rb @@ -5,4 +5,5 @@ run_list *[ 'recipe[redis]', 'recipe[postgresql::colab]', 'recipe[postgresql::gitlab]', + 'recipe[postgresql::noosfero]', ] diff --git a/config/roles/social_server.rb b/config/roles/social_server.rb index 1dda53f..ed9e3a0 100644 --- a/config/roles/social_server.rb +++ b/config/roles/social_server.rb @@ -1,3 +1,6 @@ name 'database_server' description 'Social networking server' -#run_list 'recipe[noosfero]' +run_list *[ + 'recipe[basics::nginx]', + 'recipe[noosfero]' +] diff --git a/cookbooks/colab/templates/01-apps.yaml.erb b/cookbooks/colab/templates/01-apps.yaml.erb index 7ab2b8a..3ce5820 100644 --- a/cookbooks/colab/templates/01-apps.yaml.erb +++ b/cookbooks/colab/templates/01-apps.yaml.erb @@ -2,3 +2,5 @@ PROXIED_APPS: gitlab: upstream: 'http://<%= node['peers']['integration'] %>:8081/gitlab/' + noosfero: + upstream: 'http://<%= node['peers']['social'] %>:8080/social/' diff --git a/cookbooks/noosfero/files/noosfero-default b/cookbooks/noosfero/files/noosfero-default new file mode 100644 index 0000000..9778fcc --- /dev/null +++ b/cookbooks/noosfero/files/noosfero-default @@ -0,0 +1,7 @@ +# MANAGED WITH CHEF; DO NOT MAKE MANUAL CHANGES + +export RAILS_RELATIVE_URL_ROOT=/social + +NOOSFERO_DIR="/usr/lib/noosfero" +NOOSFERO_USER="noosfero" +NOOSFERO_DATA_DIR="/var/lib/noosfero" diff --git a/cookbooks/noosfero/recipes/default.rb b/cookbooks/noosfero/recipes/default.rb new file mode 100644 index 0000000..42c8468 --- /dev/null +++ b/cookbooks/noosfero/recipes/default.rb @@ -0,0 +1,52 @@ +if node['platform'] == 'centos' + cookbook_file '/etc/yum.repos.d/noosfero.repo' do + owner 'root' + mode 0644 + end +end + +package 'noosfero' + +template '/etc/noosfero/database.yml' do + owner 'noosfero' + group 'noosfero' + mode '0600' + notifies :restart, 'service[noosfero]' +end + +# create DB schema +execute 'noosfero:schema' do + command 'RAILS_ENV=production bundle exec rake db:schema:load && RAILS_ENV=production bundle exec rake db:data:minimal' + cwd '/usr/lib/noosfero' + user 'noosfero' + not_if do + # if the profiles table already exists, the schema was already loaded + system("psql -h database -U noosfero --no-align --tuples-only -q -c 'select count(*) from profiles'") + end + notifies :restart, 'service[noosfero]' +end + +# TODO remote user auth +# TODO spb plugin +# TODO theme + +template '/etc/noosfero/thin.yml' do + owner 'root'; group 'root'; mode 0644 + notifies :restart, 'service[noosfero]' +end + +cookbook_file '/etc/default/noosfero' do + owner 'root'; group 'root'; mode 0644 + source 'noosfero-default' + notifies :restart, 'service[noosfero]' +end + +service 'noosfero' do + action [:enable, :start] +end + +template '/etc/nginx/conf.d/noosfero.conf' do + owner 'root'; group 'root'; mode 0644 + source 'nginx.conf.erb' + notifies :reload, 'service[nginx]' +end diff --git a/cookbooks/noosfero/templates/database.yml.erb b/cookbooks/noosfero/templates/database.yml.erb new file mode 100644 index 0000000..35ddd9a --- /dev/null +++ b/cookbooks/noosfero/templates/database.yml.erb @@ -0,0 +1,7 @@ +# MANAGED WITH CHEF. DO NOT MAKE MANUAL CHANGES +production: + adapter: postgresql + encoding: unicode + database: noosfero + host: <%= node['peers']['database'] %> + user: noosfero diff --git a/cookbooks/noosfero/templates/nginx.conf.erb b/cookbooks/noosfero/templates/nginx.conf.erb new file mode 100644 index 0000000..34d4f6a --- /dev/null +++ b/cookbooks/noosfero/templates/nginx.conf.erb @@ -0,0 +1,31 @@ +upstream noosfero { +<% (1..(`nproc`.strip.to_i)).each do |p| %> + server 127.0.0.1:<%= 9000 + p - 1 %> fail_timeout=10s; +<% end %> +} + +server { + listen *:8080; + server_name <%= node['config']['external_hostname'] %>; + + access_log /var/log/nginx/noosfero.access.log; + error_log /var/log/nginx/noosfero.error.log; + + root /usr/lib/noosfero/public; + location /social/ { + alias /usr/lib/noosfero/public/; + try_files $uri @noosfero_proxy; + } + try_files $uri @noosfero_proxy; + + location @noosfero_proxy { + proxy_pass http://noosfero; + 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; + } + +} diff --git a/cookbooks/noosfero/templates/thin.yml.erb b/cookbooks/noosfero/templates/thin.yml.erb new file mode 100644 index 0000000..a8b4189 --- /dev/null +++ b/cookbooks/noosfero/templates/thin.yml.erb @@ -0,0 +1,15 @@ +--- +chdir: /usr/lib/noosfero +environment: production +address: 127.0.0.1 +port: 9000 +timeout: 30 +log: log/thin.log +pid: tmp/pids/thin.pid +max_conns: 1024 +max_persistent_conns: 512 +require: [] +wait: 30 +daemonize: true +servers: <%= `nproc`.strip %> +prefix: /social diff --git a/cookbooks/postgresql/recipes/noosfero.rb b/cookbooks/postgresql/recipes/noosfero.rb new file mode 100644 index 0000000..db99355 --- /dev/null +++ b/cookbooks/postgresql/recipes/noosfero.rb @@ -0,0 +1,17 @@ +execute 'createuser:noosfero' do + command 'createuser noosfero' + user 'postgres' + only_if do + `sudo -u postgres -i psql --quiet --tuples-only -c "select count(*) from pg_user where usename = 'noosfero';"`.strip.to_i == 0 + end +end + +execute 'createdb:noosfero' do + command 'createdb --owner=noosfero noosfero' + user 'postgres' + only_if do + `sudo -u postgres -i psql --quiet --tuples-only -c "select count(1) from pg_database where datname = 'noosfero';"`.strip.to_i == 0 + end +end + + diff --git a/cookbooks/postgresql/templates/centos/pg_hba.conf.erb b/cookbooks/postgresql/templates/centos/pg_hba.conf.erb index 2b630b3..efcb384 100644 --- a/cookbooks/postgresql/templates/centos/pg_hba.conf.erb +++ b/cookbooks/postgresql/templates/centos/pg_hba.conf.erb @@ -9,3 +9,4 @@ host all all ::1/128 ident # TYPE DATABASE USER ADDRESS METHOD host colab colab <%= node['peers']['integration'] %>/32 trust host gitlab gitlab <%= node['peers']['integration'] %>/32 trust +host noosfero noosfero <%= node['peers']['social'] %>/32 trust diff --git a/test/colab_test.sh b/test/colab_test.sh index eec4e28..0edb92e 100644 --- a/test/colab_test.sh +++ b/test/colab_test.sh @@ -29,4 +29,8 @@ test_reverse_proxy_gitlab() { assertTrue 'Reverse proxy for gitlab' "curl --header 'Host: softwarepublico.dev' http://$integration/gitlab/public/projects | grep -i ''" } +test_reverse_proxy_noosfero() { + assertTrue 'Reverse proxy for noosfero' "curl --header 'Host: softwarepublico.dev' http://$integration/social/search/people | grep -i ''" +} + load_shunit2 diff --git a/test/noosfero_test.sh b/test/noosfero_test.sh new file mode 100644 index 0000000..051f3ed --- /dev/null +++ b/test/noosfero_test.sh @@ -0,0 +1,27 @@ +. $(dirname $0)/test_helper.sh + +test_database_connectivity() { + assertTrue 'noosfero database connectivity' 'run_on social psql -h database -U noosfero < /dev/null' +} + +test_noosfero_running() { + assertTrue 'Noosfero running' 'run_on social pgrep -u noosfero -f thin' +} + +test_noosfero_on_subdir() { + local meta="$(run_on social curl --fail http://localhost:9000/social | sed -e '/noosfero:root/ !d; s/^\s*//')" + assertEquals '' "$meta" +} + +test_reverse_proxy_noosfero() { + local meta="$(run_on social curl-host softwarepublico.dev http://localhost:8080/social | sed -e '/noosfero:root/ !d; s/^\s*//')" + assertEquals '' "$meta" +} + +test_reverse_proxy_static_files() { + local content_type="$(curl-host softwarepublico.dev --head http://$social:8080/social/images/noosfero-network.png | grep-header Content-Type)" + assertEquals "Content-Type: image/png" "$content_type" +} + + +load_shunit2 diff --git a/test/postgresql_test.sh b/test/postgresql_test.sh index 6885549..fe16ddd 100644 --- a/test/postgresql_test.sh +++ b/test/postgresql_test.sh @@ -12,5 +12,9 @@ test_gitlab_database_created() { assertTrue 'gitlab database created in PostgreSQL' 'run_on database sudo -u postgres -i psql gitlab < /dev/null' } +test_noosfero_database_created() { + assertTrue 'noosfero database created in PostgreSQL' 'run_on database sudo -u postgres -i psql noosfero < /dev/null' +} + load_shunit2 -- libgit2 0.21.2