diff --git a/Procfile b/Procfile new file mode 100644 index 000000000..e634d02bf --- /dev/null +++ b/Procfile @@ -0,0 +1,2 @@ +local: dynamodb-local # port 8000 +admin: env AWS_ACCESS_KEY_ID=$DYNAMODB_ADMIN_AWS_ACCESS_KEY_ID PORT=8001 dynamodb-admin # port 8001 diff --git a/lib/jets/application.rb b/lib/jets/application.rb index 6bf7289ab..2cc84bb9d 100644 --- a/lib/jets/application.rb +++ b/lib/jets/application.rb @@ -13,12 +13,14 @@ def config @config ||= RecursiveOpenStruct.new end + # Jets' the default config/application.rb is loaded, + # then the project's config/application.rb is loaded. def load_configs require File.expand_path("../default/application.rb", __FILE__) app_config = "#{Jets.root}config/application.rb" require app_config if File.exist?(app_config) set_aliases! - normalize_environment! + normalize_env_vars! end # Use the shorter name in stack names, but use the full name when it @@ -48,9 +50,10 @@ def set_aliases! end end - # It is pretty easy to attempt to environment variables without the correct - # AWS Environment.Variables path struture. We auto-fix it for convenience. - def normalize_environment! + # It is pretty easy to attempt to set environment variables without + # the correct AWS Environment.Variables path struture. + # Auto-fix it for convenience. + def normalize_env_vars! environment = config.function.environment if environment and !environment.to_h.key?(:variables) config.function.environment = { diff --git a/lib/jets/default/application.rb b/lib/jets/default/application.rb index abcb6c94a..6fdf9d3fc 100644 --- a/lib/jets/default/application.rb +++ b/lib/jets/default/application.rb @@ -12,6 +12,7 @@ config.extra_autoload_paths = [] # function properties defaults + config.function = RecursiveOpenStruct.new config.function.timeout = 10 config.function.runtime = "nodejs6.10" config.function.memory_size = 1536 diff --git a/lib/jets/util.rb b/lib/jets/util.rb index 76dd02ff2..b4c202182 100644 --- a/lib/jets/util.rb +++ b/lib/jets/util.rb @@ -30,11 +30,14 @@ def config Jets.application.config end + # Calling application triggers load of configs. + # Jets' the default config/application.rb is loaded, + # then the project's config/application.rb is loaded. @@application = nil def application return @@application if @@application @@application = Jets::Application.new - @@application.load_configs # triggers load of application configs + @@application.load_configs @@application end diff --git a/spec/lib/jets/cfn/template_builders/controller_builder_spec.rb b/spec/lib/jets/cfn/template_builders/controller_builder_spec.rb index f33cd26a1..fc3f9e7be 100644 --- a/spec/lib/jets/cfn/template_builders/controller_builder_spec.rb +++ b/spec/lib/jets/cfn/template_builders/controller_builder_spec.rb @@ -55,8 +55,7 @@ properties = resources["StoresControllerIndexLambdaFunction"]["Properties"] expect(properties["MemorySize"]).to eq 1000 - # should not pascalize the keys under Variables section - expect(properties["DeadLetterConfig"]).to eq "arn" + expect(properties["Timeout"]).to eq 20 end end diff --git a/spec/lib/jets/cfn/template_builders/function_properties_builder_spec.rb b/spec/lib/jets/cfn/template_builders/function_properties_builder_spec.rb index 6e2479469..4315b0243 100644 --- a/spec/lib/jets/cfn/template_builders/function_properties_builder_spec.rb +++ b/spec/lib/jets/cfn/template_builders/function_properties_builder_spec.rb @@ -34,7 +34,7 @@ # pp props # testing properties(...) expect(props["MemorySize"]).to eq 1000 - expect(props["Role"]).to eq "myrole" + expect(props["Role"]).to eq("Ref"=>"IamRole") expect(props["Timeout"]).to eq 20 end end diff --git a/spec/lib/jets/lambda/dsl_spec.rb b/spec/lib/jets/lambda/dsl_spec.rb index ba4683859..439a345c9 100644 --- a/spec/lib/jets/lambda/dsl_spec.rb +++ b/spec/lib/jets/lambda/dsl_spec.rb @@ -1,6 +1,26 @@ require "spec_helper" +class TestPropertiesController < ApplicationController + properties( + dead_letter_config: "arn", timeout: 20, role: "myrole", memory_size: 1000 + ) + def index + end +end + describe Jets::Lambda::Dsl do + context "TestPropertiesController" do + let(:controller) { TestPropertiesController.new({}, nil, "index") } + + it "tasks" do + index_task = TestPropertiesController.all_tasks[:index] + expect(index_task).to be_a(Jets::Lambda::Task) + expect(index_task.properties).to eq( + dead_letter_config: "arn", timeout: 20, role: "myrole", memory_size: 1000 + ) + end + end + context "StoresController" do let(:controller) { StoresController.new({}, nil, "new") } @@ -10,9 +30,6 @@ index_task = StoresController.all_tasks[:index] expect(index_task).to be_a(Jets::Lambda::Task) - expect(index_task.properties).to eq( - dead_letter_config: "arn", timeout: 20, role: "myrole", memory_size: 1000 - ) end it "timeout" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8ab38a83a..5f3049a5b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -36,6 +36,15 @@ def json_file(path) end end +# pretty hacky way of stubbing out md5_code_zipfile +Jets::Naming # autoload it +class Jets::Naming + # override this for specs + def self.md5_code_zipfile + "/tmp/jets/demo/code/code-2e0e18f6.zip" + end +end + RSpec.configure do |c| c.before(:suite) do Aws.config.update(stub_responses: true)