Skip to content

Commit

Permalink
Parametize CKAN's repository.
Browse files Browse the repository at this point in the history
This was a problem faced by willhelmbot at
http://stackoverflow.com/questions/16242798/how-to-link-a-ckan-installation-in-vagrant-to-a-cloned-repo-in-the-host-os/16243862#16243862

He wanted to clone his own repository, instead of the official CKAN's, and also
wanted to clone it inside /vagrant/ckan, so he could do changes using the host
OS.

This solves both.
  • Loading branch information
vitorbaptista committed May 7, 2013
1 parent 63a0340 commit 38b788b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
11 changes: 6 additions & 5 deletions cookbooks/ckan/recipes/ckanext.rb
Expand Up @@ -2,7 +2,8 @@
HOME = "/home/#{USER}" HOME = "/home/#{USER}"
ENV['VIRTUAL_ENV'] = "#{HOME}/pyenv" ENV['VIRTUAL_ENV'] = "#{HOME}/pyenv"
ENV['PATH'] = "#{ENV['VIRTUAL_ENV']}/bin:#{ENV['PATH']}" ENV['PATH'] = "#{ENV['VIRTUAL_ENV']}/bin:#{ENV['PATH']}"
SOURCE_DIR = "#{ENV['VIRTUAL_ENV']}/src/ckan" SOURCE_DIR = "#{ENV['VIRTUAL_ENV']}/src"
CKAN_DIR = "#{SOURCE_DIR}/ckan"


# Create Database # Create Database
pg_user "ckanuser" do pg_user "ckanuser" do
Expand All @@ -23,24 +24,24 @@
# Configure database variables # Configure database variables
execute "Set up datastore database's urls" do execute "Set up datastore database's urls" do
user USER user USER
cwd SOURCE_DIR cwd CKAN_DIR
command "sed -i -e 's/.*datastore.write_url.*/ckan.datastore.write_url=postgresql:\\/\\/ckanuser:pass@localhost\\/datastore/;s/.*datastore.read_url.*/ckan.datastore.read_url=postgresql:\\/\\/readonlyuser:pass@localhost\\/datastore/' development.ini" command "sed -i -e 's/.*datastore.write_url.*/ckan.datastore.write_url=postgresql:\\/\\/ckanuser:pass@localhost\\/datastore/;s/.*datastore.read_url.*/ckan.datastore.read_url=postgresql:\\/\\/readonlyuser:pass@localhost\\/datastore/' development.ini"
end end


# Set permissions # Set permissions
execute "don't ask for postgres password when setting database's permissions" do execute "don't ask for postgres password when setting database's permissions" do
user USER user USER
cwd "#{SOURCE_DIR}/ckanext/datastore/bin" cwd "#{CKAN_DIR}/ckanext/datastore/bin"
command "sed -i -e 's/-W//g' datastore_setup.py" command "sed -i -e 's/-W//g' datastore_setup.py"
end end


execute "set permissions" do execute "set permissions" do
cwd SOURCE_DIR cwd CKAN_DIR
command "paster datastore set-permissions postgres" command "paster datastore set-permissions postgres"
end end


execute "run other tests" do execute "run other tests" do
user USER user USER
cwd SOURCE_DIR cwd CKAN_DIR
command "nosetests --ckan --with-pylons=test-core.ini --nologcapture --cover-package=ckanext.datastore ckanext/datastore/tests -x" command "nosetests --ckan --with-pylons=test-core.ini --nologcapture --cover-package=ckanext.datastore ckanext/datastore/tests -x"
end end
46 changes: 35 additions & 11 deletions cookbooks/ckan/recipes/default.rb
Expand Up @@ -5,10 +5,12 @@
include_recipe "java" include_recipe "java"


USER = node[:user] USER = node[:user]
REPOSITORY = node[:repository]
HOME = "/home/#{USER}" HOME = "/home/#{USER}"
ENV['VIRTUAL_ENV'] = "#{HOME}/pyenv" ENV['VIRTUAL_ENV'] = "#{HOME}/pyenv"
ENV['PATH'] = "#{ENV['VIRTUAL_ENV']}/bin:#{ENV['PATH']}" ENV['PATH'] = "#{ENV['VIRTUAL_ENV']}/bin:#{ENV['PATH']}"
SOURCE_DIR = "#{ENV['VIRTUAL_ENV']}/src/ckan" SOURCE_DIR = "#{ENV['VIRTUAL_ENV']}/src"
CKAN_DIR = "#{SOURCE_DIR}/ckan"


