• R/O
  • HTTP
  • SSH
  • HTTPS

grid-chef-repo: Commit

Grid環境構築用のChefリポジトリです。


Commit MetaInfo

Revision0f69360c089b8bf43c49e8d5b72a9ddd4084071a (tree)
Time2018-09-18 21:32:00
Authorwhitestar <whitestar@user...>
Commiterwhitestar

Log Message

adds autopilot features.

Change Summary

Incremental Difference

--- a/cookbooks/bind-grid/.rubocop.yml
+++ b/cookbooks/bind-grid/.rubocop.yml
@@ -24,8 +24,10 @@ Style/RescueModifier:
2424 Enabled: false
2525 Style/SpaceBeforeFirstArg:
2626 Enabled: false
27+Style/SpaceInsideBlockBraces:
28+ Enabled: false
2729 Style/TrailingCommaInLiteral:
28- EnforcedStyleForMultiline: comma
30+ EnforcedStyleForMultiline: consistent_comma
2931 Style/WordArray:
3032 Enabled: false
3133
--- a/cookbooks/bind-grid/CHANGELOG.md
+++ b/cookbooks/bind-grid/CHANGELOG.md
@@ -1,5 +1,9 @@
11 # bind-grid CHANGELOG
22
3+0.2.0
4+-----
5+- adds autopilot features.
6+
37 0.1.1
48 -----
59 - adds the `['bind-grid']['options']['dnssec-validation']` attribute.
--- /dev/null
+++ b/cookbooks/bind-grid/Gemfile
@@ -0,0 +1,4 @@
1+source 'https://rubygems.org'
2+
3+# with Chef DK
4+gem 'stove'
--- /dev/null
+++ b/cookbooks/bind-grid/Gemfile.lock
@@ -0,0 +1,22 @@
1+GEM
2+ remote: https://rubygems.org/
3+ specs:
4+ chef-api (0.8.0)
5+ logify (~> 0.1)
6+ mime-types
7+ logify (0.2.0)
8+ mime-types (3.2.2)
9+ mime-types-data (~> 3.2015)
10+ mime-types-data (3.2018.0812)
11+ stove (6.0.0)
12+ chef-api (~> 0.5)
13+ logify (~> 0.2)
14+
15+PLATFORMS
16+ ruby
17+
18+DEPENDENCIES
19+ stove
20+
21+BUNDLED WITH
22+ 1.16.0
--- a/cookbooks/bind-grid/README.md
+++ b/cookbooks/bind-grid/README.md
@@ -31,6 +31,7 @@ This cookbook sets up BIND server.
3131
3232 |Key|Type|Description, example|Default|
3333 |:--|:--|:--|:--|
34+|`['bind-grid']['autopilot']`|Hash|Autopilot configurations.|See `attribute/default.rb`|
3435 |`['bind-grid']['role']`|String|`'master'` or `'slave'`|`'master'`|
3536 |`['bind-grid']['acl']`|Hash|acl statements.|See `attribute/default.rb`|
3637 |`['bind-grid']['acl']['internal']`|Array|Predefined `internal` acl.|`['127.0.0.1']`|
@@ -185,7 +186,7 @@ override_attributes(
185186 - Author:: whitestar at osdn.jp
186187
187188 ```text
188-Copyright 2017, whitestar
189+Copyright 2017-2018, whitestar
189190
190191 Licensed under the Apache License, Version 2.0 (the "License");
191192 you may not use this file except in compliance with the License.
--- a/cookbooks/bind-grid/Rakefile
+++ b/cookbooks/bind-grid/Rakefile
@@ -1,10 +1,67 @@
11 require 'rspec/core/rake_task'
22 require 'rubocop/rake_task'
33 require 'foodcritic'
4+require 'stove/rake_task'
5+
6+tpl_cookbook = '00cookbook'
7+cookbook_name = File.basename(Dir.pwd)
8+
9+desc 'Initialize project'
10+task :init do
11+ next if cookbook_name == tpl_cookbook
12+
13+ [
14+ '.foodcritic',
15+ '.rubocop.yml',
16+ 'Berksfile',
17+ 'concourse.yml',
18+ 'fly-vars.yml',
19+ 'fly-vars.local.yml',
20+ 'Gemfile',
21+ 'Gemfile.lock',
22+ 'version',
23+ ].each {|conf|
24+ sh "cp ../#{tpl_cookbook}/#{conf} ./" unless File.exist?(conf)
25+ }
26+
27+ ruby [
28+ %(-pne '$_.gsub!(/^cookbook-name: .*$/, "cookbook-name: #{cookbook_name}")'),
29+ '-i fly-vars.local.yml',
30+ ].join(' ')
31+end
32+
33+desc 'Update project'
34+task :update do
35+ next if cookbook_name == tpl_cookbook
36+
37+ [
38+ 'Rakefile',
39+ 'concourse.yml',
40+ 'fly-vars.yml',
41+ 'Gemfile',
42+ 'Gemfile.lock',
43+ ].each {|conf|
44+ sh "cp ../#{tpl_cookbook}/#{conf} ./"
45+ }
46+end
47+
48+desc 'fly set-pipeline'
49+task :'set-pipeline' do
50+ sh [
51+ "fly -t $CC_TARGET sp -p #{cookbook_name}-cookbook -c concourse.yml",
52+ '-l fly-vars.yml -l fly-vars.local.yml -l ~/sec/credentials-prod.yml',
53+ ].join(' ')
54+end
55+desc 'rake set-pipeline alias'
56+task sp: 'set-pipeline'
457
558 namespace :style do
659 desc 'Run Ruby style checks'
7- RuboCop::RakeTask.new(:ruby)
60+ RuboCop::RakeTask.new(:ruby) do |t|
61+ t.options = [
62+ '--auto-gen-config', # creates .rubocop_todo.yml
63+ ]
64+ end
865
966 desc 'Run Chef style checks'
1067 FoodCritic::Rake::LintTask.new(:chef) do |t|
@@ -20,4 +77,17 @@ task style: ['style:chef', 'style:ruby']
2077 desc 'Run ChefSpec examples'
2178 RSpec::Core::RakeTask.new(:spec)
2279
80+desc 'Publish cookbook'
81+Stove::RakeTask.new(:publish) do |t|
82+ t.stove_opts = [
83+ # `--username` and `--key` are set in ~/.stove typically.
84+ #'--username', 'somebody',
85+ #'--key', '~/chef/chef.io.example.com/somebody.pem',
86+ #'--endpoint', 'https://supermarket.io.example.com/api/v1', # default: supermarket.chef.io
87+ #'--no-ssl-verify',
88+ '--no-git',
89+ '--log-level', 'info',
90+ ]
91+end
92+
2393 task default: ['style', 'spec']
--- a/cookbooks/bind-grid/attributes/default.rb
+++ b/cookbooks/bind-grid/attributes/default.rb
@@ -2,7 +2,7 @@
22 # Cookbook Name:: bind-grid
33 # Attributes:: default
44 #
5-# Copyright 2017, whitestar
5+# Copyright 2017-2018, whitestar
66 #
77 # Licensed under the Apache License, Version 2.0 (the "License");
88 # you may not use this file except in compliance with the License.
@@ -17,6 +17,11 @@
1717 # limitations under the License.
1818 #
1919
20+default['bind-grid']['autopilot'] = {
21+ 'enabled' => false,
22+ 'log_dir' => '/var/log',
23+ 'wait_time' => '90s',
24+}
2025 default['bind-grid']['role'] = 'master' # or 'slave'
2126 default['bind-grid']['acl'] = {
2227 'internal' => [
--- /dev/null
+++ b/cookbooks/bind-grid/concourse.yml
@@ -0,0 +1,101 @@
1+---
2+resources:
3+- name: src-git
4+ type: git
5+ source:
6+ uri: ((git-id-osdn))@git.osdn.net:/gitroot/metasearch/grid-chef-repo.git
7+ branch: master
8+ paths:
9+ - cookbooks/((cookbook-name))
10+ private_key: ((git-private-key))
11+ git_user: ((git-user-osdn))
12+ #check_every: 1h # default: 1m
13+- name: chefdk-cache
14+ type: docker-image
15+ source:
16+ repository: chef/chefdk
17+ tag: ((chefdk-version))
18+ # ((param)) style: fly >= 3.2.0
19+ registry_mirror: https://((registry-mirror-domain)) # e.g. https://registry.docker.example.com:5000
20+ ca_certs:
21+ - domain: ((registry-mirror-domain)) # e.g. registry.docker.example.com:5000
22+ cert: ((docker-reg-ca-cert))
23+ check_every: 6h # default: 1m
24+
25+jobs:
26+- name: test-cookbook
27+ plan:
28+ - aggregate:
29+ - get: src-git
30+ params:
31+ depth: 5
32+ trigger: true
33+ - get: chefdk-cache
34+ - task: ci-build
35+ image: chefdk-cache
36+ params:
37+ http_proxy: ((http-proxy)) # e.g. http://proxy.example.com:3128
38+ #HTTP_PROXY: ((http-proxy))
39+ config:
40+ platform: linux
41+ #image_resource:
42+ # type: docker-image
43+ # source:
44+ # repository: chef/chefdk
45+ # tag: ((chefdk-version))
46+ # NG, setting disable
47+ #registry_mirror: https://((registry-mirror-domain))
48+ #ca_certs:
49+ #- domain: ((registry-mirror-domain))
50+ # cert: ((docker-reg-ca-cert))
51+ inputs:
52+ - name: src-git
53+ run:
54+ #dir: ./src-git/cookbooks/((cookbook-name))
55+ #path: rake
56+ path: /bin/bash
57+ args:
58+ - -c
59+ - |
60+ cd ./src-git/cookbooks/((cookbook-name))
61+ bundle config --local silence_root_warning 1
62+ bundle install
63+ rake
64+- name: publish-cookbook
65+ plan:
66+ - aggregate:
67+ - get: src-git
68+ params:
69+ depth: 5
70+ trigger: false
71+ passed: [test-cookbook]
72+ - get: chefdk-cache
73+ passed: [test-cookbook]
74+ - task: publish
75+ image: chefdk-cache
76+ params:
77+ http_proxy: ((http-proxy))
78+ chef_username: ((chef-username))
79+ chef_client_key: ((chef-client-key))
80+ config:
81+ platform: linux
82+ inputs:
83+ - name: src-git
84+ run:
85+ path: /bin/bash
86+ args:
87+ - -c
88+ - |
89+ echo '{"username":"((chef-username))","key":"/root/chef-client-key.pem"}' > /root/.stove
90+ echo "$chef_client_key" > /root/chef-client-key.pem
91+ cd ./src-git/cookbooks/((cookbook-name))
92+ bundle config --local silence_root_warning 1
93+ bundle install
94+ rake publish
95+ - put: src-git
96+ params:
97+ repository: src-git
98+ tag_prefix: ((cookbook-name))-
99+ tag: src-git/cookbooks/((cookbook-name))/version
100+ only_tag: true
101+ annotate: src-git/cookbooks/((cookbook-name))/version
--- /dev/null
+++ b/cookbooks/bind-grid/fly-vars.local.yml
@@ -0,0 +1,2 @@
1+---
2+cookbook-name: bind-grid
--- /dev/null
+++ b/cookbooks/bind-grid/fly-vars.yml
@@ -0,0 +1,2 @@
1+---
2+chefdk-version: 1.6.11
--- a/cookbooks/bind-grid/metadata.rb
+++ b/cookbooks/bind-grid/metadata.rb
@@ -5,10 +5,11 @@ maintainer_email ''
55 license 'Apache 2.0'
66 description 'Installs/Configures BIND'
77 long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
8-version '0.1.1'
8+version IO.read(File.join(File.dirname(__FILE__), 'version')).chomp
99 source_url 'http://scm.osdn.jp/gitroot/metasearch/grid-chef-repo.git'
1010 issues_url 'https://osdn.jp/projects/metasearch/ticket'
1111
12-%w( debian ubuntu ).each do |os|
12+chef_version '>= 12'
13+%w(debian ubuntu).each do |os|
1314 supports os
1415 end
--- a/cookbooks/bind-grid/recipes/bind.rb
+++ b/cookbooks/bind-grid/recipes/bind.rb
@@ -2,7 +2,7 @@
22 # Cookbook Name:: bind-grid
33 # Recipe:: bind
44 #
5-# Copyright 2017, whitestar
5+# Copyright 2017-2018, whitestar
66 #
77 # Licensed under the Apache License, Version 2.0 (the "License");
88 # you may not use this file except in compliance with the License.
@@ -60,3 +60,13 @@ if node['bind-grid']['role'] == 'master'
6060 end
6161 }
6262 end
63+
64+# autopilot
65+srv = 'bind9'
66+template "/etc/cron.d/#{srv}-local" do
67+ source "etc/cron.d/#{srv}-local"
68+ owner 'root'
69+ group 'root'
70+ mode '0644'
71+ action :delete unless node['bind-grid']['autopilot']['enabled']
72+end
--- /dev/null
+++ b/cookbooks/bind-grid/templates/default/etc/cron.d/bind9-local
@@ -0,0 +1,13 @@
1+<%
2+name = 'bind9'
3+
4+conf = node['bind-grid']['autopilot']
5+log = "#{conf['log_dir']}/#{name}-local.log"
6+wait_time = conf['wait_time']
7+-%>
8+PATH=/usr/bin:/bin:/usr/local/bin
9+DATE_F='+%Y-%m-%d %H:%M:%S %z'
10+LOG=<%= log %>
11+NAME=<%= name %>
12+
13+@reboot root sleep <%= wait_time %> && date "$DATE_F" > $LOG && systemctl restart $NAME >> $LOG 2>&1 && systemctl status $NAME >> $LOG 2>&1
--- /dev/null
+++ b/cookbooks/bind-grid/version
@@ -0,0 +1 @@
1+0.2.0
Show on old repository browser