stack_master 1.8.2 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/lib/stack_master.rb +2 -0
- data/lib/stack_master/parameter_resolvers/latest_container.rb +55 -0
- data/lib/stack_master/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 703182eae32be458fba4518afcd5ea019579178941d5491478ca26718816d4b3
|
4
|
+
data.tar.gz: 5fe2acde9e09e1eb81568244268c2ff26e35f868e02de16d80dfbc03f6079e7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df7259d1e06cff12577234e58670c83676833c4d5936e825fd232fe7815740216aad539c6ba25a87b8fd3e3a466b2fb3cc2d86071d4c4e5b8ba1b62ef6493b98
|
7
|
+
data.tar.gz: aec708ec027cacc228e3ea2968ea9788362022effbb087e497eeca92c7ad26e196e5497971c031e56607da115b7ca9fcfb5393a830af06af734e4a971a75f53c
|
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
|
data/lib/stack_master/version.rb
CHANGED
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.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
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-
|
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
|