Class: KubeDeployTools::ImageRegistry::Driver::Aws
Instance Method Summary
collapse
#check_and_err, #check_and_warn, #load_library
Methods inherited from Base
#authorize, #unauthorize_command
Constructor Details
#initialize(h) ⇒ Aws
Returns a new instance of Aws.
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/kube_deploy_tools/image_registry/driver/aws.rb', line 12
def initialize(h)
super(h)
check_and_err(
@registry.config&.has_key?('region'),
"Expected .image_registries['#{@name}'] to have .config.region to be set "\
"for the AWS image registry driver, but .config.region is not set "\
"e.g. .config.region = 'us-west-2'"
)
end
|
Instance Method Details
#authorize_command ⇒ Object
28
29
30
31
32
|
# File 'lib/kube_deploy_tools/image_registry/driver/aws.rb', line 28
def authorize_command
login_cmd = get_docker_login
raise "Unexpected login command: #{login_cmd}" if login_cmd.first(2) != ['docker', 'login']
login_cmd
end
|
#delete_image(image, dryrun) ⇒ Object
37
38
39
40
|
# File 'lib/kube_deploy_tools/image_registry/driver/aws.rb', line 37
def delete_image(image, dryrun)
delete_images([image], dryrun)
end
|
#delete_images(images, dryrun) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/kube_deploy_tools/image_registry/driver/aws.rb', line 42
def delete_images(images, dryrun)
ids_by_repository = {}
images.each do |image|
repository, tag = split_full_image_id(image)
item = {'imageTag': tag}
if ids_by_repository[repository].nil?
ids_by_repository[repository] = [item]
else
ids_by_repository[repository].push(item)
end
end
ids_by_repository.each do |repository, image_ids|
image_chunks = image_ids.each_slice(100).to_a
image_chunks.each do |images|
cmd = [
'aws', 'ecr', 'batch-delete-image',
'--repository-name', repository,
'--region', @registry.config.fetch('region'),
'--image-ids', images.to_json,
]
if dryrun
Logger.info("Would run: #{cmd}")
else
Shellrunner.check_call(*cmd)
end
end
end
end
|
#push_image(image) ⇒ Object
23
24
25
26
|
# File 'lib/kube_deploy_tools/image_registry/driver/aws.rb', line 23
def push_image(image)
create_repository(image.repository) unless repository_exists?(image.repository)
super(image)
end
|
#unauthorize ⇒ Object
34
35
|
# File 'lib/kube_deploy_tools/image_registry/driver/aws.rb', line 34
def unauthorize
end
|