Skip to content

Commit aea60bf

Browse files
authored
Merge pull request #166 from theonestack/feature/publish-artifacts
adds support for publishing additional artifacts to CloudFormation destination bucket
2 parents dfc842b + d94055f commit aea60bf

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,27 @@ end
863863
864864
```
865865
866+
### Publishing Additonal Artifacts
867+
868+
If you need to publish additonal files along with your cloudformation templates you can use the following DSL:
869+
870+
```ruby
871+
CfhighlanderTemplate do
872+
Name 'my_app'
873+
PublishArtifact file: "my-apigateway-spec.yaml"
874+
end
875+
```
876+
877+
This will upload the file `my-apigateway-spec.yaml` to the s3 destnation/distribution bucket using the default s3 prefix. If you want to override the s3 key you can use
878+
879+
```ruby
880+
CfhighlanderTemplate do
881+
Name 'my_app'
882+
PublishArtifact file: "my-apigateway-spec.yaml", key: '/my-custom-path/my-custom-file.yaml'
883+
end
884+
```
885+
886+
866887
## Finding templates and creating components
867888
868889

lib/cfhighlander.dsl.template.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class HighlanderTemplate < DslBase
3737
:lambda_functions_keys,
3838
:description,
3939
:dependson_components,
40-
:template_dir
40+
:template_dir,
41+
:publish_artifacts
4142

4243
attr_reader :conditions,
4344
:subcomponents,
@@ -63,6 +64,7 @@ def initialize
6364
# execution blocks for subcomponents
6465
@subcomponents_exec = {}
6566
@template_dir = nil
67+
@publish_artifacts = []
6668
end
6769

6870
# DSL statements
@@ -207,6 +209,11 @@ def LambdaFunctions(config_key)
207209
@lambda_functions_keys << config_key
208210
end
209211

212+
def PublishArtifact(file: nil, key: key=nil)
213+
puts "INFO: adding artifact #{file} to publishing list"
214+
@publish_artifacts << {file: file, key: key}
215+
end
216+
210217
# Internal and interface functions
211218

212219
def loadComponents

lib/cfhighlander.publisher.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ def publishFiles(file_list)
8383
end
8484
print "\n"
8585

86+
@component.highlander_dsl.publish_artifacts.each do |artifact|
87+
s3_key = artifact[:key].nil? ? "#{prefix}/#{version}/#{artifact[:file]}" : artifact[:key]
88+
print "\nPublishing artifact: #{artifact[:file]} to s3://#{bucket}/#{s3_key} ..."
89+
s3.put_object({
90+
body: File.read(artifact[:file]),
91+
bucket: bucket,
92+
key: s3_key
93+
})
94+
print ' [OK] '
95+
end
8696
end
8797

8898
end

0 commit comments

Comments
 (0)