OSDN Git Service

adds the `platform_utils::pip` recipe.
authorwhitestar <whitestar@users.osdn.me>
Tue, 21 Aug 2018 02:49:08 +0000 (11:49 +0900)
committerwhitestar <whitestar@users.osdn.me>
Tue, 21 Aug 2018 02:49:08 +0000 (11:49 +0900)
cookbooks/platform_utils/.rubocop.yml
cookbooks/platform_utils/CHANGELOG.md
cookbooks/platform_utils/Rakefile
cookbooks/platform_utils/concourse.yml [new file with mode: 0644]
cookbooks/platform_utils/fly-vars.yml [new file with mode: 0644]
cookbooks/platform_utils/libraries/helper.rb
cookbooks/platform_utils/libraries/package_utils.rb
cookbooks/platform_utils/metadata.rb
cookbooks/platform_utils/recipes/pip.rb [new file with mode: 0644]
cookbooks/platform_utils/recipes/sudo.rb
cookbooks/platform_utils/version [new file with mode: 0644]

index e4666a4..8941c49 100644 (file)
@@ -28,13 +28,17 @@ Style/RescueModifier:
   Enabled: false
 Style/SpaceBeforeFirstArg:
   Enabled: false
+Style/SpaceInsideBlockBraces:
+  Enabled: false
 Style/TrailingCommaInLiteral:
-  EnforcedStyleForMultiline: comma
+  EnforcedStyleForMultiline: consistent_comma
 Style/WordArray:
   Enabled: false
 
 #Style/AccessorMethodName:
 #  Enabled: false
+Metrics/BlockLength:
+  Max: 50
 Metrics/MethodLength:
   Max: 60
 Metrics/ModuleLength:
index bcd2a8c..66ff295 100644 (file)
@@ -1,6 +1,10 @@
 platform_utils CHANGELOG
 ========================
 
+0.5.0
+-----
+- adds the `platform_utils::pip` recipe. 
+
 0.4.4
 -----
 - improves the `platform_utils::kernel_modules` recipe.
index 513cecc..64191a5 100644 (file)
@@ -1,10 +1,15 @@
 require 'rspec/core/rake_task'
 require 'rubocop/rake_task'
 require 'foodcritic'
+require 'stove/rake_task'
 
 namespace :style do
   desc 'Run Ruby style checks'
-  RuboCop::RakeTask.new(:ruby)
+  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|
@@ -20,4 +25,17 @@ 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/platform_utils/concourse.yml b/cookbooks/platform_utils/concourse.yml
new file mode 100644 (file)
index 0000000..a9b0307
--- /dev/null
@@ -0,0 +1,100 @@
+---
+# $ fly -t $CC_TARGET sp -p platform_utils-cookbook -c concourse.yml -l fly-vars.yml -l ~/sec/credentials-prod.yml
+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 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 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/platform_utils/fly-vars.yml b/cookbooks/platform_utils/fly-vars.yml
new file mode 100644 (file)
index 0000000..33bbc17
--- /dev/null
@@ -0,0 +1,3 @@
+---
+cookbook-name: platform_utils
+chefdk-version: 1.4.3
index cf8c770..2067d3a 100644 (file)
@@ -26,28 +26,28 @@ module PlatformUtils
     include PlatformUtils::VirtUtils
 
     def load_kernel_module(mod_name)
-      unless container_guest_node?
-        # for old distributions.
-        dir = '/etc/modules-load.d'
-        resources(directory: dir) rescue directory dir do
-          owner 'root'
-          group 'root'
-          mode '0755'
-        end
+      return if container_guest_node?
+
+      # for old distributions.
+      dir = '/etc/modules-load.d'
+      resources(directory: dir) rescue directory dir do
+        owner 'root'
+        group 'root'
+        mode '0755'
+      end
 
-        exec_name = "load_#{mod_name}_kernel_module"
-        resources(execute: exec_name) rescue execute exec_name do
-          command "modprobe #{mod_name}"
-          not_if "lsmod | grep #{mod_name}"
-        end
+      exec_name = "load_#{mod_name}_kernel_module"
+      resources(execute: exec_name) rescue execute exec_name do
+        command "modprobe #{mod_name}"
+        not_if "lsmod | grep #{mod_name}"
+      end
 
-        file_name = "/etc/modules-load.d/#{mod_name}.conf"
-        resources(file: file_name) rescue file file_name do
-          content "#{mod_name}\n"
-          owner 'root'
-          group 'root'
-          mode '0644'
-        end
+      file_name = "/etc/modules-load.d/#{mod_name}.conf"
+      resources(file: file_name) rescue file file_name do
+        content "#{mod_name}\n"
+        owner 'root'
+        group 'root'
+        mode '0644'
       end
     end
 
