OSDN Git Service

add the go_utils cookbook. go_utils-0.1.0
authorwhitestar <whitestar@users.osdn.me>
Sun, 3 Mar 2019 12:46:13 +0000 (21:46 +0900)
committerwhitestar <whitestar@users.osdn.me>
Sun, 3 Mar 2019 12:46:13 +0000 (21:46 +0900)
21 files changed:
cookbooks/go_utils/.foodcritic [new file with mode: 0644]
cookbooks/go_utils/.rubocop.yml [new file with mode: 0644]
cookbooks/go_utils/Berksfile [new file with mode: 0644]
cookbooks/go_utils/CHANGELOG.md [new file with mode: 0644]
cookbooks/go_utils/Gemfile [new file with mode: 0644]
cookbooks/go_utils/Gemfile.lock [new file with mode: 0644]
cookbooks/go_utils/README.md [new file with mode: 0644]
cookbooks/go_utils/Rakefile [new file with mode: 0644]
cookbooks/go_utils/attributes/default.rb [new file with mode: 0644]
cookbooks/go_utils/chefignore [new file with mode: 0644]
cookbooks/go_utils/concourse.yml [new file with mode: 0644]
cookbooks/go_utils/fly-vars.local.yml [new file with mode: 0644]
cookbooks/go_utils/fly-vars.yml [new file with mode: 0644]
cookbooks/go_utils/metadata.rb [new file with mode: 0644]
cookbooks/go_utils/recipes/default.rb [new file with mode: 0644]
cookbooks/go_utils/recipes/go-installer.rb [new file with mode: 0644]
cookbooks/go_utils/spec/recipes/default_spec.rb [new file with mode: 0644]
cookbooks/go_utils/spec/spec_helper.rb [new file with mode: 0644]
cookbooks/go_utils/templates/default/usr/local/bin/go_install [new file with mode: 0644]
cookbooks/go_utils/version [new file with mode: 0644]
roles/go-utils.rb [new file with mode: 0644]