# Create user # Create user
user USER do user USER do
Expand All @@ -25,17 +27,32 @@
action :create action :create
end end


# Create source dir
directory SOURCE_DIR do
owner USER
group USER
end

# Clone CKAN
git CKAN_DIR do
user USER
group USER
repository REPOSITORY
reference "master"
enable_submodules true
end

# Install CKAN Package # Install CKAN Package
python_pip "git+https://github.com/okfn/ckan.git#egg=ckan" do python_pip CKAN_DIR do
user USER user USER
group USER group USER
virtualenv ENV['VIRTUAL_ENV'] virtualenv ENV['VIRTUAL_ENV']
options "-e" options "--exists-action=i -e"
action :install action :install
end end


# Install CKAN's requirements # Install CKAN's requirements
python_pip "#{SOURCE_DIR}/pip-requirements.txt" do python_pip "#{CKAN_DIR}/pip-requirements.txt" do
user USER user USER
group USER group USER
virtualenv ENV['VIRTUAL_ENV'] virtualenv ENV['VIRTUAL_ENV']
Expand All @@ -49,11 +66,18 @@
password "pass" password "pass"
end end


pg_database "ckantest" do pg_database "ckan_dev" do
owner "ckanuser" owner "ckanuser"
encoding "utf8" encoding "utf8"
end end


# Configure database variables
execute "Set up database's urls" do
user USER
cwd CKAN_DIR
command "sed -i -e 's/.*sqlalchemy.url.*/sqlalchemy.url=postgresql:\\/\\/ckanuser:pass@localhost\\/ckan_dev/;' development.ini"
end

# Install and configure Solr # Install and configure Solr
package "solr-jetty" package "solr-jetty"
template "/etc/default/jetty" do template "/etc/default/jetty" do
Expand All @@ -62,7 +86,7 @@
}) })
end end
execute "setup solr's schema" do execute "setup solr's schema" do
command "sudo ln -f -s #{SOURCE_DIR}/ckan/config/solr/schema-2.0.xml /etc/solr/conf/schema.xml" command "sudo ln -f -s #{CKAN_DIR}/ckan/config/solr/schema-2.0.xml /etc/solr/conf/schema.xml"
action :run action :run
end end
service "jetty" do service "jetty" do
Expand All @@ -73,20 +97,20 @@
# Create configuration file # Create configuration file
execute "make paster's config file and setup solr_url and ckan.site_id" do execute "make paster's config file and setup solr_url and ckan.site_id" do
user USER user USER
cwd SOURCE_DIR cwd CKAN_DIR
command "paster make-config ckan development.ini --no-interactive && sed -i -e 's/.*solr_url.*/solr_url=http:\\/\\/127.0.0.1:8983\\/solr/;s/.*ckan\\.site_id.*/ckan.site_id=vagrant_ckan/' development.ini" command "paster make-config ckan development.ini --no-interactive && sed -i -e 's/.*solr_url.*/solr_url=http:\\/\\/127.0.0.1:8983\\/solr/;s/.*ckan\\.site_id.*/ckan.site_id=vagrant_ckan/' development.ini"
creates "#{SOURCE_DIR}/development.ini" creates "#{CKAN_DIR}/development.ini"
end end


# Generate database # Generate database
execute "create database tables" do execute "create database tables" do
user USER user USER
cwd SOURCE_DIR cwd CKAN_DIR
command "paster --plugin=ckan db init" command "paster --plugin=ckan db init"
end end


# Run tests # Run tests
python_pip "#{SOURCE_DIR}/pip-requirements-test.txt" do python_pip "#{CKAN_DIR}/pip-requirements-test.txt" do
user USER user USER
group USER group USER
virtualenv ENV['VIRTUAL_ENV'] virtualenv ENV['VIRTUAL_ENV']
Expand All @@ -96,6 +120,6 @@


execute "running tests with SQLite" do execute "running tests with SQLite" do
user USER user USER
cwd SOURCE_DIR cwd CKAN_DIR
command "nosetests --ckan ckan" command "nosetests --ckan ckan"
end end
1 change: 1 addition & 0 deletions solo.json
Expand Up @@ -5,6 +5,7 @@
"recipe[ckan::ckanext]" "recipe[ckan::ckanext]"
], ],
"user": "ckan", "user": "ckan",
"repository": "https://github.com/okfn/ckan.git",
"postgresql": { "postgresql": {
"version": "9.1", "version": "9.1",
"ssl": false "ssl": false
Expand Down

0 comments on commit 38b788b

Please sign in to comment.