basho-labs / riak-chef-cookbook

Chef cookbook for Riak
https://supermarket.chef.io/cookbooks/riak
94 stars 78 forks source link

Can't install from corporate repo [JIRA: TOOLS-82] #166

Closed jaconstantine closed 9 years ago

jaconstantine commented 9 years ago

I'm trying to install 2.0.5-1 on RHEL 6.5 behind a firewall

my cookbook Berkshelf contains:
cookbook 'riak', "~> 3.1.0"

had to add to avoid berks error: cookbook 'pkg_add', github: 'wanelo-chef/pkg_add'

I'm setting:

default['riak']['install_method'] = 'custom_package'
default['riak']['package']['local']['checksum'] = 'thechecksum'
default['riak']['package']['local']['url'] = 'internal_url_to_fetch_rpm'

Is this even supported with this cookbook?

Getting a nil reference in:

       Relevant File Content:
       ----------------------
       /tmp/kitchen/cache/cookbooks/riak/recipes/package.rb:

        88:      when 9
        89:        package_file = "#{oss_or_ee}-#{version_str}-FreeBSD-amd64.tbz"
        90:        ee_url_suffix = "/freebsd/9.2/#{package_file}"
        91:      end
        92:    end
        93:  
        94:    if node['riak']['package']['enterprise_key'].empty?
        95>>     checksum_val = node['riak']['package']['local']['checksum'][node['platform']][plat_ver_int.to_s]
        96:      pkg_url = "#{node['riak']['package']['local']['url']}/#{package_file}"
        97:    elsif node['riak']['package']['enterprise_key'].length > 0 && node['riak']['package']['local']['url'].length > 0
        98:      checksum_val = node['riak']['package']['enterprise']['checksum'][node['platform']][plat_ver_int.to_s]
        99:      pkg_url = "#{node['riak']['package']['local']['url']}/#{package_file}"
       100:    else
       101:      checksum_val = node['riak']['package']['enterprise']['checksum'][node['platform']][plat_ver_int.to_s]
       102:      pkg_url = ee_url_prefix + ee_url_suffix
       103:    end
       104:  
cheeseplus commented 9 years ago

First - what is the error you are getting from Berkshelf? If it's what I suspect, then fixing it is a matter of just moving to the https endpoint (the github alias isn't firewall friendly).

As for the main question - yes this is supported. If you intend to install from a repo then you use custom_repository for node['riak']['install_method']. This will install riak assuming the repo itself is already configured (a checksum isn't required as signing is already included).

When using custom_package and local URL it assumes that a build matching the Basho naming syntax exists at the URL prefix you provide. See the .kitchen.yml for examples of the local URL format and how it is used with the custom_package install method.

jaconstantine commented 9 years ago

Here's the error from berks:

$ berks install
Resolving cookbook dependencies...
Fetching 'hw-api-riak-node' from source at .
Fetching cookbook index from https://supermarket.getchef.com...
Unable to satisfy constraints on package pkg_add, which does not exist, due to solution constraint (riak ~> 3.1.0). Solution constraints that may result in a constraint on pkg_add: [(hw-api-riak-node = 1.0.1) -> (riak = 3.1.0) -> (pkg_add >= 0.0.0)], [(riak = 3.1.0) -> (pkg_add >= 0.0.0)]
Missing artifacts: pkg_add
Demand that cannot be met: (riak ~> 3.1.0)
Unable to find a solution for demands: hw-api-riak-node (1.0.1), riak (~> 3.1.0)

The maintainers of our local, and only allowed yum repo would prefer that it remain a filtered copy of the official rhel repo. So what we've been doing is placing the .rpm in our nexus repo. The url to retrieve the .rpm uses group, artifact, version, classifier and extension arguments to grab it, not a filename. What I may have to do is grab the remote and copy it to the node using your naming convention and then point the cookbook to it by using a file:/// url. Will that work?

Thanks!

cheeseplus commented 9 years ago

Could you possibly run the berks install in verbose mode? Curious why missing gets thrown. Still probably related to the ssh vs https endpoint issues we've seen with firewalls but want to be sure.

If you aren't using a repo (in the strict yum/apt) sense and not using a URL that ends with the Basho filename format then it's going to be a bit of an issue currently. Options include adding a fully customizable URL or possibly adding a nexus artifact resource if I wanted to get carried away.

I believe the file:// url will work (the resource supports it) but I can't say I've tested it.

Context - I re-factored the cookbook recently and in doing so removed some edge case options that didn't seem like they were being leveraged. You've already proven the need for this support so it's clear I need to look at re-adding support.

jaconstantine commented 9 years ago

The following is working just fine for me now.

In attributes/default.rb:

# Find riak rpm in nexus
default['riak-rpm'].tap do |rpm|
  rpm['group_id'] = "com.basho.riak"
  rpm['artifact_id'] = "riak"
  rpm['classifier'] = "el6.x86_64"
  rpm['version'] = "#{node['riak']['package']['version']['major']}.#{node['riak']['package']['version']['minor']}.#{node['riak']['package']['version']['incremental']}-#{node['riak']['package']['version']['build']}"
  rpm['url'] = "http://nexus01:8081/nexus/service/local/artifact/maven/redirect?r=public&g="+node['riak-rpm']['group_id']+"&a="+node['riak-rpm']['artifact_id']+"&v="+node['riak-rpm']['version']+"&c="+node['riak-rpm']['classifier']+"&e=rpm"
  # filename pattern example: riak-2.0.5-1.el6.x86_64.rpm
  rpm['filename'] = "riak-" + node['riak-rpm']['version'] + "." + node['riak-rpm']['classifier'] + ".rpm"
end

# compute the urls and set the checksums - chef uses SHA256
default['riak']['install_method'] = 'custom_package'
# node['riak']['package']['local']['checksum'][node['platform']][plat_ver_int.to_s]
default['riak']['package']['local']['checksum']['centos']['6'] = '25434359e61eb284a595160fec552854b0971ffee3a569bdf9957c5cf04643b6'
default['riak']['package']['local']['url'] = "file:///tmp/riak"

In recipes/default.rb:

# Grab the riak rpm from nexus and put it in /tmp/riak.  Then use the custom-package
# install method which makes an assumption about the filename:
# e.g. riak-2.0.5-1.el6.x86_64.rpm
directory "/tmp/riak" do
  action :create
end

remote_file File.join("/tmp/riak", node['riak-rpm']['filename']) do
  source node['riak-rpm']['url']
end

# Installs riak on this node. Also installs java using the 'java' cookbook when
# needed (for Solr). The java cookbook can not install from nexus!
include_recipe 'riak'