From cfd79d54a1d337117a98316b1cdfff59e887411c Mon Sep 17 00:00:00 2001 From: Michael Burns Date: Sat, 24 Feb 2018 22:13:38 -0800 Subject: [PATCH] rename cookbook, use 'golang' namespace for attributes (#56) * use 'golang' namespace for attributes * rename cookbook * version 2.0.0! --- .kitchen.yml | 9 ++-- .rubocop_todo.yml | 6 +-- CHANGELOG.md | 5 +++ CONTRIBUTING.md | 7 +++ README.md | 57 ++++++++++------------- attributes/default.rb | 38 ++++++++-------- metadata.rb | 2 +- providers/package.rb | 42 ++++++++--------- recipes/default.rb | 62 +++++++++++++------------- recipes/packages.rb | 2 +- templates/default/golang.sh.erb | 6 +-- test/cookbooks/golang_test/README.md | 58 +++--------------------- test/cookbooks/golang_test/metadata.rb | 8 ++-- 13 files changed, 129 insertions(+), 173 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/.kitchen.yml b/.kitchen.yml index 22b1ca3..427e96c 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -7,8 +7,9 @@ provisioner: require_chef_omnibus: true platforms: -- name: ubuntu-14.10 -- name: centos-6.5 +- name: ubuntu-16.04 +- name: debian-8 +- name: centos-6.9 suites: - name: default @@ -16,7 +17,7 @@ suites: - recipe[golang_test::default] - recipe[minitest-handler] attributes: - go: + golang: owner: 'vagrant' group: 'vagrant' - name: src @@ -24,7 +25,7 @@ suites: - recipe[golang_test::default] - recipe[minitest-handler] attributes: - go: + golang: from_source: true arch: 'amd64' owner: 'vagrant' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 73c7a0b..187c684 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2018-02-23 20:09:39 -0800 using RuboCop version 0.52.1. +# on 2018-02-24 21:54:23 -0800 using RuboCop version 0.52.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -27,8 +27,8 @@ Style/RegexpLiteral: Exclude: - 'providers/package.rb' -# Offense count: 12 +# Offense count: 14 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: - Max: 131 + Max: 135 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b699fc..7a3a187 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ This file is used to list changes made in each version of golang. +## 2.0.0 + +* rename to `chef-golang` so that metadata name matches repositoriy name +* change attribute namespace to `node['golang']` + ## 1.7.2 * Better chef12,13 support diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..3745ced --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,7 @@ +## Contributing + +1. Fork the repository +2. Create a named feature branch (like `add_component_x`) +3. Write you change +4. Test it by running `rake kitchen:all` +5. Submit a Pull Request diff --git a/README.md b/README.md index 44f269e..b75d50b 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,26 @@ [![Build Status](https://travis-ci.org/NOX73/chef-golang.svg?branch=master)](https://travis-ci.org/NOX73/chef-golang) [![Cookbook Version](https://img.shields.io/cookbook/v/golang.svg?style=flat)](https://supermarket.chef.io/cookbooks/golang) -# golang (Chef cookbook for Go) +# chef-golang (Chef cookbook Go) ## Description -Chef cookbook for [Go programming language](http://golang.org/). +Chef cookbook for the [Go programming language](http://golang.org/). ## Requirements ### Platform -* Ubuntu (12.04/13.04/14.10) -* Debian (6.0) -* CentOS (6.5) +* Ubuntu (16.04) +* Debian (8) +* CentOS (6.9) -**Notes**: This cookbook has been tested on the listed platforms. It -may work on other platforms with or without modification. Please -[report issues](https://github.com/NOX73/chef-golang/issues) any additional platforms so they can be added. +**Notes**: This cookbook has been tested on the listed platforms. It may work on other platforms with or without modification. Please [report issues](https://github.com/NOX73/chef-golang/issues) any additional platforms so they can be added. ## Usage -#### golang::default +#### chef-golang::default Just include `golang` in your node's `run_list`: @@ -30,14 +28,14 @@ Just include `golang` in your node's `run_list`: { "name":"my_node", "run_list": [ - "recipe[golang]" + "recipe[chef-golang]" ] } ``` -#### golang::packages +#### chef-golang::packages -To install Go packages using node attributes, include `golang::packages` in your node's `run_list`, and use the `['go']['packages']` attribute: +To install Go packages using node attributes, include `golang::packages` in your node's `run_list`, and use the `['golang']['packages']` attribute: ```json { @@ -56,23 +54,22 @@ To install Go packages using node attributes, include `golang::packages` in your ## Attributes -#### golang::default - +#### chef-golang::default Key | Type | Description | Default --- | ---- | ----------- | ------- -`['go']['version']` | String | Go version | `1.5` -`['go']['platform']` | String | `amd64` or `i386` | `amd64` -`['go']['scm']` | Boolean | install SCM dependencies `git`, `hg`, and `bzr` | `true` -`['go']['packages']` | Array | Go packages to install when using the `golang::packages` recipe | `[]` -`['go']['owner']` | String | The user account that owns $GOPATH | `root` -`['go']['group']` | String | The group that owns $GOPATH | `root` -`['go']['mode']` | String | The mode of $GOPATH | `0755` -`['go']['from_source']` | Boolean | Install go from source | `false` -`['go']['os']` | String | Build go for which operating system | `linux` -`['go']['arch']` | String | Build go for which architecture | `arm` -`['go']['arm']` | String | Build go for which arm version | `6` -`['go']['source_method']` | String | Choose which install script should be used | `all.bash` +`['golang']['version']` | String | Go version | `1.5` +`['golang']['platform']` | String | `amd64` or `i386` | `amd64` +`['golang']['scm']` | Boolean | install SCM dependencies `git`, `hg`, and `bzr` | `true` +`['golang']['packages']` | Array | Go packages to install when using the `golang::packages` recipe | `[]` +`['golang']['owner']` | String | The user account that owns $GOPATH | `root` +`['golang']['group']` | String | The group that owns $GOPATH | `root` +`['golang']['mode']` | String | The mode of $GOPATH | `0755` +`['golang']['from_source']` | Boolean | Install go from source | `false` +`['golang']['os']` | String | Build go for which operating system | `linux` +`['golang']['arch']` | String | Build go for which architecture | `arm` +`['golang']['arm']` | String | Build go for which arm version | `6` +`['golang']['source_method']` | String | Choose which install script should be used | `all.bash` ## Testing @@ -87,11 +84,3 @@ satisfied: * [Vagrant](http://vagrantup.com/) (>= 1.1.0) * [VirtualBox](https://www.virtualbox.org/) * [Vagrant Berkshelf Plugin](http://rubygems.org/gems/vagrant-berkshelf) - -## Contributing - -1. Fork the repository -2. Create a named feature branch (like `add_component_x`) -3. Write you change -4. Test it by running `rake kitchen:all` -5. Submit a Pull Request diff --git a/attributes/default.rb b/attributes/default.rb index 37fdc6e..a591cf1 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,20 +1,20 @@ -default['go']['version'] = '1.5' -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' +default['golang']['version'] = '1.5' +default['golang']['platform'] = node['kernel']['machine'] =~ /i.86/ ? '386' : 'amd64' +default['golang']['filename'] = "go#{node['golang']['version']}.#{node['os']}-#{node['golang']['platform']}.tar.gz" +default['golang']['from_source'] = false +if node['golang']['from_source'] + default['golang']['filename'] = "go#{node['golang']['version']}.src.tar.gz" + default['golang']['os'] = 'linux' + default['golang']['arch'] = 'arm' + default['golang']['arm'] = '6' + default['golang']['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' -default['go']['scm'] = true -default['go']['packages'] = [] -default['go']['owner'] = 'root' -default['go']['group'] = 'root' -default['go']['mode'] = 0o755 +default['golang']['url'] = "http://golang.org/dl/#{node['golang']['filename']}" +default['golang']['install_dir'] = '/usr/local' +default['golang']['gopath'] = '/opt/go' +default['golang']['gobin'] = '/opt/go/bin' +default['golang']['scm'] = true +default['golang']['packages'] = [] +default['golang']['owner'] = 'root' +default['golang']['group'] = 'root' +default['golang']['mode'] = 0o755 diff --git a/metadata.rb b/metadata.rb index 0332f6c..f3b586e 100644 --- a/metadata.rb +++ b/metadata.rb @@ -6,7 +6,7 @@ license 'Apache-2.0' description 'Installs go programming language' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '1.7.2' +version '2.0.0' chef_version '>= 12' if respond_to?(:chef_version) recipe 'golang', 'Installs go programing language.' diff --git a/providers/package.rb b/providers/package.rb index fa1020a..9c29eec 100644 --- a/providers/package.rb +++ b/providers/package.rb @@ -5,26 +5,26 @@ tmp_file_path = ::File.join tmp_dir_path, new_resource.name.gsub(/\//, '-') directory tmp_dir_path do - user node['go']['owner'] - group node['go']['group'] + user node['golang']['owner'] + group node['golang']['group'] mode '0775' action :nothing end.run_action(:create) bash "Installing package #{new_resource.name}" do - code "#{node['go']['install_dir']}/go/bin/go get -v #{new_resource.name} 2> >(grep -v '(download)$' | tee #{tmp_file_path})" + 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['go']['owner'] - group node['go']['group'] + user node['golang']['owner'] + group node['golang']['group'] environment( - 'GOPATH' => node['go']['gopath'], - 'GOBIN' => node['go']['gobin'] + 'GOPATH' => node['golang']['gopath'], + 'GOBIN' => node['golang']['gobin'] ) end.run_action(:run) f = file tmp_file_path do - user node['go']['owner'] - group node['go']['group'] + user node['golang']['owner'] + group node['golang']['group'] content '' end f.run_action(:create) @@ -34,13 +34,13 @@ tmp_file_path = ::File.join Chef::Config[:file_cache_path], new_resource.name.gsub(/\//, '-') bash "Updating package #{new_resource.name}" do - code "#{node['go']['install_dir']}/go/bin/go get -v -u #{new_resource.name} 2> >(grep -v '(download)$' | tee #{tmp_file_path})" + code "#{node['golang']['install_dir']}/go/bin/go get -v -u #{new_resource.name} 2> >(grep -v '(download)$' | tee #{tmp_file_path})" action :nothing - user node['go']['owner'] - group node['go']['group'] + user node['golang']['owner'] + group node['golang']['group'] environment( - 'GOPATH' => node['go']['gopath'], - 'GOBIN' => node['go']['gobin'] + 'GOPATH' => node['golang']['gopath'], + 'GOBIN' => node['golang']['gobin'] ) end.run_action(:run) @@ -53,8 +53,8 @@ action :build do tmpdir = directory (::File.join Chef::Config[:file_cache_path], new_resource.name.gsub(/\//, '-') + '_BUILD') do action :nothing - owner node['go']['owner'] - group node['go']['group'] + owner node['golang']['owner'] + group node['golang']['group'] recursive true end @@ -62,14 +62,14 @@ tmpdir.run_action(:create) b = bash "Build package #{new_resource.name}" do - code "#{node['go']['install_dir']}/go/bin/go build #{new_resource.name}" + code "#{node['golang']['install_dir']}/go/bin/go build #{new_resource.name}" action :nothing cwd tmpdir.name - user node['go']['owner'] - group node['go']['group'] + user node['golang']['owner'] + group node['golang']['group'] environment( - 'GOPATH' => node['go']['gopath'], - 'GOBIN' => node['go']['gobin'] + 'GOPATH' => node['golang']['gopath'], + 'GOBIN' => node['golang']['gobin'] ) end diff --git a/recipes/default.rb b/recipes/default.rb index ea1de9b..0df652f 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -17,18 +17,18 @@ # under the License. # -node.default['go']['platform'] = node['kernel']['machine'] =~ /i.86/ ? '386' : 'amd64' -node.default['go']['filename'] = "go#{node['go']['version']}.#{node['os']}-#{node['go']['platform']}.tar.gz" -node.default['go']['url'] = "http://golang.org/dl/#{node['go']['filename']}" +node.default['golang']['platform'] = node['kernel']['machine'] =~ /i.86/ ? '386' : 'amd64' +node.default['golang']['filename'] = "go#{node['golang']['version']}.#{node['os']}-#{node['golang']['platform']}.tar.gz" +node.default['golang']['url'] = "http://golang.org/dl/#{node['golang']['filename']}" bash 'install-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']} + rm -rf #{node['golang']['install_dir']}/go + tar -C #{node['golang']['install_dir']} -xzf #{node['golang']['filename']} EOH - not_if { node['go']['from_source'] } + not_if { node['golang']['from_source'] } action :nothing end @@ -36,24 +36,24 @@ 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 + rm -rf #{node['golang']['install_dir']}/go + tar -C #{node['golang']['install_dir']} -xzf #{node['golang']['filename']} + cd #{node['golang']['install_dir']}/go/src mkdir -p $GOBIN - ./#{node['go']['source_method']} + ./#{node['golang']['source_method']} EOH environment ({ - 'GOROOT' => "#{node['go']['install_dir']}/go", + 'GOROOT' => "#{node['golang']['install_dir']}/go", 'GOBIN' => '$GOROOT/bin', - 'GOOS' => node['go']['os'], - 'GOARCH' => node['go']['arch'], - 'GOARM' => node['go']['arm'] + 'GOOS' => node['golang']['os'], + 'GOARCH' => node['golang']['arch'], + 'GOARM' => node['golang']['arm'] }) - only_if { node['go']['from_source'] } + only_if { node['golang']['from_source'] } action :nothing end -if node['go']['from_source'] +if node['golang']['from_source'] case node['platform'] when 'debian', 'ubuntu' packages = %w[build-essential] @@ -67,39 +67,39 @@ end end -remote_file File.join(Chef::Config[:file_cache_path], node['go']['filename']) do - source node['go']['url'] +remote_file File.join(Chef::Config[:file_cache_path], node['golang']['filename']) do + source node['golang']['url'] owner 'root' mode 0o644 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']} \"" + not_if "#{node['golang']['install_dir']}/go/bin/go version | grep \"go#{node['golang']['version']} \"" end -directory node['go']['gopath'] do +directory node['golang']['gopath'] do action :create recursive true - owner node['go']['owner'] - group node['go']['group'] - mode node['go']['mode'] + owner node['golang']['owner'] + group node['golang']['group'] + mode node['golang']['mode'] end -directory node['go']['gobin'] do +directory node['golang']['gobin'] do action :create recursive true - owner node['go']['owner'] - group node['go']['group'] - mode node['go']['mode'] + owner node['golang']['owner'] + group node['golang']['group'] + mode node['golang']['mode'] end template '/etc/profile.d/golang.sh' do source 'golang.sh.erb' - owner node['go']['owner'] - group node['go']['group'] - mode node['go']['mode'] + owner node['golang']['owner'] + group node['golang']['group'] + mode node['golang']['mode'] end -if node['go']['scm'] +if node['golang']['scm'] %w[git mercurial bzr].each do |scm| package scm end diff --git a/recipes/packages.rb b/recipes/packages.rb index f11422b..a62b924 100644 --- a/recipes/packages.rb +++ b/recipes/packages.rb @@ -19,6 +19,6 @@ include_recipe 'golang' -node['go']['packages'].each do |package| +node['golang']['packages'].each do |package| golang_package package end diff --git a/templates/default/golang.sh.erb b/templates/default/golang.sh.erb index 124c314..4088249 100644 --- a/templates/default/golang.sh.erb +++ b/templates/default/golang.sh.erb @@ -1,3 +1,3 @@ -export PATH=$PATH:<%= node['go']['install_dir'] %>/go/bin:<%= node['go']['gobin'] %> -export GOPATH=<%= node['go']['gopath'] %> -export GOBIN=<%= node['go']['gobin'] %> +export PATH=$PATH:<%= node['golang']['install_dir'] %>/go/bin:<%= node['golang']['gobin'] %> +export GOPATH=<%= node['golang']['gopath'] %> +export GOBIN=<%= node['golang']['gobin'] %> diff --git a/test/cookbooks/golang_test/README.md b/test/cookbooks/golang_test/README.md index 7d92db5..56f823c 100644 --- a/test/cookbooks/golang_test/README.md +++ b/test/cookbooks/golang_test/README.md @@ -1,45 +1,15 @@ -golang_test Cookbook -========================= -TODO: Enter the cookbook description here. +# golang_test Cookbook -e.g. -This cookbook makes your favorite breakfast sandwhich. +Testing cookbook for `chef-golang`. -Requirements ------------- -TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc. +## Requirements -e.g. -#### packages -- `toaster` - golang_test needs toaster to brown your bagel. +Depends on `chef-golang`. -Attributes ----------- -TODO: List you cookbook attributes here. +## Usage -e.g. -#### golang_test::default - - - - - - - - - - - - - -
KeyTypeDescriptionDefault
['golang_test']['bacon']Booleanwhether to include bacontrue
+### golang_test::default -Usage ------ -#### golang_test::default -TODO: Write usage instructions for each cookbook. - -e.g. Just include `golang_test` in your node's `run_list`: ```json @@ -50,19 +20,3 @@ Just include `golang_test` in your node's `run_list`: ] } ``` - -Contributing ------------- -TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section. - -e.g. -1. Fork the repository on Github -2. Create a named feature branch (like `add_component_x`) -3. Write you change -4. Write tests for your change (if applicable) -5. Run the tests, ensuring they all pass -6. Submit a Pull Request using Github - -License and Authors -------------------- -Authors: TODO: List authors diff --git a/test/cookbooks/golang_test/metadata.rb b/test/cookbooks/golang_test/metadata.rb index 7cedd59..c47e4bd 100644 --- a/test/cookbooks/golang_test/metadata.rb +++ b/test/cookbooks/golang_test/metadata.rb @@ -1,11 +1,11 @@ name 'golang_test' -maintainer 'YOUR_COMPANY_NAME' -maintainer_email 'YOUR_EMAIL' -license 'All rights reserved' +maintainer 'Alexander Rozhnov' +maintainer_email 'gnox73@gmail.com' +license 'Apache-2.0' description 'Installs/Configures golang_test' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) version '0.1.0' recipe 'golang_test', 'default' -depends 'golang' +depends 'chef-golang'