awsclean 1.0 → 1.1

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
- SHA1:
3
- metadata.gz: e3cecacbeb7d9e801bc4b3571f6958bdbc9110f7
4
- data.tar.gz: 3c0c1d0c23b1dd948e6660803eddc0f7d50d32ce
2
+ SHA256:
3
+ metadata.gz: 85e8e88ab01e03117ce712c5c67f0ad5abd3f9f1b34af56532ec41e2fb96f906
4
+ data.tar.gz: e0799e7ba427ef13dbab6353eee09ba2908acd3cdf6de9a923692969e6d1e26a
5
5
  SHA512:
6
- metadata.gz: e7708fc702c34508450fa3d88b90de7e75e1009d951354f14b40ecf747de5e5f9ebdc95beacd20bdb4a8d42aed427169a4ad566c68ec5bf4ff42b25ccfc7e74b
7
- data.tar.gz: 02ca4a17b82529c5677f5c4f3facb732400c661fa78d4e76aceae890753865cb95836eb3c5e69e8c4a0bd4fcd739fa56fb059e742d462a486047884b8694508b
6
+ metadata.gz: f88083fa73bf4e057983a520a57c1e314813bf7d7e990389ca3f94fb769bd79eb327ce5ec8311853975ec2206d65e04e3a5c2d5e4d1b7b49057c95f12a423c33
7
+ data.tar.gz: 898f34a86760599b8ce5fca81c1bac04181619527cbd2307823ce90a503e4ed10c4efba24b3170fd8b8f553f0923edd5cdca9072e5ee4382d80e4b687005e9e5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- awsclean (1.0)
4
+ awsclean (1.1)
5
5
  aws-sdk (~> 2.7.4)
6
6
  bundler (~> 1.14)
7
7
  pry
@@ -70,4 +70,4 @@ RUBY VERSION
70
70
  ruby 2.3.3p222
71
71
 
72
72
  BUNDLED WITH
73
- 1.15.1
73
+ 1.17.1
data/README.md CHANGED
@@ -34,7 +34,7 @@ Locates and deletes stale docker images stored in Amazon ECR.
34
34
  An ECR image is considered stale when:
35
35
 
36
36
  1. It was created over `--e` days ago (default: 60).
37
- 2. It's not being used by any ECS active task definition.
37
+ 2. It was untagged.
38
38
 
39
39
  #### Listing images eligible for cleanup:
40
40
 
@@ -45,7 +45,7 @@ $ awsclean clean_ecr_images
45
45
  ```
46
46
  [clean_ecr_images] Checking region: us-east-2
47
47
  REGION IN USE? REPOSITORY URI TAGS IMAGE ID CREATED SIZE ELEGIBLE FOR CLEANUP?
48
- us-east-2 true 3333344444.dkr.ecr.us-east-2.amazonaws.com/foobar baz sha256:464ea4713d51 2017-04-05T21:00:45+00:00 (100 days ago) 184.0 MB false
48
+ us-east-2 false 3333344444.dkr.ecr.us-east-2.amazonaws.com/foobar (!TAG) sha256:464ea4713d51 2017-04-05T21:00:45+00:00 (100 days ago) 184.0 MB true
49
49
  us-east-2 true 3333344444.dkr.ecr.us-east-2.amazonaws.com/foobar latest sha256:464ea4713d51 2017-04-05T21:00:45+00:00 (100 days ago) 184.0 MB false
50
50
  us-east-2 false 3333344444.dkr.ecr.us-east-2.amazonaws.com/foobar_v2 (!TAG) sha256:f47d0c6acbe9 2017-06-22T22:55:44+00:00 (21 days ago) 136.0 MB false
51
51
  us-east-2 false 3333344444.dkr.ecr.us-east-2.amazonaws.com/foobar_v2 latest sha256:58e584fd7654 2017-06-23T16:13:22+00:00 (21 days ago) 15.0 MB false
@@ -71,6 +71,7 @@ The following flags are available to use in both commands:
71
71
  * `--c`: delete images marked as eligible for cleanup. (default: false)
72
72
  * `--e`: images older than `--e` days are considered old. (default: 60)
73
73
  * `--r`: select which AWS regions to perform on. (default: all)
74
+ * `--a`: specify AMIs will not be deleted. (default: [])
74
75
 
75
76
  The `--r` flag accepts a space separated list of region names.
76
77
 
@@ -78,6 +79,12 @@ The `--r` flag accepts a space separated list of region names.
78
79
  $ awsclean clean_amis -r us-east-2 ca-central-1
79
80
  ```
80
81
 
82
+ The `--a` flag accepts a space separated list of AMI IDs.
83
+
84
+ ```
85
+ $ awsclean clean_amis -a ami-xxxxxx ami-yyyyyy
86
+ ```
87
+
81
88
  ## Development