@@ -55,10 +55,10 @@ module PlatformUtils
       invalid_word = words.find {|word|
         word =~ /[;\|&<>`]/
       }
-      unless invalid_word.nil?
-        Chef::Log.fatal("Command string includes the invalid character (;|&<>`): #{invalid_word}")
-        raise
-      end
+
+      return if invalid_word.nil?
+      Chef::Log.fatal("Command string includes the invalid character (;|&<>`): #{invalid_word}")
+      raise
     end
 
     def touch_subid_files
index 7360cc0..fcbc5ad 100644 (file)
@@ -22,43 +22,43 @@ module PlatformUtils
   module PackageUtils
     def cron_pkg_name
       case node['platform_family']
-      when 'debian'then return 'cron'
-      when 'rhel'  then return 'crontabs'
+      when 'debian'then 'cron'
+      when 'rhel'  then 'crontabs'
       end
     end
 
     def cron_serv_name
       case node['platform_family']
-      when 'debian'then return 'cron'
-      when 'rhel'  then return 'crond'
+      when 'debian'then 'cron'
+      when 'rhel'  then 'crond'
       end
     end
 
     def httpd_pkg_name
       case node['platform_family']
-      when 'debian'then return 'apache2'
-      when 'rhel'  then return 'httpd'
+      when 'debian'then 'apache2'
+      when 'rhel'  then 'httpd'
       end
     end
 
     def httpd_serv_name
       case node['platform_family']
-      when 'debian'then return 'apache2'
-      when 'rhel'  then return 'httpd'
+      when 'debian'then 'apache2'
+      when 'rhel'  then 'httpd'
       end
     end
 
     def jsvc_pkg_name
       case node['platform_family']
-      when 'debian' then return 'jsvc'
-      when 'rhel'   then return 'jakarta-commons-daemon-jsvc'
+      when 'debian' then 'jsvc'
+      when 'rhel'   then 'jakarta-commons-daemon-jsvc'
       end
     end
 
     def libbz2_pkg_name
       case node['platform_family']
-      when 'debian' then return 'libbz2-1.0'
-      when 'rhel'   then return 'bzip2-libs'
+      when 'debian' then 'libbz2-1.0'
+      when 'rhel'   then 'bzip2-libs'
       end
     end
   end
index d1ac1a7..e018ff2 100644 (file)
@@ -5,10 +5,11 @@ maintainer_email ''
 license          'Apache 2.0'
 description      'Platform Utilities'
 long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
-version          '0.4.4'
+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'
 
-%w( centos redhat debian ubuntu ).each do |os|
+chef_version     '>= 12'
+%w(centos redhat debian ubuntu).each do |os|
   supports os
 end
diff --git a/cookbooks/platform_utils/recipes/pip.rb b/cookbooks/platform_utils/recipes/pip.rb
new file mode 100644 (file)
index 0000000..4a154a2
--- /dev/null
@@ -0,0 +1,43 @@
+#
+# Cookbook Name:: platform_utils
+# Recipe:: pip
+#
+# Copyright 2018, 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.
+#
+
+case node['platform_family']
+when 'debian'
+  pkgs = [
+    'python-setuptools',
+    'python-pip',
+  ]
+  pkgs.each {|pkg|
+    resources(package: pkg) rescue package pkg do
+      action :install
+    end
+  }
+when 'rhel'
+  pkg = 'python-setuptools'
+  resources(package: pkg) rescue package pkg do
+    action :install
+  end
+
+  execute 'install_pip' do
+    user 'root'
+    command 'easy_install pip'
+    action :run
+    not_if 'which pip'
+  end
+end
index 5239f1c..37a11c6 100644 (file)
@@ -43,9 +43,11 @@ sudo_group = value_for_platform_family(
 )
 sudo_members = node['platform_utils']['sudo']['group']['members']
 
-group "append_#{sudo_members.join('_')}_to_#{sudo_group}_group" do
-  group_name sudo_group
-  action :modify
-  members sudo_members
-  append true
-end unless sudo_members.empty?
+unless sudo_members.empty?
+  group "append_#{sudo_members.join('_')}_to_#{sudo_group}_group" do
+    group_name sudo_group
+    action :modify
+    members sudo_members
+    append true
+  end
+end
diff --git a/cookbooks/platform_utils/version b/cookbooks/platform_utils/version
new file mode 100644 (file)
index 0000000..8f0916f
--- /dev/null
@@ -0,0 +1 @@
+0.5.0