mamiya 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2fb2fdd6a1a46565922f01ce57b1a8e60f0adb2
4
- data.tar.gz: 902cdbccfb4320195e837dcb2d3f2f45d9a40c05
3
+ metadata.gz: a268bd1aef679e677567701786e0bfb1232f9750
4
+ data.tar.gz: 54a40fd2fa7dfb7b5e2c75d24b6fb05781a9374e
5
5
  SHA512:
6
- metadata.gz: bc4305e19a32b06dbd9c3bf3c4ce35d231ae85251ab3754f267d8fd33251285fea4cd7b76c4127f3298360860228a7d3c66da6704ce444cc5f97f78a785a85ae
7
- data.tar.gz: a83dee125f7bac4f5af2efba42a36675c1fde2193cfaee8fa5d18a3c44518b7be9a3ef5ddee4d978345bb75e5e4aa85ef6bf62da2eb70cb07e9ff34e2aac13c7
6
+ metadata.gz: 79c8920e28d2ed4a3f3169507fdde0f29ef499039a031a277bde5e527e662644be695f9b0eaa3841ae189e51cfa7fd0907d4601c9d8cc15eacb06ca863ff3c93
7
+ data.tar.gz: bab3ba643a76b6aefc0c57dea36090e9c3157724df98019b5f9b7bf70152c19c9db7f069f9629521592801a0d51d9907aad6b51117eeb1cc4b86d5b5542f3fc8
@@ -1,5 +1,12 @@
1
1
  require "mamiya/version"
2
+ require 'thread'
2
3
 
3
4
  module Mamiya
4
- # Your code goes here...
5
+
6
+ @chdir_monitor = Monitor.new
7
+ def self.chdir(dir, &block)
8
+ @chdir_monitor.synchronize do
9
+ Dir.chdir(dir, &block)
10
+ end
11
+ end
5
12
  end
@@ -1,4 +1,5 @@
1
1
  require 'time'
2
+ require 'mamiya'
2
3
 
3
4
  set_default :git_remote, 'origin'
4
5
  set_default :commit, "#{self.git_remote}/HEAD"
@@ -48,7 +49,7 @@ prepare_build do |update|
48
49
  run "git", "clone", self.repository, self.build_from
49
50
  end
50
51
 
51
- Dir.chdir(self.build_from) do
52
+ Mamiya.chdir(self.build_from) do
52
53
  logger.info Dir.pwd
53
54
  run "git", "fetch", self.git_remote
54
55
  run "git", "remote", "prune", self.git_remote, allow_failure: true
@@ -81,7 +82,7 @@ end
81
82
  options[:manage_script] = true unless options.key?(:manage_script)
82
83
  options[:script_auto_additionals] = true unless options.key?(:script_auto_additionals)
83
84
  if options[:manage_script] && _file
84
- Dir.chdir(File.dirname(_file)) do
85
+ Mamiya.chdir(File.dirname(_file)) do
85
86
  break unless git_managed?
86
87
 
87
88
  script_git_head = git_head()
@@ -1,3 +1,4 @@
1
+ require 'mamiya'
1
2
  require 'mamiya/logger'
2
3
 
3
4
  require 'pathname'
@@ -76,7 +77,7 @@ module Mamiya
76
77
  meta['name'] = self.name
77
78
  File.write meta_in_build, self.meta.to_json
78
79
 
79
- Dir.chdir(build_dir) do
80
+ Mamiya.chdir(build_dir) do
80
81
  excludes = exclude_from_package.flat_map { |exclude| ['--exclude', exclude] }
81
82
  dereference = dereference_symlinks ? ['-h'] : []
82
83
 
@@ -90,7 +90,7 @@ module Mamiya
90
90
  l = logger['timekeeper']
91
91
  loop do
92
92
  if 90 < (Time.now - last_out)
93
- l.warn "pid #! {pid} still running; since #{started_at}"
93
+ l.warn "! pid #{pid} still running; since #{started_at}"
94
94
  end
95
95
  sleep 60
96
96
  end
@@ -135,6 +135,7 @@ module Mamiya
135
135
 
136
136
  def cd(*args)
137
137
  logger.info "$ cd #{args[0]}"
138
+ # FIXME: This could make conflict with other threads
138
139
  Dir.chdir *args
139
140
  end
140
141
 