82
89
  After checking out the repo, run `bin/setup` to install dependencies.
83
90
 
@@ -6,8 +6,8 @@ module Awsclean
6
6
 
7
7
  SERVICE_IDENTIFIER = "EC2"
8
8
 
9
- IMAGE_LIST_HEADER = ['REGION', 'IN USE?', 'AMI ID', 'CREATED', 'ELEGIBLE FOR CLEANUP?']
10
- IMAGE_LIST_FORMAT = '%-16s%-12s%-16s%-42s%-24s'
9
+ IMAGE_LIST_HEADER = ['REGION', 'IN USE?', 'NAME', 'AMI ID', 'CREATED', 'ELEGIBLE FOR CLEANUP?']
10
+ IMAGE_LIST_FORMAT = '%-10s%-10s%-24s%-24s%-42s%-6s'
11
11
 
12
12
  def self.run options
13
13
  regions = filter_regions(options[:r])
@@ -31,6 +31,14 @@ module Awsclean
31
31
  instances = res.reservations.flat_map(&:instances)
32
32
  amis_in_use = instances.map(&:image_id).uniq
33
33
 
34
+ # Allow user to define a list of locked AMIs
35
+ if !options[:a].empty?
36
+ options[:a].each do |ami|
37
+ puts "Locked AMI: #{ami}"
38
+ amis_in_use << ami
39
+ end
40
+ end
41
+
34
42
  # Get a list of all of AMI's owned by the account.
35
43
  #
36
44
  res = ec2.describe_images(owners: %w(self))
@@ -72,7 +80,7 @@ module Awsclean
72
80
  created << " (#{image.days_since_creation} days ago)"
73
81
 
74
82
  sprintf(IMAGE_LIST_FORMAT,
75
- region, image.in_use, image.image_id,
83
+ region, image.in_use, image.name, image.image_id,
76
84
  created, image.elegible_for_cleanup)
77
85
  end
78
86
  end
@@ -10,12 +10,14 @@ module Awsclean
10
10
  -- -e [days] the number of days considered "unused", default is 60
11
11
  -- -l and -c can be used with -e but -l and -c cannot be used together. Default mode is -l.
12
12
  -- -r [regions] to specify regions to check, in the form of "us-west-1,us-east-1,..." separated by comma
13
+ -- -a [amis] to specify amis to skip for deletion, in the form of "ami-xxxxxx,ami-yyyyyy,..." separated by comma
13
14
  =end
14
15
 
15
16
  option :l, type: :boolean, default: true #list
16
17
  option :c, type: :boolean
17
18
  option :e, type: :numeric, default: 60
18
19
  option :r, type: :array, default: %w(all)
20
+ option :a, type: :array, default: %w()
19
21
 
20
22
  # TODO: dynamically generate these based on listing out subclasses of AwsCommand?
21
23
 
@@ -20,19 +20,6 @@ module Awsclean
20
20
  exit 1
21
21
  end
22
22
 
23
- # List images used in active task definitions from all regions.
24
- # This is a global operation so we run it once.
25
- #
26
- images_in_active_task_defs = supported_regions.flat_map do |region|
27
- ecs = Aws::ECS::Client.new(region: region)
28
- res = ecs.list_task_definitions(status: 'ACTIVE', max_results: 100)
29
-
30
- res.task_definition_arns.flat_map do |td|
31
- ecs.describe_task_definition(task_definition: td)
32
- .task_definition.container_definitions.map(&:image)
33
- end
34
- end
35
-
36
23
  regions.each do |region|
37
24
  puts "[clean_ecr_images] Checking region: #{region}"
38
25
 
@@ -48,7 +35,7 @@ module Awsclean
48
35
 
49
36
  images.each do |image|
50
37
  image.region = region
51
- image.in_use = !(images_in_active_task_defs & image.image_uris).empty?
38
+ image.in_use = !image.image_uris.empty?
52
39
  image.elegible_for_cleanup = (image.stale?(options[:e]) && !image.in_use)
53
40
  end
54
41
 
@@ -2,6 +2,6 @@
2
2
  #
3
3
 
4
4
  module Awsclean
5
- VERSION = "1.0"
5
+ VERSION = "1.1"
6
6
  end
7
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awsclean
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-05 00:00:00.000000000 Z
11
+ date: 2018-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  version: '0'
184
184
  requirements: []
185
185
  rubyforge_project:
186
- rubygems_version: 2.5.2
186
+ rubygems_version: 2.7.7
187
187
  signing_key:
188
188
  specification_version: 4
189
189
  summary: CLI to clean up AWS AMIs and ECR images