-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from sous-chefs/clean-up-go_package
Clean up golang_package resource, allow package & source to install different versions
- Loading branch information
Showing
10 changed files
with
68 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,47 @@ | ||
default_action :install | ||
|
||
action :install do | ||
tmp_dir_path = ::File.join Chef::Config[:file_cache_path], 'golang' | ||
tmp_file_path = ::File.join tmp_dir_path, new_resource.name.gsub(%r{/}, '-') | ||
|
||
directory tmp_dir_path do | ||
user node['golang']['owner'] | ||
group node['golang']['group'] | ||
mode '0775' | ||
action :nothing | ||
end.run_action(:create) | ||
gocache = '/tmp/go' | ||
|
||
bash "Installing package #{new_resource.name}" do | ||
code "#{node['golang']['install_dir']}/go/bin/go get -v #{new_resource.name} 2> >(grep -v '(download)$' | tee #{tmp_file_path})" | ||
action :nothing | ||
user node['golang']['owner'] | ||
group node['golang']['group'] | ||
environment( | ||
'GOPATH' => node['golang']['gopath'], | ||
'GOBIN' => node['golang']['gobin'] | ||
) | ||
end.run_action(:run) | ||
|
||
f = file tmp_file_path do | ||
action :install do | ||
execute "go get #{new_resource.name}" do | ||
user node['golang']['owner'] | ||
group node['golang']['group'] | ||
content '' | ||
environment({ | ||
PATH: "#{node['golang']['install_dir']}/go/bin:#{node['golang']['gobin']}:" \ | ||
'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', | ||
GOPATH: node['golang']['gopath'], | ||
GOBIN: node['golang']['gobin'], | ||
GOCACHE: gocache, | ||
}) | ||
end | ||
f.run_action(:create) | ||
end | ||
|
||
action :update do | ||
tmp_file_path = ::File.join Chef::Config[:file_cache_path], new_resource.name.gsub(%r{/}, '-') | ||
|
||
bash "Updating package #{new_resource.name}" do | ||
code "#{node['golang']['install_dir']}/go/bin/go get -v -u #{new_resource.name} 2> >(grep -v '(download)$' | tee #{tmp_file_path})" | ||
action :nothing | ||
execute "go get -u #{new_resource.name}" do | ||
user node['golang']['owner'] | ||
group node['golang']['group'] | ||
environment( | ||
'GOPATH' => node['golang']['gopath'], | ||
'GOBIN' => node['golang']['gobin'] | ||
) | ||
end.run_action(:run) | ||
|
||
f = file tmp_file_path do | ||
content '' | ||
environment({ | ||
PATH: "#{node['golang']['install_dir']}/go/bin:#{node['golang']['gobin']}:" \ | ||
'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', | ||
GOPATH: node['golang']['gopath'], | ||
GOBIN: node['golang']['gobin'], | ||
GOCACHE: gocache, | ||
}) | ||
end | ||
f.run_action(:create) | ||
end | ||
|
||
action :build do | ||
tmpdir = directory(::File.join(Chef::Config[:file_cache_path], new_resource.name.gsub(%r{/}, '-') + '_BUILD')) do | ||
action :nothing | ||
owner node['golang']['owner'] | ||
group node['golang']['group'] | ||
recursive true | ||
end | ||
|
||
# create temporary directory to executing the build in | ||
tmpdir.run_action(:create) | ||
|
||
b = bash "Build package #{new_resource.name}" do | ||
code "#{node['golang']['install_dir']}/go/bin/go build #{new_resource.name}" | ||
action :nothing | ||
cwd tmpdir.name | ||
execute "go build -work -x #{new_resource.name}" do | ||
user node['golang']['owner'] | ||
group node['golang']['group'] | ||
environment( | ||
'GOPATH' => node['golang']['gopath'], | ||
'GOBIN' => node['golang']['gobin'] | ||
) | ||
cwd gocache | ||
environment({ | ||
PATH: "#{node['golang']['install_dir']}/go/bin:#{node['golang']['gobin']}:" \ | ||
'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', | ||
HOME: "/home/#{node['golang']['owner']}", | ||
GOPATH: node['golang']['gopath'], | ||
GOBIN: node['golang']['gobin'], | ||
GOCACHE: gocache, | ||
}) | ||
end | ||
|
||
# execute the build | ||
b.run_action(:run) | ||
|
||
# remove temporary directory | ||
# tmpdir.run_action(:delete) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export PATH=$PATH:<%= node['golang']['install_dir'] %>/go/bin:<%= node['golang']['gobin'] %> | ||
export PATH="<%= node['golang']['install_dir'] %>/go/bin:<%= node['golang']['gobin'] %>:$PATH" | ||
export GOPATH=<%= node['golang']['gopath'] %> | ||
export GOBIN=<%= node['golang']['gobin'] %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
describe command '/usr/local/go/bin/go version' do | ||
its('stdout') { should include '1.13.12' } | ||
end | ||
|
||
describe command 'export GOPATH=/opt/go; cd /tmp/hello_world && /usr/local/go/bin/go test' do | ||
its('exit_status') { should cmp 0 } | ||
end | ||
|
||
describe directory '/opt/go' do | ||
its('owner') { should eq 'root' } | ||
its('group') { should eq 'root' } | ||
end | ||
|
||
describe command '/opt/go/bin/hello' do | ||
its('stdout') { should include 'Hello, Go examples!' } | ||
end |