stack_master 1.8.2-x64-mingw32 → 1.9.0-x64-mingw32

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: f5c8df4c1ca5a902795056c7177627da422fa80b
4
- data.tar.gz: b3d6e8fdd78625adaf9b52a9f635e1264612f462
3
+ metadata.gz: 39fb8fe954e9eb163f2a8cdbdc13648d3452fdcd
4
+ data.tar.gz: 20e8005d4bb5168b46e7425921a3959195c036d9
5
5
  SHA512:
6
- metadata.gz: 7778982bc492a324fd1a8a626d7f36968f6f13c851c3734c9db84c129bc0fe998776bbf1329e95be40c53f66dba90c002d8a9a19c73bc40d82d0f1c4d0ce06b8
7
- data.tar.gz: 6ad24bcbec94d05cd0bb99095b03f96384d0a6ed998e0188b458bef521cfa4cae81bd9c2be088b66135c279f73ec8e58a630494c8e1e953f34f475d5ad02860f
6
+ metadata.gz: aa0da8aba62df0e798a84d3040f809e746e7162fe378bf92781c3340c5f6cb2750d250785b18a777859062dac64b2cdbab42c6b4f25285d76c2cf0247e5e6577
7
+ data.tar.gz: b47296525f3e4e9691145aa083c2cff5dc2d4a12c3ac722f816e21200f04084b0bf9c69e831668dbc4066445732aa62a8148863c782bf9503985ec1d60a3c7bf
data/README.md CHANGED
@@ -331,6 +331,24 @@ A set of possible attributes is available in the [AWS documentation](https://doc
331
331
 
332
332
  Any value can be an array of possible matches.
333
333
 
334
+ ### Latest Container from Repository
335
+
336
+ Looks up the a Container Image from an ECR repository. By default this will return the latest container in a repository.
337
+ If `tag` is specified we return the sha digest of the image with this tag.
338
+ This avoids the issue where CloudFormation won't update a Task Definition if we use a tag such as `latest`, because it only updates resources if a parameter has changed.
339
+ This allows us to tag an image and deploy the latest version of that image via CloudFormation and avoids versioning our tags and having to store the metadata about the latest tag version somewhere.
340
+
341
+ Returns the docker repository URI, i.e. `aws_account_id.dkr.ecr.region.amazonaws.com/container@sha256:digest`
342
+
343
+ ```yaml
344
+ container_image_id:
345
+ latest_container:
346
+ repository_name: nginx # Required. The name of the repository
347
+ registry_id: 012345678910 # The AWS Account ID the repository is located in. Defaults to the current account's default registry
348
+ region: us-east-1 # Defaults to the region the stack is located in
349
+ tag: production # By default we'll find the latest image pushed to the repository. If tag is specified we return the sha digest of the image with this tag
350
+ ```
351
+
334
352
  ### Environment Variable
335
353
 
336
354
  Lookup an environment variable:
data/lib/stack_master.rb CHANGED
@@ -3,6 +3,7 @@ require 'yaml'
3
3
  require 'aws-sdk-acm'
4
4
  require 'aws-sdk-cloudformation'
5
5
  require 'aws-sdk-ec2'
6
+ require 'aws-sdk-ecr'
6
7
  require 'aws-sdk-s3'
7
8
  require 'aws-sdk-sns'
8
9
  require 'aws-sdk-ssm'
@@ -74,6 +75,7 @@ module StackMaster
74
75
  autoload :Env, 'stack_master/parameter_resolvers/env'
75
76
  autoload :ParameterStore, 'stack_master/parameter_resolvers/parameter_store'
76
77
  autoload :OnePassword, 'stack_master/parameter_resolvers/one_password'
78
+ autoload :LatestContainer, 'stack_master/parameter_resolvers/latest_container'
77
79
  end
78
80
 
79
81
  module AwsDriver
@@ -0,0 +1,55 @@
1
+ module StackMaster
2
+ module ParameterResolvers
3
+ class LatestContainer < Resolver
4
+ array_resolver class_name: 'LatestContainers'
5
+
6
+ def initialize(config, stack_definition)
7
+ @config = config
8
+ @stack_definition = stack_definition
9
+ end
10
+
11
+ def resolve(parameters)
12
+ if parameters['repository_name'].nil?
13
+ raise ArgumentError, "repository_name parameter is required but was not supplied"
14
+ end
15
+
16
+ @region = parameters['region'] || @stack_definition.region
17
+ ecr_client = Aws::ECR::Client.new(region: @region)
18
+
19
+ images = fetch_images(parameters['repository_name'], parameters['registry_id'], ecr_client)
20
+ return nil if images.empty?
21
+
22
+ if !parameters['tag'].nil?
23
+ images.select! { |image| image.image_tags.any? { |tag| tag == parameters['tag'] } }
24
+ end
25
+ images.sort! { |image_x, image_y| image_y.image_pushed_at <=> image_x.image_pushed_at }
26
+ latest_image = images.first
27
+
28
+ # aws_account_id.dkr.ecr.region.amazonaws.com/repository@sha256:digest
29
+ "#{latest_image.registry_id}.dkr.ecr.#{@region}.amazonaws.com/#{parameters['repository_name']}@#{latest_image.image_digest}"
30
+ end
31
+
32
+ private
33
+
34
+ def fetch_images(repository_name, registry_id, ecr)
35
+ images = []
36
+ next_token = nil
37
+ while
38
+ resp = ecr.describe_images({
39
+ repository_name: repository_name,
40
+ registry_id: registry_id,
41
+ next_token: next_token,
42
+ filter: {
43
+ tag_status: "TAGGED",
44
+ },
45
+ })
46
+
47
+ images += resp.image_details
48
+ next_token = resp.next_token
49
+ break if next_token.nil?
50
+ end
51
+ images
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,3 +1,3 @@
1
1
  module StackMaster
2
- VERSION = "1.8.2"
2
+ VERSION = "1.9.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stack_master
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.9.0
5
5
  platform: x64-mingw32
6
6
  authors:
7
7
  - Steve Hodgkiss
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-08-17 00:00:00.000000000 Z
12
+ date: 2018-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -235,6 +235,20 @@ dependencies:
235
235
  - - "~>"
236
236
  - !ruby/object:Gem::Version
237
237
  version: '1'
238
+ - !ruby/object:Gem::Dependency
239
+ name: aws-sdk-ecr
240
+ requirement: !ruby/object:Gem::Requirement
241
+ requirements:
242
+ - - "~>"
243
+ - !ruby/object:Gem::Version
244
+ version: '1'
245
+ type: :runtime
246
+ prerelease: false
247
+ version_requirements: !ruby/object:Gem::Requirement
248
+ requirements:
249
+ - - "~>"
250
+ - !ruby/object:Gem::Version
251
+ version: '1'
238
252
  - !ruby/object:Gem::Dependency
239
253
  name: diffy
240
254
  requirement: !ruby/object:Gem::Requirement
@@ -415,6 +429,7 @@ files:
415
429
  - lib/stack_master/parameter_resolvers/env.rb
416
430
  - lib/stack_master/parameter_resolvers/latest_ami.rb
417
431
  - lib/stack_master/parameter_resolvers/latest_ami_by_tags.rb
432
+ - lib/stack_master/parameter_resolvers/latest_container.rb
418
433
  - lib/stack_master/parameter_resolvers/one_password.rb
419
434
  - lib/stack_master/parameter_resolvers/parameter_store.rb
420
435
  - lib/stack_master/parameter_resolvers/secret.rb