@@ -1,3 +1,4 @@
1
+ require 'mamiya'
1
2
  require 'mamiya/steps/abstract'
2
3
  require 'mamiya/package'
3
4
 
@@ -72,15 +73,12 @@ module Mamiya
72
73
  end
73
74
 
74
75
  def run_build
75
- old_pwd = Dir.pwd
76
- begin
77
- # Using without block because chdir in block shows warning
78
- Dir.chdir(script.build_from)
76
+ # FIXME: This could show warning saying "conflicting chdir during another chdir block".
77
+ # Do not use `Dir.chdir` without block anyware.
78
+ Mamiya.chdir(script.build_from) do
79
79
  logger.info "Running script.build"
80
80
  logger.debug "pwd=#{Dir.pwd}"
81
81
  script.build[]
82
- ensure
83
- Dir.chdir old_pwd
84
82
  end
85
83
  end
86
84
 
@@ -112,7 +110,7 @@ module Mamiya
112
110
  def set_metadata
113
111
  package.meta[:application] = script.application
114
112
  package.meta[:script] = File.basename(script_file)
115
- Dir.chdir(script.build_from) do
113
+ Mamiya.chdir(script.build_from) do
116
114
  package.meta.replace script.package_meta[package.meta]
117
115
  end
118
116
  end
@@ -130,7 +128,7 @@ module Mamiya
130
128
  def package_name
131
129
  @package_name ||= begin
132
130
  logger.debug "Determining package name..."
