ncss-cookbooks 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +35 -0
  2. data/VERSION +1 -1
  3. data/lib/ncss-cookbooks.rb +33 -7
  4. metadata +17 -17
data/README.md CHANGED
@@ -4,8 +4,43 @@
4
4
 
5
5
  Chef の Cookbooks を一発で NIFTYCloud クラウドストレージにアップロードするコマンドです。
6
6
 
7
+ ## インストール
8
+
9
+ gem install ncss-cookbooks
10
+
7
11
  ## 使い方
8
12
 
13
+ まずはアップロードしたい cookbooks を用意します。
14
+
15
+ $ mkdir my-cookbooks
16
+ $ cd my-cookbooks
17
+ $ echo "cookbook_path '.'" > knife.rb
18
+ $ knife cookbook create hello-world
19
+ ** Creating cookbook hello-world
20
+ ** Creating README for cookbook: hello-world
21
+ ** Creating CHANGELOG for cookbook: hello-world
22
+ ** Creating metadata for cookbook: hello-world
23
+
24
+ 次に同じディレクトリの中に、
25
+ cookbooks のバージョン情報が書いてある VERSION ファイルを作成します。
26
+
27
+ $ echo "0.0.0" > VERSION
28
+
29
+ さらに環境変数で API キーを設定します。
30
+
31
+ $ export ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX
32
+ $ export SECRET_ACCESS_KEY=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
33
+
34
+ これで準備完了です。cookbooks ディレクトリの中で ncss-cookbooks コマンドを打ちます。
35
+ ncss-cookbooks create でバケットを作成します。
36
+
9
37
  $ ncss-cookbooks create my-bucket
38
+
39
+ ncss-cookbooks upload で作成したバケットに cookbooks をアップロードします。
40
+
10
41
  $ ncss-cookbooks upload my-bucket
42
+ https://my-bucket.ncss.nifty.com/v0.0.0/cookbooks.tgz
43
+
44
+ 発行された URL は chef-solo の -r オプションで利用することができます。
11
45
 
46
+ $ chef-solo -j node.json -r https://my-bucket.ncss.nifty.com/v0.0.0/cookbooks.tgz
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -17,32 +17,46 @@ class NcssCookbooks < Thor
17
17
  end
18
18
 
19
19
  desc 'upload <bucket>', 'upload . to ncss bucket'
20
+ option :verbose
20
21
  def upload(bucket_name)
21
- pwd = Dir.pwd
22
- unless File.exists?("#{pwd}/VERSION") || File.readble?("#{pwd}/VERSION")
22
+ @pwd = Dir.pwd
23
+ unless File.exists?("#{@pwd}/VERSION") || File.readble?("#{@pwd}/VERSION")
23
24
  abort "Error: VERSION file does not exists."
24
25
  end
25
- version = File.read("#{pwd}/VERSION").chomp
26
+ version = File.read("#{@pwd}/VERSION").chomp
27
+ puts "Version is v#{version}"
26
28
 
27
29
  bucket = ncss.buckets[bucket_name]
28
30
  unless bucket.exists?
29
31
  abort "Error: Bucket #{bucket_name} does not exist."
30
32
  end
31
- object = bucket.objects["#{version}/cookbooks.tgz"]
33
+ object = bucket.objects["v#{version}/cookbooks.tgz"]
32
34
 
33
- Dir.mktmpdir('ncss-cookbooks') do |dir|
35
+ Dir.mktmpdir('ncss-cookbooks-') do |dir|
36
+ puts "Creating directory #{dir}/cookbooks/"
34
37
  FileUtils.mkdir_p("#{dir}/cookbooks/")
35
- FileUtils.cp_r(Dir["#{pwd}/*"], "#{dir}/cookbooks/")
36
38
 
39
+ puts "Copying files from #{@pwd} to #{dir}/cookbooks/"
40
+ FileUtils.cp_r(pwd_files, "#{dir}/cookbooks/")
41
+
42
+ puts "Archiving #{dir}/cookbooks/ to #{dir}/cookbooks.tgz"
37
43
  FileUtils.cd(dir)
38
44
  cookbooks_tgz = Zlib::GzipWriter.new(File.open("cookbooks.tgz", "wb"))
39
45
  Archive::Tar::Minitar.pack('cookbooks', cookbooks_tgz)
40
46
 
47
+ if options[:verbose]
48
+ puts "Archive includes:"
49
+ system "tar tzvf cookbooks.tgz"
50
+ end
51
+
52
+ puts "Uploading #{dir}/cookbooks.tgz to bucket:#{bucket_name}, object:#{object.key}"
41
53
  object.write(:file => "cookbooks.tgz")
42
54
  object.acl = :public_read
55
+
56
+ puts "Temporary directory #{dir} will be deleted automatically"
43
57
  end
44
58
 
45
- puts object.url_for(:read).to_s.gsub(/\?(.+)$/, '')
59
+ puts "Uploaded to " + object.url_for(:read).to_s.gsub(/\?(.+)$/, '')
46
60
  end
47
61
 
48
62
  private
@@ -55,4 +69,16 @@ class NcssCookbooks < Thor
55
69
  :s3_endpoint => 'ncss.nifty.com'
56
70
  )
57
71
  end
72
+
73
+ def pwd_files
74
+ files = Dir["{#{@pwd}/*,#{@pwd}/.*}"]
75
+ files.reject do |file|
76
+ if FileTest.directory?(file) && %w(.git .svn).include?(File.basename(file))
77
+ puts " Excluded #{file}"
78
+ true
79
+ elsif %w(. ..).include?(File.basename(file))
80
+ true
81
+ end
82
+ end
83
+ end
58
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ncss-cookbooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-18 00:00:00.000000000Z
12
+ date: 2013-05-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &160602060 !ruby/object:Gem::Requirement
16
+ requirement: &224772700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *160602060
24
+ version_requirements: *224772700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: highline
27
- requirement: &160579040 !ruby/object:Gem::Requirement
27
+ requirement: &224769760 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *160579040
35
+ version_requirements: *224769760
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: aws-sdk
38
- requirement: &160577700 !ruby/object:Gem::Requirement
38
+ requirement: &224768820 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *160577700
46
+ version_requirements: *224768820
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: archive-tar-minitar
49
- requirement: &160576760 !ruby/object:Gem::Requirement
49
+ requirement: &224767080 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *160576760
57
+ version_requirements: *224767080
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &160575620 !ruby/object:Gem::Requirement
60
+ requirement: &224751260 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 2.8.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *160575620
68
+ version_requirements: *224751260
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdoc
71
- requirement: &160574580 !ruby/object:Gem::Requirement
71
+ requirement: &224748660 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '3.12'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *160574580
79
+ version_requirements: *224748660
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: jeweler
82
- requirement: &160572900 !ruby/object:Gem::Requirement
82
+ requirement: &224745580 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: 1.8.4
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *160572900
90
+ version_requirements: *224745580
91
91
  description: Chef の Cookbooks を一発で NIFTYCloud クラウドストレージにアップロードするコマンド
92
92
  email: tily05@gmail.com
93
93
  executables:
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  segments:
128
128
  - 0
129
- hash: 3173881512082075132
129
+ hash: -2339505270493421964
130
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  none: false
132
132
  requirements: