Skip to content

Commit

Permalink
Merge branch 'rollbrettler-add-src-build-install'
Browse files Browse the repository at this point in the history
* rollbrettler-add-src-build-install:
  Add posibility to install go from source

Conflicts:
	attributes/default.rb
  • Loading branch information
NOX73 committed Oct 19, 2015
2 parents d92c64c + 67193dc commit ba6c884
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ suites:
go:
owner: 'vagrant'
group: 'vagrant'
- name: src
run_list:
- recipe[golang_test::default]
- recipe[minitest-handler]
attributes:
go:
from_source: true
arch: 'amd64'
owner: 'vagrant'
group: 'vagrant'
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,36 @@ To install Go packages using node attributes, include `golang::packages` in your
<td>The mode of $GOPATH</td>
<td><tt>0755</tt></td>
</tr>
<tr>
<td><tt>['go']['from_source']</tt></td>
<td>Boolean</td>
<td>Install go from source</td>
<td><tt>false</tt></td>
</tr>
<tr>
<td><tt>['go']['os']</tt></td>
<td>String</td>
<td>Build go for which operating system</td>
<td><tt>linux</tt></td>
</tr>
<tr>
<td><tt>['go']['arch']</tt></td>
<td>String</td>
<td>Build go for which architecture</td>
<td><tt>arm</tt></td>
</tr>
<tr>
<td><tt>['go']['arm']</tt></td>
<td>String</td>
<td>Build go for which arm version</td>
<td><tt>6</tt></td>
</tr>
<tr>
<td><tt>['go']['source_method']</tt></td>
<td>String</td>
<td>Choose which install script should be used</td>
<td><tt>all.bash</tt></td>
</tr>
</table>

## <a name="testing"></a> Testing
Expand Down
11 changes: 11 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
default['go']['version'] = '1.4'
default['go']['platform'] = node['kernel']['machine'] =~ /i.86/ ? '386' : 'amd64'
default['go']['filename'] = "go#{node['go']['version']}.#{node['os']}-#{node['go']['platform']}.tar.gz"
default['go']['from_source'] = false
if node['go']['from_source']
default['go']['filename'] = "go#{node['go']['version']}.src.tar.gz"
default['go']['os'] = 'linux'
default['go']['arch'] = 'arm'
default['go']['arm'] = '6'
default['go']['source_method'] = "all.bash"
end
default['go']['url'] = "http://golang.org/dl/#{node['go']['filename']}"
default['go']['install_dir'] = '/usr/local'
default['go']['gopath'] = '/opt/go'
default['go']['gobin'] = '/opt/go/bin'
Expand Down
39 changes: 38 additions & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,53 @@
code <<-EOH
rm -rf go
rm -rf #{node['go']['install_dir']}/go
tar -C #{node['go']['install_dir']} -xzf #{node["go"]["filename"]}
tar -C #{node['go']['install_dir']} -xzf #{node['go']['filename']}
EOH
not_if { node['go']['from_source'] }
action :nothing
end

bash "build-golang" do
cwd Chef::Config[:file_cache_path]
code <<-EOH
rm -rf go
rm -rf #{node['go']['install_dir']}/go
tar -C #{node['go']['install_dir']} -xzf #{node['go']['filename']}
cd #{node['go']['install_dir']}/go/src
mkdir -p $GOBIN
./#{node['go']['source_method']}
EOH
environment ({
'GOROOT' => "#{node['go']['install_dir']}/go",
'GOBIN' => '$GOROOT/bin',
'GOOS' => node['go']['os'],
'GOARCH' => node['go']['arch'],
'GOARM' => node['go']['arm']
})
only_if { node['go']['from_source'] }
action :nothing
end

if node['go']['from_source']
case node["platform"]
when 'debian', 'ubuntu'
packages = %w(build-essential)
when 'redhat', 'centos', 'fedora'
packages = %w(gcc glibc-devel)
end
packages.each do |dev_package|
package dev_package do
action :install
end
end
end

remote_file File.join(Chef::Config[:file_cache_path], node['go']['filename']) do
source node['go']['url']
owner 'root'
mode 0644
notifies :run, 'bash[install-golang]', :immediately
notifies :run, 'bash[build-golang]', :immediately
not_if "#{node['go']['install_dir']}/go/bin/go version | grep \"go#{node['go']['version']} \""
end

Expand Down

0 comments on commit ba6c884

Please sign in to comment.