Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Vagrant+chef support #69

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
# Ignore bundler config.
/.bundle

# Ignore vagrant config
/.vagrant
/Berksfile.lock

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
Expand Down
4 changes: 4 additions & 0 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "https://supermarket.getchef.com"

cookbook 'participacion', path: File.join(File.dirname(__FILE__), 'chef', 'participacion')
cookbook 'postgresql', '~> 3.4.20'
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ Para ejecutar los tests:
bundle exec bin/rspec
```

## Vagrant

Prerequisitos:

* Instalar [Vagrant](http://www.vagrantup.com/downloads.html)
* Instalar [ChefDK](https://downloads.chef.io/chef-dk/)
* Plugin de Berkshelf de vagrant ```vagrant plugin install vagrant-berkshelf```

Uso:

```vagrant up``` y abrir el navegador en http://127.0.0.1:8888

```vagrant destroy``` para destruir la maquina virtual



## Licencia

El código de este proyecto está publicado bajo la licencia MIT (ver MIT-license.md)
Expand Down
22 changes: 22 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Vagrant.configure("2") do |config|
config.vm.box = "opscode_debian-8.1"
config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_debian-8.1_chef-provisionerless.box"
config.vm.hostname = "participacion"
config.vm.network "forwarded_port", guest: 80, host: 8888
config.vm.synced_folder '.', '/vagrant', owner: "www-data", group: "www-data"

config.vm.provider "virtualbox" do |v|
v.memory = 1024
v.cpus = 1
v.customize ["modifyvm", :id, "--ioapic", "on"]
end

config.vm.provision :chef_solo do |chef|
chef.log_level = ENV.fetch("CHEF_LOG", "info").downcase.to_sym
chef.formatter = ENV.fetch("CHEF_FORMAT", "null").downcase.to_sym
chef.add_recipe 'participacion'
chef.cookbooks_path = 'chef'
chef.json.merge!(JSON.parse(File.read("Vagrantfile.json")))
end

end
17 changes: 17 additions & 0 deletions Vagrantfile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"postgresql": {
"password": {
"postgres": "supersecret_password"
}
},
"participacion": {
"app": {
"base_dir": "/vagrant"
},
"db": {
"name": "participacion_development",
"username": "participacion",
"password": "participacion"
}
}
}
2 changes: 2 additions & 0 deletions chef/participacion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Participacion chef recipe
=========================
4 changes: 4 additions & 0 deletions chef/participacion/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
default['participacion']['app']['base_dir'] = ""
default['participacion']['db']['name'] = "participacion"
default['participacion']['db']['username'] = "participacion"
default['participacion']['db']['password'] = "participacion"
11 changes: 11 additions & 0 deletions chef/participacion/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name 'participacion'
maintainer 'Ayuntamiento Madrid'
license 'MIT'
description 'Installs/Configures participacion project'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.1.0'

depends 'apt'
depends 'apache2'
depends 'postgresql'
depends 'database'
82 changes: 82 additions & 0 deletions chef/participacion/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
case node['platform']
when "debian", "ubuntu"
include_recipe "apt"
package "ca-certificates"
end

# Web server
include_recipe 'apache2'

case node['platform']
when "debian", "ubuntu"
package 'libapache2-mod-passenger'
apache_module 'passenger'
end

# Database
include_recipe 'postgresql::server'
include_recipe 'database::postgresql'

db_connection_info = {
:host => '127.0.0.1',
:port => node['postgresql']['config']['port'],
:username => 'postgres',
:password => node['postgresql']['password']['postgres']
}

postgresql_database node['participacion']['db']['name'] do
connection db_connection_info
action :create
end

postgresql_database_user node['participacion']['db']['username'] do
connection db_connection_info
password node['participacion']['db']['password']
action :create
end

# App
template "#{node['participacion']['app']['base_dir']}/config/database.yml" do
source 'database.yml.erb'
owner 'www-data'
group 'www-data'
mode '0644'
variables({
:db_name => node['participacion']['db']['name'],
:db_username => node['participacion']['db']['username'],
:db_password => node['participacion']['db']['password']
})
end

case node['platform']
when "debian", "ubuntu"
package 'bundler'
package 'ruby-execjs'
end

bash 'Configure and install app' do
user 'root'
cwd node['participacion']['app']['base_dir']
code <<-EOH
cp config/secrets.yml.example config/secrets.yml
bundler install
rake db:migrate
EOH
end

apache_site "000-default" do
enable false
notifies :restart, "service[apache2]"
end

web_app "participacion" do
template "apache2/participacion.conf.erb"
docroot "#{node['participacion']['app']['base_dir']}/public"
notifies :restart, "service[apache2]"
end






Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
RackEnv development

<VirtualHost *:80>
DocumentRoot <%= @params[:docroot] %>
<Directory <%= @params[:docroot] %>>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
11 changes: 11 additions & 0 deletions chef/participacion/templates/default/database.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
default: &default
adapter: postgresql
encoding: unicode
host: localhost
pool: 5

development:
<<: *default
database: <%= @db_name %>
username: <%= @db_username %>
password: <%= @db_password %>