deb-s3-lock-fix 0.11.8.fix6 → 0.11.8.fix8
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/README.md +12 -2
- data/lib/deb/s3/cli.rb +14 -10
- data/lib/deb/s3/lock.rb +8 -11
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a7f40985258d5212ac5f40cf777e3c18ead8e1f73768444462a14f4b04727fe
|
4
|
+
data.tar.gz: d90d94de2da1ffab4439347e2f9fbe964b41b0663f58b509c110a71a91f32878
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dffaadf897accef8d6427768d393d543959843531bd2e2ce7756243580b3c6793cb917bf1f78eed47e2314ac03bc640e89b7cd252c9380aea2e258224e293d1
|
7
|
+
data.tar.gz: 749f27fca151c95688da92a2b7ed3686bb59df8c6118120c80ae385987091224c6bf0e00a8f3b49defd1ed4b56b1c920756b567e4676832f6cfe54bae6fbf814
|
data/README.md
CHANGED
@@ -1,8 +1,18 @@
|
|
1
|
-
# deb-s3
|
1
|
+
# deb-s3-lock-fix
|
2
2
|
|
3
3
|
[](https://travis-ci.org/deb-s3/deb-s3)
|
4
4
|
|
5
|
-
**This repository is a fork of [
|
5
|
+
**This repository is a fork of [deb-s3](https://github.com/deb-s3/deb-s3).**
|
6
|
+
|
7
|
+
Note: The locking mechanism in the original deb-s3 library does not prevent race conditions.
|
8
|
+
It relies on S3 for distributed locking, which will not work consistently due to S3's eventual
|
9
|
+
consistency model. This fork uses DynamoDB for distributed locking, since it ensures atomic
|
10
|
+
conditional put operations on the lock.
|
11
|
+
|
12
|
+
To use this library create a DynamoDB table and export the following three env variables:
|
13
|
+
`DEB_S3_LOCK_ACCESS_KEY_ID`
|
14
|
+
`DEB_S3_LOCK_SECRET_ACCESS_KEY`
|
15
|
+
`AWS_BUILDERS_REGION`
|
6
16
|
|
7
17
|
`deb-s3` is a simple utility to make creating and managing APT repositories on
|
8
18
|
S3.
|
data/lib/deb/s3/cli.rb
CHANGED
@@ -165,7 +165,7 @@ class Deb::S3::CLI < Thor
|
|
165
165
|
if options[:lock]
|
166
166
|
log("Checking for existing lock file")
|
167
167
|
log("Locking repository for updates")
|
168
|
-
Deb::S3::Lock.lock(options[:codename])
|
168
|
+
Deb::S3::Lock.lock(options[:bucket], options[:codename])
|
169
169
|
@lock_acquired = true
|
170
170
|
end
|
171
171
|
|
@@ -242,18 +242,22 @@ class Deb::S3::CLI < Thor
|
|
242
242
|
log("Uploading packages and new manifests to S3")
|
243
243
|
manifests.each_value do |manifest|
|
244
244
|
begin
|
245
|
-
manifest.write_to_s3
|
245
|
+
manifest.write_to_s3 do |f|
|
246
|
+
sublog("Transferring #{f} at #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}")
|
247
|
+
end
|
246
248
|
rescue Deb::S3::Utils::AlreadyExistsError => e
|
247
249
|
error("Uploading manifest failed because: #{e}")
|
248
250
|
end
|
249
251
|
release.update_manifest(manifest)
|
250
252
|
end
|
251
|
-
release.write_to_s3
|
253
|
+
release.write_to_s3 do |f|
|
254
|
+
sublog("Transferring #{f} at #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}")
|
255
|
+
end
|
252
256
|
|
253
257
|
log("Update complete.")
|
254
258
|
ensure
|
255
259
|
if options[:lock] && @lock_acquired
|
256
|
-
Deb::S3::Lock.unlock(options[:codename])
|
260
|
+
Deb::S3::Lock.unlock(options[:bucket], options[:codename])
|
257
261
|
log("Lock released.")
|
258
262
|
end
|
259
263
|
end
|
@@ -402,7 +406,7 @@ class Deb::S3::CLI < Thor
|
|
402
406
|
if options[:lock]
|
403
407
|
log("Checking for existing lock file")
|
404
408
|
log("Locking repository for updates")
|
405
|
-
Deb::S3::Lock.lock(options[:codename])
|
409
|
+
Deb::S3::Lock.lock(options[:bucket], options[:codename])
|
406
410
|
@lock_acquired = true
|
407
411
|
end
|
408
412
|
|
@@ -444,7 +448,7 @@ class Deb::S3::CLI < Thor
|
|
444
448
|
log "Copy complete."
|
445
449
|
ensure
|
446
450
|
if options[:lock] && @lock_acquired
|
447
|
-
Deb::S3::Lock.unlock(options[:codename])
|
451
|
+
Deb::S3::Lock.unlock(options[:bucket], options[:codename])
|
448
452
|
log("Lock released.")
|
449
453
|
end
|
450
454
|
end
|
@@ -497,7 +501,7 @@ class Deb::S3::CLI < Thor
|
|
497
501
|
if options[:lock]
|
498
502
|
log("Checking for existing lock file")
|
499
503
|
log("Locking repository for updates")
|
500
|
-
Deb::S3::Lock.lock(options[:codename])
|
504
|
+
Deb::S3::Lock.lock(options[:bucket], options[:codename])
|
501
505
|
@lock_acquired = true
|
502
506
|
end
|
503
507
|
|
@@ -545,7 +549,7 @@ class Deb::S3::CLI < Thor
|
|
545
549
|
end
|
546
550
|
ensure
|
547
551
|
if options[:lock] && @lock_acquired
|
548
|
-
Deb::S3::Lock.unlock(options[:codename])
|
552
|
+
Deb::S3::Lock.unlock(options[:bucket], options[:codename])
|
549
553
|
log("Lock released.")
|
550
554
|
end
|
551
555
|
end
|
@@ -611,7 +615,7 @@ class Deb::S3::CLI < Thor
|
|
611
615
|
if options[:lock]
|
612
616
|
log("Checking for existing lock file")
|
613
617
|
log("Locking repository for updates")
|
614
|
-
Deb::S3::Lock.lock(options[:codename])
|
618
|
+
Deb::S3::Lock.lock(options[:bucket], options[:codename])
|
615
619
|
@lock_acquired = true
|
616
620
|
end
|
617
621
|
|
@@ -675,7 +679,7 @@ class Deb::S3::CLI < Thor
|
|
675
679
|
end
|
676
680
|
ensure
|
677
681
|
if options[:lock] && @lock_acquired
|
678
|
-
Deb::S3::Lock.unlock(options[:codename])
|
682
|
+
Deb::S3::Lock.unlock(options[:bucket], options[:codename])
|
679
683
|
log("Lock released.")
|
680
684
|
end
|
681
685
|
end
|
data/lib/deb/s3/lock.rb
CHANGED
@@ -30,10 +30,10 @@ class Deb::S3::Lock
|
|
30
30
|
end
|
31
31
|
|
32
32
|
class << self
|
33
|
-
def lock(codename, max_attempts = 60, max_wait_interval = 10)
|
33
|
+
def lock(bucket, codename, max_attempts = 60, max_wait_interval = 10)
|
34
34
|
uuid = SecureRandom.uuid
|
35
35
|
lock_body = "#{Etc.getlogin}@#{Socket.gethostname}-#{uuid}"
|
36
|
-
lock_key = codename
|
36
|
+
lock_key = "#{bucket}/#{codename}"
|
37
37
|
|
38
38
|
$stderr.puts("Current job's hostname with UUID: #{lock_body}")
|
39
39
|
|
@@ -51,34 +51,31 @@ class Deb::S3::Lock
|
|
51
51
|
})
|
52
52
|
return
|
53
53
|
rescue Aws::DynamoDB::Errors::ConditionalCheckFailedException
|
54
|
-
lock_holder = current_lock_holder(codename)
|
54
|
+
lock_holder = current_lock_holder(bucket, codename)
|
55
55
|
current_time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
56
56
|
$stderr.puts("[#{current_time}] Repository is locked by another user: #{lock_holder.user} at host #{lock_holder.host_with_uuid}")
|
57
57
|
$stderr.puts("Attempting to obtain a lock after #{wait_interval} second(s).")
|
58
58
|
sleep(wait_interval)
|
59
|
-
rescue => e
|
60
|
-
$stderr.puts("Unexpected error: #{e.message}")
|
61
|
-
sleep(wait_interval)
|
62
59
|
end
|
63
60
|
end
|
64
61
|
|
65
|
-
raise "Unable to obtain a lock after #{max_attempts}, giving up."
|
62
|
+
raise "Unable to obtain a lock after #{max_attempts} attemtps, giving up."
|
66
63
|
end
|
67
64
|
|
68
|
-
def unlock(codename)
|
65
|
+
def unlock(bucket, codename)
|
69
66
|
dynamodb.delete_item({
|
70
67
|
table_name: DYNAMODB_TABLE_NAME,
|
71
68
|
key: {
|
72
|
-
'lock_key' => codename
|
69
|
+
'lock_key' => "#{bucket}/#{codename}"
|
73
70
|
}
|
74
71
|
})
|
75
72
|
end
|
76
73
|
|
77
|
-
def current_lock_holder(codename)
|
74
|
+
def current_lock_holder(bucket, codename)
|
78
75
|
response = dynamodb.get_item({
|
79
76
|
table_name: DYNAMODB_TABLE_NAME,
|
80
77
|
key: {
|
81
|
-
'lock_key' => codename
|
78
|
+
'lock_key' => "#{bucket}/#{codename}"
|
82
79
|
}
|
83
80
|
})
|
84
81
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deb-s3-lock-fix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.8.
|
4
|
+
version: 0.11.8.fix8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Braeden Wolf & Ken Robertson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -82,7 +82,7 @@ dependencies:
|
|
82
82
|
version: '11'
|
83
83
|
description: Fork of deb-s3 with a specific fix for locking. Original work by Ken
|
84
84
|
Robertson.
|
85
|
-
email:
|
85
|
+
email: braeden.wolf@sanctuary.ai & ken@invalidlogic.com
|
86
86
|
executables:
|
87
87
|
- deb-s3
|
88
88
|
extensions: []
|
@@ -99,7 +99,7 @@ files:
|
|
99
99
|
- lib/deb/s3/templates/package.erb
|
100
100
|
- lib/deb/s3/templates/release.erb
|
101
101
|
- lib/deb/s3/utils.rb
|
102
|
-
homepage: https://
|
102
|
+
homepage: https://gitlab.com/sanctuaryai/precog2/infrastructure/deb-s3-lock-fix
|
103
103
|
licenses:
|
104
104
|
- MIT
|
105
105
|
metadata: {}
|