Sha256: 686dd1812b50d54826e14450711d12dde82015e914e88a59fc1d8524f89582ab

Contents?: true

Size: 1.25 KB

Versions: 35

Compression:

Stored size: 1.25 KB

Contents

class KuberKit::ServiceDeployer::Deployer
  StrategyNotFoundError = Class.new(KuberKit::NotFoundError)

  include KuberKit::Import[
    "core.service_store",
    "service_deployer.strategies.kubernetes",
    "service_deployer.strategies.docker",
    "service_deployer.strategies.docker_compose"
  ]

  def initialize(**injected_deps)
    super(injected_deps)
    add_default_strategies
  end

  def register_strategy(strategy_name, strategy)
    @@strategies ||= {}

    if !strategy.is_a?(KuberKit::ServiceDeployer::Strategies::Abstract)
      raise ArgumentError.new("should be an instance of KuberKit::ServiceDeployer::Strategies::Abstract, got: #{strategy.inspect}")
    end

    @@strategies[strategy_name] = strategy
  end

  Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service, Symbol => Any
  def deploy(shell, service, strategy_name)
    deployer = @@strategies[strategy_name]

    raise StrategyNotFoundError, "Can't find strategy with name #{strategy_name}" if deployer.nil?

    deployer.deploy(shell, service)
  end

  def reset!
    @@strategies = {}
  end

  private
    def add_default_strategies
      register_strategy(:kubernetes, kubernetes)
      register_strategy(:docker, docker)
      register_strategy(:docker_compose, docker_compose)
    end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
kuber_kit-0.4.5 lib/kuber_kit/service_deployer/deployer.rb
kuber_kit-0.4.4 lib/kuber_kit/service_deployer/deployer.rb
kuber_kit-0.4.3 lib/kuber_kit/service_deployer/deployer.rb
kuber_kit-0.4.2 lib/kuber_kit/service_deployer/deployer.rb
kuber_kit-0.4.1 lib/kuber_kit/service_deployer/deployer.rb
kuber_kit-0.4.0 lib/kuber_kit/service_deployer/deployer.rb
kuber_kit-0.3.11 lib/kuber_kit/service_deployer/deployer.rb
kuber_kit-0.3.10 lib/kuber_kit/service_deployer/deployer.rb
kuber_kit-0.3.9 lib/kuber_kit/service_deployer/deployer.rb
kuber_kit-0.3.8 lib/kuber_kit/service_deployer/deployer.rb
kuber_kit-0.3.7 lib/kuber_kit/service_deployer/deployer.rb
kuber_kit-0.3.6 lib/kuber_kit/service_deployer/deployer.rb
kuber_kit-0.3.5 lib/kuber_kit/service_deployer/deployer.rb
kuber_kit-0.3.4 lib/kuber_kit/service_deployer/deployer.rb
kuber_kit-0.3.3 lib/kuber_kit/service_deployer/deployer.rb