133
- name = Dir.chdir(script.build_from) {
131
+ name = Mamiya.chdir(script.build_from) {
134
132
  script.package_name[
135
133
  [Time.now.strftime("%Y%m%d%H%M%S"), script.application]
136
134
  ].join('-')
@@ -1,3 +1,4 @@
1
+ require 'mamiya'
1
2
  require 'mamiya/steps/abstract'
2
3
 
3
4
  require 'pathname'
@@ -8,20 +9,18 @@ module Mamiya
8
9
  class Prepare < Abstract
9
10
  def run!
10
11
  @exception = nil
11
- old_pwd = Dir.pwd
12
- Dir.chdir(target)
12
+ Mamiya.chdir(target) do
13
+ logger.info "Preparing #{target}..."
13
14
 
14
- logger.info "Preparing #{target}..."
15
+ script.before_prepare(labels)[]
16
+ script.prepare(labels)[]
15
17
 
16
- script.before_prepare(labels)[]
17
- script.prepare(labels)[]
18
-
19
- File.write target.join('.mamiya.prepared'), "#{Time.now.to_i}\n"
18
+ File.write target.join('.mamiya.prepared'), "#{Time.now.to_i}\n"
19
+ end
20
20
  rescue Exception => e
21
21
  @exception = e
22
22
  raise e
23
23
  ensure
24
- Dir.chdir old_pwd if old_pwd
25
24
  logger.warn "Exception occured, cleaning up..." if @exception
26
25
 
27
26
  script.after_prepare(labels)[@exception]
@@ -1,3 +1,4 @@
1
+ require 'mamiya'
1
2
  require 'mamiya/steps/abstract'
2
3
 
3
4
  module Mamiya
@@ -44,14 +45,11 @@ module Mamiya
44
45
  # TODO: link with relative if available?
45
46
  # TODO: Restore this if FAILED
46
47
 
47
- old_pwd = Dir.pwd
48
- Dir.chdir(target)
48
+ Mamiya.chdir(target) do
49
+ logger.info "Releasing..."
49
50
 
50
- logger.info "Releasing..."
51
-
52
- script.release(labels)[@exception]
53
- ensure
54
- Dir.chdir old_pwd if old_pwd
51
+ script.release(labels)[@exception]
52
+ end
55
53
  end
56
54
 
57
55
  # XXX: dupe with prepare step. modulize?
@@ -1,6 +1,7 @@
1
1
  require 'mamiya/package'
2
2
  require 'mamiya/storages/abstract'
3
3
  require 'aws-sdk-core'
4
+ require 'fileutils'
4
5
  require 'json'
5
6
 
6
7
  module Mamiya
@@ -64,12 +65,16 @@ module Mamiya
64
65
  raise AlreadyFetched
65
66
  end
66
67
 
67
- open(package_path, 'wb+') do |io|
68
+ tmp_package_path = "#{package_path}.progress"
69
+ tmp_meta_path = "#{meta_path}.progress"
70
+ open(tmp_package_path, 'wb+') do |io|
68
71
  s3.get_object({bucket: @config[:bucket], key: package_key}, target: io)
69
72
  end
70
- open(meta_path, 'wb+') do |io|
73
+ open(tmp_meta_path, 'wb+') do |io|
71
74
  s3.get_object({bucket: @config[:bucket], key: meta_key}, target: io)
72
75
  end
76
+ FileUtils.mv(tmp_package_path, package_path)
77
+ FileUtils.mv(tmp_meta_path, meta_path)
73
78
 
74
79
  return Mamiya::Package.new(package_path)
75
80
 
@@ -1,5 +1,6 @@
1
1
  require 'mamiya/package'
2
2
  require 'mamiya/storages/s3'
3
+ require 'fileutils'
3
4
 
4
5
  module Mamiya
5
6
  module Storages
@@ -22,12 +23,16 @@ module Mamiya
22
23
  raise AlreadyFetched
23
24
  end
24
25
 
25
- open(package_path, 'wb+') do |io|
26
+ tmp_package_path = "#{package_path}.progress"
27
+ tmp_meta_path = "#{meta_path}.progress"
28
+ open(tmp_package_path, 'wb+') do |io|
26
29
  proxy_get(package_key, io)
27
30
  end
28
- open(meta_path, 'wb+') do |io|
31
+ open(tmp_meta_path, 'wb+') do |io|
29
32
  proxy_get(meta_key, io)
30
33
  end
34
+ FileUtils.mv(tmp_package_path, package_path)
35
+ FileUtils.mv(tmp_meta_path, meta_path)
31
36
 
32
37
  return Mamiya::Package.new(package_path)
33
38
 
@@ -1,3 +1,3 @@
1
1
  module Mamiya
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -124,18 +124,18 @@ describe Mamiya::Storages::S3 do
124
124
  expect(options[:bucket]).to eq 'testbucket'
125
125
  expect(options[:key]).to eq "myapp/test.tar.gz"
126
126
  expect(send_options[:target]).to be_a_kind_of(File)
127
- expect(send_options[:target].path).to eq tarball
127
+ expect(send_options[:target].path).to eq("#{tarball}.progress")
128
128
 
129
129
  options, send_options = requests.shift
130
130
  expect(options[:bucket]).to eq 'testbucket'
131
131
  expect(options[:key]).to eq "myapp/test.json"
132
132
  expect(send_options[:target]).to be_a_kind_of(File)
133
- expect(send_options[:target].path).to eq metafile
133
+ expect(send_options[:target].path).to eq("#{metafile}.progress")
134
134
  end
135
135
 
136
136
  it "returns Mamiya::Package" do
137
137
  allow(s3).to receive(:get_object) do
138
- File.write metafile, "{}\n"
138
+ File.write "#{metafile}.progress", "{}\n"
139
139
  end
140
140
 
141
141
  expect(fetch).to be_a_kind_of(Mamiya::Package)
@@ -184,7 +184,7 @@ describe Mamiya::Storages::S3 do
184
184
  hash_including(bucket: 'testbucket', key: 'myapp/test.tar.gz'), hash_including(target: an_instance_of(File)))
185
185
  expect(s3).to receive(:get_object).with(
186
186
  hash_including(bucket: 'testbucket', key: 'myapp/test.json'), hash_including(target: an_instance_of(File))) do
187
- File.write metafile, "{}\n"
187
+ File.write "#{metafile}.progress", "{}\n"
188
188
  end
189
189
 
190
190
  fetch
@@ -199,7 +199,7 @@ describe Mamiya::Storages::S3 do
199
199
  hash_including(bucket: 'testbucket', key: 'myapp/test.tar.gz'), hash_including(target: an_instance_of(File)))
200
200
  expect(s3).to receive(:get_object).with(
201
201
  hash_including(bucket: 'testbucket', key: 'myapp/test.json'), hash_including(target: an_instance_of(File))) do
202
- File.write metafile, "{}\n"
202
+ File.write "#{metafile}.progress", "{}\n"
203
203
  end
204
204
 
205
205
  fetch
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mamiya
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shota Fukumori (sora_h)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-30 00:00:00.000000000 Z
11
+ date: 2016-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor