OSDN Git Service

adds autopilot features. bind-grid-0.2.0
authorwhitestar <whitestar@users.osdn.me>
Tue, 18 Sep 2018 12:32:00 +0000 (21:32 +0900)
committerwhitestar <whitestar@users.osdn.me>
Tue, 18 Sep 2018 12:32:00 +0000 (21:32 +0900)
14 files changed:
cookbooks/bind-grid/.rubocop.yml
cookbooks/bind-grid/CHANGELOG.md
cookbooks/bind-grid/Gemfile [new file with mode: 0644]
cookbooks/bind-grid/Gemfile.lock [new file with mode: 0644]
cookbooks/bind-grid/README.md
cookbooks/bind-grid/Rakefile
cookbooks/bind-grid/attributes/default.rb
cookbooks/bind-grid/concourse.yml [new file with mode: 0644]
cookbooks/bind-grid/fly-vars.local.yml [new file with mode: 0644]
cookbooks/bind-grid/fly-vars.yml [new file with mode: 0644]
cookbooks/bind-grid/metadata.rb
cookbooks/bind-grid/recipes/bind.rb
cookbooks/bind-grid/templates/default/etc/cron.d/bind9-local [new file with mode: 0644]
cookbooks/bind-grid/version [new file with mode: 0644]

index 17f87f1..7af5114 100644 (file)
@@ -24,8 +24,10 @@ Style/RescueModifier:
   Enabled: false
 Style/SpaceBeforeFirstArg:
   Enabled: false
+Style/SpaceInsideBlockBraces:
+  Enabled: false
 Style/TrailingCommaInLiteral:
-  EnforcedStyleForMultiline: comma
+  EnforcedStyleForMultiline: consistent_comma
 Style/WordArray:
   Enabled: false
   
index 172d13b..6153098 100644 (file)
@@ -1,5 +1,9 @@
 # bind-grid CHANGELOG
 
+0.2.0
+-----
+- adds autopilot features.
+
 0.1.1
 -----
 - adds the `['bind-grid']['options']['dnssec-validation']` attribute.
diff --git a/cookbooks/bind-grid/Gemfile b/cookbooks/bind-grid/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/bind-grid/Gemfile.lock b/cookbooks/bind-grid/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
index 43011a5..5a59ef3 100644 (file)
@@ -31,6 +31,7 @@ This cookbook sets up BIND server.
 
 |Key|Type|Description, example|Default|
 |:--|:--|:--|:--|
+|`['bind-grid']['autopilot']`|Hash|Autopilot configurations.|See `attribute/default.rb`|
 |`['bind-grid']['role']`|String|`'master'` or `'slave'`|`'master'`|
 |`['bind-grid']['acl']`|Hash|acl statements.|See `attribute/default.rb`|
 |`['bind-grid']['acl']['internal']`|Array|Predefined `internal` acl.|`['127.0.0.1']`|
@@ -185,7 +186,7 @@ override_attributes(
 - Author:: whitestar at osdn.jp
 
 ```text
-Copyright 2017, whitestar
+Copyright 2017-2018, whitestar
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
index 513cecc..f1c82d7 100644 (file)
@@ -1,10 +1,67 @@
 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',
+    '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',
+    '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)
+  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 +77,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']
index fbf24e2..8137365 100644 (file)
@@ -2,7 +2,7 @@
 # Cookbook Name:: bind-grid
 # Attributes:: default
 #
-# Copyright 2017, whitestar
+# Copyright 2017-2018, whitestar
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # limitations under the License.
 #
 
+default['bind-grid']['autopilot'] = {
+  'enabled' => false,
+  'log_dir' => '/var/log',
+  'wait_time' => '90s',
+}
 default['bind-grid']['role'] = 'master'  # or 'slave'
 default['bind-grid']['acl'] = {
   'internal' => [
diff --git a/cookbooks/bind-grid/concourse.yml b/cookbooks/bind-grid/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/bind-grid/fly-vars.local.yml b/cookbooks/bind-grid/fly-vars.local.yml
new file mode 100644 (file)
index 0000000..04bceaf
--- /dev/null
@@ -0,0 +1,2 @@
+---
+cookbook-name: bind-grid
diff --git a/cookbooks/bind-grid/fly-vars.yml b/cookbooks/bind-grid/fly-vars.yml
new file mode 100644 (file)
index 0000000..76f2fcd
--- /dev/null
@@ -0,0 +1,2 @@
+---
+chefdk-version: 1.6.11
index d6daea8..90920bb 100644 (file)
@@ -5,10 +5,11 @@ maintainer_email ''
 license          'Apache 2.0'
 description      'Installs/Configures BIND'
 long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
-version          '0.1.1'
+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( debian ubuntu ).each do |os|
+chef_version     '>= 12'
+%w(debian ubuntu).each do |os|
   supports os
 end
index 17b96fb..2ac2d7c 100644 (file)
@@ -2,7 +2,7 @@
 # Cookbook Name:: bind-grid
 # Recipe:: bind
 #
-# Copyright 2017, whitestar
+# Copyright 2017-2018, whitestar
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -60,3 +60,13 @@ if node['bind-grid']['role'] == 'master'
     end
   }
 end
+
+# autopilot
+srv = 'bind9'
+template "/etc/cron.d/#{srv}-local" do
+  source  "etc/cron.d/#{srv}-local"
+  owner 'root'
+  group 'root'
+  mode '0644'
+  action :delete unless node['bind-grid']['autopilot']['enabled']
+end
diff --git a/cookbooks/bind-grid/templates/default/etc/cron.d/bind9-local b/cookbooks/bind-grid/templates/default/etc/cron.d/bind9-local
new file mode 100644 (file)
index 0000000..c79b7a2
--- /dev/null
@@ -0,0 +1,13 @@
+<%
+name = 'bind9'
+
+conf = node['bind-grid']['autopilot']
+log = "#{conf['log_dir']}/#{name}-local.log"
+wait_time = conf['wait_time']
+-%>
+PATH=/usr/bin:/bin:/usr/local/bin
+DATE_F='+%Y-%m-%d %H:%M:%S %z'
+LOG=<%= log %>
+NAME=<%= name %>
+
+@reboot root sleep <%= wait_time %> && date "$DATE_F" > $LOG && systemctl restart $NAME >> $LOG 2>&1 && systemctl status $NAME >> $LOG 2>&1
diff --git a/cookbooks/bind-grid/version b/cookbooks/bind-grid/version
new file mode 100644 (file)
index 0000000..0ea3a94
--- /dev/null
@@ -0,0 +1 @@
+0.2.0