capistrano-s3_archive 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/capistrano/s3_archive.rb +66 -23
- data/lib/capistrano/s3_archive/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 270d0445f78fdccee13f4d069148a4c73fef1dd0
|
4
|
+
data.tar.gz: 269e6176739259c329cd6c401ddc3326b6625317
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 150b7fea2b9bf4fe5c51a61d567252792c7435e7a0537a390c496bf9f4c6ea959286925e2b0f1a6942e35dba28b6b294dc84f19e976aa4626459e583e233ac81
|
7
|
+
data.tar.gz: d8978b666b74a52d118f60323b427f282dde0332615b7c80c7b875d7e67c8a1a224da98144b99ef6d95e09aa5b2017da830343635b665c4fea89066430bc94df
|
@@ -65,35 +65,47 @@ module Capistrano
|
|
65
65
|
### Default strategy
|
66
66
|
private
|
67
67
|
module RsyncStrategy
|
68
|
+
class MissingSSHKyesError < StandardError; end
|
69
|
+
class ResourceBusyError < StandardError; end
|
70
|
+
|
68
71
|
def check
|
69
72
|
list_objects(false)
|
73
|
+
ssh_key = context.host.keys.first || Array(context.host.ssh_options[:keys]).first
|
74
|
+
if ssh_key.nil?
|
75
|
+
fail MissingSSHKyesError, "#{RsyncStrategy} only supports publickey authentication. Please set #{context.host.hostname}.keys or ssh_options."
|
76
|
+
end
|
70
77
|
end
|
71
78
|
|
72
79
|
def stage
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
File.
|
78
|
-
|
80
|
+
stage_lock do
|
81
|
+
archive_file = File.join(fetch(:s3_archive), fetch(:stage).to_s, File.basename(archive_object_key))
|
82
|
+
tmp_file = "#{archive_file}.part"
|
83
|
+
fail "#{tmp_file} is found. Another process is running?" if File.exist?(tmp_file)
|
84
|
+
if not File.exist?(archive_file)
|
85
|
+
File.open(tmp_file, 'w') do |f|
|
86
|
+
mkdir_p(File.dirname(archive_file))
|
87
|
+
content = get_object.body.read
|
88
|
+
f.write(content)
|
89
|
+
end
|
90
|
+
move(tmp_file, archive_file)
|
91
|
+
else
|
92
|
+
context.info "#{archive_file} is found."
|
79
93
|
end
|
80
|
-
else
|
81
|
-
context.info "#{archive_file} is found."
|
82
|
-
end
|
83
94
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
cmd = "tar xf #{archive_file} -C #{fetch(:local_cache_dir)}"
|
93
|
-
end
|
95
|
+
remove_entry_secure(fetch(:local_cache_dir)) if File.exist? fetch(:local_cache_dir)
|
96
|
+
mkdir_p(fetch(:local_cache_dir))
|
97
|
+
case archive_file
|
98
|
+
when /\.zip\Z/
|
99
|
+
cmd = "unzip -q -d #{fetch(:local_cache_dir)} #{archive_file}"
|
100
|
+
when /\.tar\.gz\Z|\.tar\.bz2\Z/
|
101
|
+
cmd = "tar xf #{archive_file} -C #{fetch(:local_cache_dir)}"
|
102
|
+
end
|
94
103
|
|
95
|
-
|
96
|
-
|
104
|
+
release_lock(true) do
|
105
|
+
run_locally do
|
106
|
+
execute cmd
|
107
|
+
end
|
108
|
+
end
|
97
109
|
end
|
98
110
|
end
|
99
111
|
|
@@ -108,8 +120,10 @@ module Capistrano
|
|
108
120
|
rsync << "-e 'ssh -i #{key} #{ssh_port_option}'"
|
109
121
|
rsync << "#{user}#{server.hostname}:#{rsync_cache || release_path}"
|
110
122
|
|
111
|
-
|
112
|
-
|
123
|
+
release_lock do
|
124
|
+
run_locally do
|
125
|
+
execute *rsync
|
126
|
+
end
|
113
127
|
end
|
114
128
|
|
115
129
|
unless fetch(:rsync_cache).nil?
|
@@ -131,6 +145,35 @@ module Capistrano
|
|
131
145
|
cache = deploy_to + "/" + cache if cache && cache !~ /^\//
|
132
146
|
cache
|
133
147
|
end
|
148
|
+
|
149
|
+
def stage_lock(&block)
|
150
|
+
lockfile = "#{fetch(:local_cache)}.#{fetch(:stage)}.lock"
|
151
|
+
File.open(lockfile, "w") do |f|
|
152
|
+
if f.flock(File::LOCK_EX | File::LOCK_NB)
|
153
|
+
block.call
|
154
|
+
else
|
155
|
+
fail ResourceBusyError, "Could not get #{lockfile}"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
ensure
|
159
|
+
rm lockfile if File.exist? lockfile
|
160
|
+
end
|
161
|
+
|
162
|
+
def release_lock(exclusive = false, &block)
|
163
|
+
lockfile = "#{fetch(:local_cache)}.#{fetch(:stage)}.release.lock"
|
164
|
+
File.open(lockfile, File::RDONLY|File::CREAT) do |f|
|
165
|
+
mode = if exclusive
|
166
|
+
File::LOCK_EX | File::LOCK_NB
|
167
|
+
else
|
168
|
+
File::LOCK_SH
|
169
|
+
end
|
170
|
+
if f.flock(mode)
|
171
|
+
block.call
|
172
|
+
else
|
173
|
+
fail ResourceBusyError, "Could not get #{fetch(:lockfile)}"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
134
177
|
end
|
135
178
|
end
|
136
179
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-s3_archive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takuto Komazaki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|