diff --git a/.rubocop.yml b/.rubocop.yml index 8e9fdae..9667367 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -15,3 +15,6 @@ Layout/LineLength: Style/Documentation: Enabled: false + +Metrics/BlockLength: + IgnoredMethods: ['describe', 'context'] diff --git a/lib/rumbda/function.rb b/lib/rumbda/function.rb index 9b6404c..f5d8d6e 100644 --- a/lib/rumbda/function.rb +++ b/lib/rumbda/function.rb @@ -30,9 +30,9 @@ class Command < Thor desc: "Lambda functions to package and deploy. Defaults to the functions list configured in the service configuration file" class_option :ecr_registry, - required: false, + required: true, aliases: "-ecr", - desc: "Name of the ECR registry to push to. Defaults to the ecr_registry value configured for the given environment" + desc: "Name of the ECR registry to push to." class_option :image_tag, required: true, diff --git a/lib/rumbda/function/config.rb b/lib/rumbda/function/config.rb index 0ce1122..973ad00 100644 --- a/lib/rumbda/function/config.rb +++ b/lib/rumbda/function/config.rb @@ -15,11 +15,11 @@ def initialize(options) end def image_uri - @__image_uri ||= "#{ecr_registry}/#{environment}-#{service}:#{image_tag}" + @image_uri ||= "#{ecr_registry}/#{service}:#{image_tag}" end def functions - @__functions ||= function_names.map do |function_name| + @functions ||= function_names.map do |function_name| "#{environment}-#{service}-#{function_name}" end end @@ -85,15 +85,6 @@ def parse_dockerfile! def parse_ecr_registry! @ecr_registry = options[:ecr_registry] - return unless ecr_registry.blank? - - current_environment_config = yaml_content[:environments][environment] - if current_environment_config.blank? - raise ::Rumbda::Function::ConfigError, - "environments block in config file is missing options for the environment called '#{environment}'" - end - - @ecr_registry = current_environment_config[:ecr_registry] raise ::Rumbda::Function::ConfigError, "ecr_registry parameter not provided" if ecr_registry.blank? end end diff --git a/spec/rumbda/function/config_spec.rb b/spec/rumbda/function/config_spec.rb index 06ca4d3..5ec2be6 100644 --- a/spec/rumbda/function/config_spec.rb +++ b/spec/rumbda/function/config_spec.rb @@ -6,11 +6,11 @@ subject { described_class.new(options) } let(:config_file) { "spec/support/rumbda.yml" } - let(:environment) { :test } - let(:service) { "test-service" } - let(:functions) { %w[one two three] } - let(:ecr_registry) { "test-registry" } - let(:image_tag) { "test-tag" } + let(:environment) { "testenv" } + let(:service) { "petshop" } + let(:functions) { %w[order purchase cancel] } + let(:ecr_registry) { "ecr-petshop-registry" } + let(:image_tag) { "SOMETAG" } let(:dockerfile) { "spec/support/test_repository/Dockerfile" } let(:options) do { @@ -24,8 +24,8 @@ } end - let(:formatted_image_uri) { "#{ecr_registry}/#{environment}-#{service}:#{image_tag}" } - let(:formatted_functions) { functions.map { |f| "#{environment}-#{service}-#{f}" } } + let(:formatted_image_uri) { "#{ecr_registry}/#{service}:#{image_tag}" } + let(:formatted_functions) { functions.map { |function| "#{environment}-#{service}-#{function}" } } describe "#image_uri" do it "returns a correctly formatted image uri" do @@ -182,34 +182,9 @@ end context "when the ecr registry is not in the options" do - context "and it is in the config file" do - let(:ecr_registry) { nil } - it "loads the value from the config file" do - expect { subject }.to_not raise_error - expect(subject.ecr_registry).to eq(parsed_service_yaml[:environments][environment][:ecr_registry]) - end - end - - context "and the environment is not in the config file" do - before do - allow(YAML).to receive(:load_file).and_return({ environments: {} }) - end - let(:ecr_registry) { nil } - it "throws an error" do - expect { subject }.to raise_error(::Rumbda::Function::ConfigError, /environments/) - end - end - - context "and the registry is not in the config file" do - before do - allow(YAML).to receive(:load_file).and_return({ - environments: { environment => { ecr_registry: nil } } - }) - end - let(:ecr_registry) { nil } - it "throws an error" do - expect { subject }.to raise_error(::Rumbda::Function::ConfigError, /ecr_registry/) - end + let(:ecr_registry) { nil } + it "throws an error" do + expect { subject }.to raise_error(::Rumbda::Function::ConfigError, /ecr_registry/) end end end diff --git a/spec/rumbda/function/deploy_spec.rb b/spec/rumbda/function/deploy_spec.rb index 15663db..e607e61 100644 --- a/spec/rumbda/function/deploy_spec.rb +++ b/spec/rumbda/function/deploy_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" RSpec.describe Rumbda::Function::Deploy do diff --git a/spec/support/rumbda.yml b/spec/support/rumbda.yml index 13dfdca..80937f3 100644 --- a/spec/support/rumbda.yml +++ b/spec/support/rumbda.yml @@ -4,12 +4,3 @@ functions: - pets - stores - users -environments: - production: - ecr_registry: 123456789012.dkr.ecr.eu-west-1.amazonaws.com - staging: - ecr_registry: 210987654321.dkr.ecr.eu-west-1.amazonaws.com - hello: - ecr_registry: 210987654321.dkr.ecr.eu-west-1.amazonaws.com - test: - ecr_registry: 210987654321.dkr.ecr.eu-west-1.amazonaws.com