diff --git a/cookbooks/go_utils/.foodcritic b/cookbooks/go_utils/.foodcritic
new file mode 100644 (file)
index 0000000..3907cff
--- /dev/null
@@ -0,0 +1 @@
+~FC001
diff --git a/cookbooks/go_utils/.rubocop.yml b/cookbooks/go_utils/.rubocop.yml
new file mode 100644 (file)
index 0000000..4de4294
--- /dev/null
@@ -0,0 +1,53 @@
+AllCops:
+  Exclude:
+    - vendor/**/*
+
+AlignParameters:
+  Enabled: false
+LineLength:
+  Enabled: false
+Lint/UnusedBlockArgument:
+  Enabled: false
+Metrics/AbcSize:
+  Enabled: false
+Style/BlockComments:
+  Enabled: false
+Style/BlockDelimiters:
+  Enabled: false
+Style/ExtraSpacing:
+  Enabled: false
+Style/FileName:
+  Enabled: false
+Style/LeadingCommentSpace:
+  Enabled: false
+Style/RescueModifier:
+  Enabled: false
+Style/SpaceAroundOperators:
+  Enabled: false
+Style/SpaceBeforeFirstArg:
+  Enabled: false
+Style/SpaceInsideBlockBraces:
+  Enabled: false
+Style/SpaceInsidePercentLiteralDelimiters:
+  Enabled: false
+Style/TrailingCommaInLiteral:
+  EnforcedStyleForMultiline: consistent_comma
+Style/WordArray:
+  Enabled: false
+
+#Lint/ShadowingOuterLocalVariable:
+#  Enabled: false
+#Metrics/MethodLength:
+#  Max: 10
+#Metrics/ModuleLength:
+#  Max: 100
+#Metrics/CyclomaticComplexity:
+#  Max: 6
+#Metrics/PerceivedComplexity:
+#  Max: 7
+#Style/AccessorMethodName:
+#  Enabled: false
+#Style/MultilineOperationIndentation:
+#  Enabled: false
+#Style/PerlBackrefs:
+#  Enabled: false
diff --git a/cookbooks/go_utils/Berksfile b/cookbooks/go_utils/Berksfile
new file mode 100644 (file)
index 0000000..4ed8bef
--- /dev/null
@@ -0,0 +1,19 @@
+#
+# Copyright 2019 whitestar
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+source 'https://supermarket.chef.io'
+
+metadata
diff --git a/cookbooks/go_utils/CHANGELOG.md b/cookbooks/go_utils/CHANGELOG.md
new file mode 100644 (file)
index 0000000..2e49c46
--- /dev/null
@@ -0,0 +1,5 @@
+# go_utils CHANGELOG
+
+0.1.0
+-----
+- Initial release of go_utils
diff --git a/cookbooks/go_utils/Gemfile b/cookbooks/go_utils/Gemfile
new file mode 100644 (file)
index 0000000..ad84be7
--- /dev/null
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# with Chef DK
+gem 'stove'
diff --git a/cookbooks/go_utils/Gemfile.lock b/cookbooks/go_utils/Gemfile.lock
new file mode 100644 (file)
index 0000000..6fb9a3b
--- /dev/null
@@ -0,0 +1,22 @@
+GEM
+  remote: https://rubygems.org/
+  specs:
+    chef-api (0.8.0)
+      logify (~> 0.1)
+      mime-types
+    logify (0.2.0)
+    mime-types (3.2.2)
+      mime-types-data (~> 3.2015)
+    mime-types-data (3.2018.0812)
+    stove (6.0.0)
+      chef-api (~> 0.5)
+      logify (~> 0.2)
+
+PLATFORMS
+  ruby
+
+DEPENDENCIES
+  stove
+
+BUNDLED WITH
+   1.16.0
diff --git a/cookbooks/go_utils/README.md b/cookbooks/go_utils/README.md
new file mode 100644 (file)
index 0000000..b71e6a9
--- /dev/null
@@ -0,0 +1,56 @@
+go_utils Cookbook
+=================
+
+This cookbook installs `go` setup scripts.
+
+## Contents
+
+
+## Requirements
+
+### platforms
+- Debian >= 8.0
+- Ubuntu >= 14.04
+- CentOS, RHEL >= 7.3
+
+### packages
+- none.
+
+### cookbooks
+- none.
+
+## Attributes
+
+|Key|Type|Description, example|Default|
+|:--|:--|:--|:--|
+|`['go_utils']['go']['version']`|String||`'1.11.5'`|
+
+## Usage
+
+### Recipes
+
+#### go_utils::default
+
+This recipe does nothing.
+
+#### go_utils::go-installer
+
+This recipe installs the `go` setup script.
+
+- Author:: whitestar at osdn.jp
+
+```text
+Copyright 2019, whitestar
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+```
diff --git a/cookbooks/go_utils/Rakefile b/cookbooks/go_utils/Rakefile
new file mode 100644 (file)
index 0000000..1ba86c6
--- /dev/null
@@ -0,0 +1,95 @@
+require 'rspec/core/rake_task'
+require 'rubocop/rake_task'
+require 'foodcritic'
+require 'stove/rake_task'
+
+tpl_cookbook = '00cookbook'
+cookbook_name = File.basename(Dir.pwd)
+
+desc 'Initialize project'
+task :init do
+  next if cookbook_name == tpl_cookbook
+
+  [
+    '.foodcritic',
+    '.rubocop.yml',
+    'Berksfile',
+    'chefignore',
+    'concourse.yml',
+    'fly-vars.yml',
+    'fly-vars.local.yml',
+    'Gemfile',
+    'Gemfile.lock',
+    'version',
+  ].each {|conf|
+    sh "cp ../#{tpl_cookbook}/#{conf} ./" unless File.exist?(conf)
+  }
+
+  ruby [
+    %(-pne '$_.gsub!(/^cookbook-name: .*$/, "cookbook-name: #{cookbook_name}")'),
+    '-i fly-vars.local.yml',
+  ].join(' ')
+end
+
+desc 'Update project'
+task :update do
+  next if cookbook_name == tpl_cookbook
+
+  [
+    'Rakefile',
+    'chefignore',
+    'concourse.yml',
+    'fly-vars.yml',
+    'Gemfile',
+    'Gemfile.lock',
+  ].each {|conf|
+    sh "cp ../#{tpl_cookbook}/#{conf} ./"
+  }
+end
+
+desc 'fly set-pipeline'
+task :'set-pipeline' do
+  sh [
+    "fly -t $CC_TARGET sp -p #{cookbook_name}-cookbook -c concourse.yml",
+    '-l fly-vars.yml -l fly-vars.local.yml -l ~/sec/credentials-prod.yml',
+  ].join(' ')
+end
+desc 'rake set-pipeline alias'
+task sp: 'set-pipeline'
+
+namespace :style do
+  desc 'Run Ruby style checks'
+  RuboCop::RakeTask.new(:ruby) do |t|
+    t.options = [
+      '--auto-gen-config',  # creates .rubocop_todo.yml
+    ]
+  end
+
+  desc 'Run Chef style checks'
+  FoodCritic::Rake::LintTask.new(:chef) do |t|
+    t.options = {
+      fail_tags: ['any'],
+    }
+  end
+end
+
+desc 'Run all style checks'
+task style: ['style:chef', 'style:ruby']
+
+desc 'Run ChefSpec examples'
+RSpec::Core::RakeTask.new(:spec)
+
+desc 'Publish cookbook'
+Stove::RakeTask.new(:publish) do |t|
+  t.stove_opts = [
+    # `--username` and `--key` are set in ~/.stove typically.
+    #'--username', 'somebody',
+    #'--key', '~/chef/chef.io.example.com/somebody.pem',
+    #'--endpoint', 'https://supermarket.io.example.com/api/v1',  # default: supermarket.chef.io
+    #'--no-ssl-verify',
+    '--no-git',
+    '--log-level', 'info',
+  ]
+end
+
+task default: ['style', 'spec']
diff --git a/cookbooks/go_utils/attributes/default.rb b/cookbooks/go_utils/attributes/default.rb
new file mode 100644 (file)
index 0000000..5aca2c7
--- /dev/null
@@ -0,0 +1,20 @@
+#
+# Cookbook Name:: go_utils
+# Attributes:: default
+#
+# Copyright 2019, whitestar
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+default['go_utils']['go']['version'] = '1.11.5'
diff --git a/cookbooks/go_utils/chefignore b/cookbooks/go_utils/chefignore
new file mode 100644 (file)
index 0000000..10e314a
--- /dev/null
@@ -0,0 +1,20 @@
+# Put files/directories that should be ignored in this file.
+# Lines that start with '# ' are comments.
+
+Berksfile.lock
+
+# concourse
+concourse.yml
+fly-vars.yml
+fly-vars.local.yml
+
+# emacs
+*~
+
+.rubocop_todo.yml
+
+# vim
+*.sw[a-z]
+
+# subversion
+*/.svn/*
diff --git a/cookbooks/go_utils/concourse.yml b/cookbooks/go_utils/concourse.yml
new file mode 100644 (file)
index 0000000..d373185
--- /dev/null
@@ -0,0 +1,101 @@
+---
+resources:
+- name: src-git
+  type: git
+  source:
+    uri: ((git-id-osdn))@git.osdn.net:/gitroot/metasearch/grid-chef-repo.git
+    branch: master
+    paths:
+    - cookbooks/((cookbook-name))
+    private_key: ((git-private-key))
+    git_user: ((git-user-osdn))
+  #check_every: 1h  # default: 1m
+- name: chefdk-cache
+  type: docker-image
+  source:
+    repository: chef/chefdk
+    tag: ((chefdk-version))
+    # ((param)) style: fly >= 3.2.0
+    registry_mirror: https://((registry-mirror-domain))  # e.g. https://registry.docker.example.com:5000
+    ca_certs:
+    - domain: ((registry-mirror-domain))  # e.g. registry.docker.example.com:5000
+      cert: ((docker-reg-ca-cert))
+  check_every: 6h  # default: 1m
+
+jobs:
+- name: test-cookbook
+  plan:
+  - aggregate:
+    - get: src-git
+      params:
+        depth: 5
+      trigger: true
+    - get: chefdk-cache
+  - task: ci-build
+    image: chefdk-cache
+    params:
+      http_proxy: ((http-proxy))  # e.g. http://proxy.example.com:3128
+      #HTTP_PROXY: ((http-proxy))
+    config:
+      platform: linux
+      #image_resource:
+      #  type: docker-image
+      #  source:
+      #    repository: chef/chefdk
+      #    tag: ((chefdk-version))
+          # NG, setting disable
+          #registry_mirror: https://((registry-mirror-domain))
+          #ca_certs:
+          #- domain: ((registry-mirror-domain))
+          #  cert: ((docker-reg-ca-cert))
+      inputs:
+      - name: src-git
+      run:
+        #dir: ./src-git/cookbooks/((cookbook-name))
+        #path: rake
+        path: /bin/bash
+        args:
+        - -c
+        - |
+          cd ./src-git/cookbooks/((cookbook-name))
+          bundle config --local silence_root_warning 1
+          bundle install
+          rake
+- name: publish-cookbook
+  plan:
+  - aggregate:
+    - get: src-git
+      params:
+        depth: 5
+      trigger: false
+      passed: [test-cookbook]
+    - get: chefdk-cache
+      passed: [test-cookbook]
+  - task: publish
+    image: chefdk-cache
+    params:
+      http_proxy: ((http-proxy))
+      chef_username: ((chef-username))
+      chef_client_key: ((chef-client-key))
+    config:
+      platform: linux
+      inputs:
+      - name: src-git
+      run:
+        path: /bin/bash
+        args:
+        - -c
+        - |
+          echo '{"username":"((chef-username))","key":"/root/chef-client-key.pem"}' > /root/.stove
+          echo "$chef_client_key"  > /root/chef-client-key.pem
+          cd ./src-git/cookbooks/((cookbook-name))
+          bundle config --local silence_root_warning 1
+          bundle install
+          rake publish
+  - put: src-git
+    params:
+      repository: src-git
+      tag_prefix: ((cookbook-name))-
+      tag: src-git/cookbooks/((cookbook-name))/version
+      only_tag: true
+      annotate: src-git/cookbooks/((cookbook-name))/version
diff --git a/cookbooks/go_utils/fly-vars.local.yml b/cookbooks/go_utils/fly-vars.local.yml
new file mode 100644 (file)
index 0000000..3a12557
--- /dev/null
@@ -0,0 +1,2 @@
+---
+cookbook-name: go_utils
diff --git a/cookbooks/go_utils/fly-vars.yml b/cookbooks/go_utils/fly-vars.yml
new file mode 100644 (file)
index 0000000..76f2fcd
--- /dev/null
@@ -0,0 +1,2 @@
+---
+chefdk-version: 1.6.11
diff --git a/cookbooks/go_utils/metadata.rb b/cookbooks/go_utils/metadata.rb
new file mode 100644 (file)
index 0000000..7f7ed83
--- /dev/null
@@ -0,0 +1,17 @@
+name             'go_utils'
+maintainer       'whitestar'
+maintainer_email ''
+license          'Apache 2.0'
+description      'Installs/Configures Go installer'
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
+version          IO.read(File.join(File.dirname(__FILE__), 'version')).chomp
+source_url       'http://scm.osdn.jp/gitroot/metasearch/grid-chef-repo.git'
+issues_url       'https://osdn.jp/projects/metasearch/ticket'
+
+chef_version     '>= 12'
+%w(centos redhat).each do |os|
+  supports os, '>= 7.3'
+end
+
+supports 'debian', '>= 8.0'
+supports 'ubuntu', '>= 14.04'
diff --git a/cookbooks/go_utils/recipes/default.rb b/cookbooks/go_utils/recipes/default.rb
new file mode 100644 (file)
index 0000000..350d09b
--- /dev/null
@@ -0,0 +1,18 @@
+#
+# Cookbook Name:: go_utils
+# Recipe:: default
+#
+# Copyright 2019, whitestar
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
diff --git a/cookbooks/go_utils/recipes/go-installer.rb b/cookbooks/go_utils/recipes/go-installer.rb
new file mode 100644 (file)
index 0000000..f5b2f9e
--- /dev/null
@@ -0,0 +1,51 @@
+#
+# Cookbook Name:: go_utils
+# Recipe:: go-installer
+#
+# Copyright 2019, whitestar
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+doc_url = 'https://golang.org/doc/'
+
+[
+  'curl',
+].each {|pkg|
+  resources(package: pkg) rescue package pkg do
+    action :install
+  end
+}
+
+[
+  'go_install',
+].each {|script|
+  template "/usr/local/bin/#{script}" do
+    source  "usr/local/bin/#{script}"
+    owner 'root'
+    group 'root'
+    mode '0755'
+    action :create
+  end
+}
+
+log 'go-installer post install message' do
+  message <<-"EOM"
+Note: You must execute the following command manually.
+    See #{doc_url}
+    * install Go:
+      $ go_install
+      ...
+      $ /usr/local/go/bin/go version
+EOM
+end
diff --git a/cookbooks/go_utils/spec/recipes/default_spec.rb b/cookbooks/go_utils/spec/recipes/default_spec.rb
new file mode 100644 (file)
index 0000000..bd5eec5
--- /dev/null
@@ -0,0 +1,9 @@
+require_relative '../spec_helper'
+
+describe 'go_utils::default' do
+  let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) }
+
+  #it 'does something' do
+  #  expect(chef_run).to do_something('...')
+  #end
+end
diff --git a/cookbooks/go_utils/spec/spec_helper.rb b/cookbooks/go_utils/spec/spec_helper.rb
new file mode 100644 (file)
index 0000000..1995e2b
--- /dev/null
@@ -0,0 +1,25 @@
+# Added by ChefSpec
+require 'chefspec'
+
+# Uncomment to use ChefSpec's Berkshelf extension
+# require 'chefspec/berkshelf'
+
+RSpec.configure do |config|
+  # Specify the path for Chef Solo to find cookbooks
+  # config.cookbook_path = '/var/cookbooks'
+
+  # Specify the path for Chef Solo to find roles
+  # config.role_path = '/var/roles'
+
+  # Specify the Chef log_level (default: :warn)
+  # config.log_level = :debug
+
+  # Specify the path to a local JSON file with Ohai data
+  # config.path = 'ohai.json'
+
+  # Specify the operating platform to mock Ohai data from
+  # config.platform = 'ubuntu'
+
+  # Specify the operating version to mock Ohai data from
+  # config.version = '12.04'
+end
diff --git a/cookbooks/go_utils/templates/default/usr/local/bin/go_install b/cookbooks/go_utils/templates/default/usr/local/bin/go_install
new file mode 100644 (file)
index 0000000..2b50746
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+PATH=.:/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
+
+<%
+go_ver = node['go_utils']['go']['version']
+arch = nil
+
+case node['kernel']['machine']
+when 'x86_64'
+  arch = 'amd64'
+when 'arm64'
+  arch = 'arm64'
+when 'armv7l', 'armv6l'
+  arch = 'armv6l'
+end
+
+filename = "go#{go_ver}.linux-#{arch}.tar.gz"
+-%>
+curl -O https://dl.google.com/go/<%= filename %>
+sudo tar -C /usr/local -xzf <%= filename %>
diff --git a/cookbooks/go_utils/version b/cookbooks/go_utils/version
new file mode 100644 (file)
index 0000000..6e8bf73
--- /dev/null
@@ -0,0 +1 @@
+0.1.0
diff --git a/roles/go-utils.rb b/roles/go-utils.rb
new file mode 100644 (file)
index 0000000..524d72d
--- /dev/null
@@ -0,0 +1,14 @@
+name 'go-utils'
+description 'Go Setup Utilities'
+
+run_list(
+  'recipe[go_utils::go-installer]',
+)
+
+#env_run_lists
+
+default_attributes(
+)
+
+override_attributes(
+)