Skip to content

Commit

Permalink
Make ECR Registry a required option
Browse files Browse the repository at this point in the history
  • Loading branch information
muzfuz committed Jan 17, 2022
1 parent 1a3a472 commit 136129a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 57 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ Layout/LineLength:

Style/Documentation:
Enabled: false

Metrics/BlockLength:
IgnoredMethods: ['describe', 'context']
4 changes: 2 additions & 2 deletions lib/rumbda/function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 2 additions & 11 deletions lib/rumbda/function/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
45 changes: 10 additions & 35 deletions spec/rumbda/function/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions spec/rumbda/function/deploy_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.describe Rumbda::Function::Deploy do
Expand Down
9 changes: 0 additions & 9 deletions spec/support/rumbda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 136129a

Please sign in to comment.