Skip to content

Commit

Permalink
Refactor non-oss file loading (#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakolehm committed Oct 18, 2018
1 parent 7d2161b commit bcda3be
Show file tree
Hide file tree
Showing 92 changed files with 36 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pipeline:
- gem install bundler -Nf
- bundle install --path bundler
- bundle exec rspec spec/
- bundle exec rspec non-oss/spec/
- PHAROS_NON_OSS=true bundle exec rspec non-oss/spec/
- bundle exec rubocop --fail-level A -S --format c --parallel
create_gh_release:
image: ubuntu:xenial
Expand Down Expand Up @@ -35,6 +35,7 @@ pipeline:
image: ubuntu:xenial
environment:
- CPPFLAGS=-P
- PHAROS_NON_OSS=true
commands:
- ./build/drone/ubuntu.sh
when:
Expand Down
24 changes: 15 additions & 9 deletions lib/pharos/cluster_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ class ClusterManager

attr_reader :config

def self.phase_dirs
@phase_dirs ||= [
File.join(__dir__, 'phases')
]
end

def self.addon_dirs
@addon_dirs ||= [
File.join(__dir__, '..', '..', 'addons'),
File.join(Dir.pwd, 'pharos-addons')
]
end

# @param config [Pharos::Config]
# @param pastel [Pastel]
def initialize(config, pastel: Pastel.new)
Expand Down Expand Up @@ -39,15 +52,8 @@ def addon_manager

# load phases/addons
def load
Pharos::PhaseManager.load_phases(
File.join(__dir__, 'phases'),
File.join(__dir__, '..', '..', 'non-oss', 'phases')
)
addon_dirs = [
File.join(__dir__, '..', '..', 'addons'),
File.join(Dir.pwd, 'pharos-addons'),
File.join(__dir__, '..', '..', 'non-oss', 'addons')
] + @config.addon_paths.map { |d| File.join(Dir.pwd, d) }
Pharos::PhaseManager.load_phases(*self.class.phase_dirs)
addon_dirs = self.class.addon_dirs + @config.addon_paths.map { |d| File.join(Dir.pwd, d) }

addon_dirs.keep_if { |dir| File.exist?(dir) }
addon_dirs = addon_dirs.map { |dir| Pathname.new(dir).realpath.to_s }.uniq
Expand Down
2 changes: 0 additions & 2 deletions lib/pharos/root_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ def self.run
end
end
end

Dir.glob(File.join(__dir__, '..', '..', 'non-oss', 'commands', '*.rb')).each { |non_oss_command| require non_oss_command }
2 changes: 2 additions & 0 deletions lib/pharos_cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ module Pharos
COREDNS_VERSION = '1.1.3'
TELEMETRY_VERSION = '0.1.0'
end

require "pharos_non_oss" if $LOAD_PATH.any? { |path| path.end_with?('non-oss') }
6 changes: 6 additions & 0 deletions non-oss/pharos_non_oss.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

Pharos::ClusterManager.phase_dirs << File.join(__dir__, 'pharos_pro', 'phases')
Pharos::ClusterManager.addon_dirs << File.join(__dir__, 'pharos_pro', 'addons')

Dir.glob(File.join(__dir__, 'pharos_pro', 'commands', '*.rb')).each { |command| require command }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'pharos/addon'
require_relative "../../../non-oss/addons/kontena-backup/addon"
require "pharos_pro/addons/kontena-backup/addon"

describe Pharos::Addons::KontenaBackup do
let(:cluster_config) { Pharos::Config.new(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'pharos/addon'
require 'pharos/kube'
require './non-oss/addons/kontena-storage/addon'
require 'pharos_pro/addons/kontena-storage/addon'

RSpec.describe Pharos::Addons::KontenaStorage do
describe '.validate' do
Expand Down
13 changes: 9 additions & 4 deletions pharos-cluster.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "pharos/version"

files = Dir['README.md', 'LICENSE', 'licenses/*', 'bin/*', 'lib/**/*', 'addons/**/*']
require_paths = ['lib']
if ENV['PHAROS_NON_OSS'] == 'true'
files += Dir['non-oss/**/*']
require_paths << 'non-oss'
end

Gem::Specification.new do |spec|
spec.name = "pharos-cluster"
spec.version = Pharos::VERSION.sub('-', '.')
Expand All @@ -13,12 +20,10 @@ Gem::Specification.new do |spec|
spec.description = "Kontena Pharos cluster manager"
spec.homepage = "https://github.com/kontena/pharos-cluster"

spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
spec.files = files
spec.bindir = "bin"
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.require_paths = require_paths
spec.required_ruby_version = '~> 2.4'

spec.add_runtime_dependency "clamp", "1.2.1"
Expand Down

0 comments on commit bcda3be

Please sign in to comment.