harbr 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28f2c1235e59113b8c839c9415029ee430dd17a7f5b9faee3c7b87e702d1985c
4
- data.tar.gz: 4fb3a9e958c0409d63e04e2430cfb0d5133991e4971fde94f41c9e5b79ecf0f6
3
+ metadata.gz: ba1c2de0c57a31b1b85b0f7140e05995404a1a013502c6d01a965f709bb8b3b3
4
+ data.tar.gz: 95d574f90f0c21d580a924f3e8318b8af529ff2ded73574825bda2c65aa30640
5
5
  SHA512:
6
- metadata.gz: 8982a2e3d0fc1373af022ef5bace65c89fa4113539bc09606e4d58d8cb491b21c4de980638a1543747588230558013fbc1248be62fb50fbe6ece2d0d31d850cf
7
- data.tar.gz: ea16bacf0c5a6f444a9cf946443bd01eeea71147cf0e7ffff751c44264c891aa9b0001de094980851d87fc6621562eed0938df2ca76f2911c121bf6a162634bd
6
+ metadata.gz: f5b081f4e73595bd8597fa05aa97dc2612869f9a96340df638fb6109859657e34909c3b0532d5bc2b1b76a67e07cb31d3e52c868f0740de5fbcad26ea118a37f
7
+ data.tar.gz: 5c99af944a71d9f31ef2412bdeb1cdbef04ed32e81df82259596a82397f90a21aac10770cffd196616e149ba4291fe10d94ed6aec3058f6c888004aaacd31a42
File without changes
File without changes
Binary file
Binary file
data/exe/harbr CHANGED
@@ -1,33 +1,23 @@
1
1
  #!/usr/bin/env ruby
2
- require 'thor'
3
- require 'listen'
4
- require 'dddr'
5
- require 'harbr'
6
- require 'sucker_punch'
7
- require 'terminal-table'
2
+ require "thor"
3
+ require "dddr"
4
+ require "harbr"
5
+ require "sucker_punch"
6
+ require "terminal-table"
8
7
 
9
8
  class HarbrCLI < Thor
10
- DEFAULT_DIRECTORY = '/var/harbr'
9
+ DEFAULT_DIRECTORY = "/var/harbr"
11
10
  DEFAULT_DIRECTORY_DATA_DIR = "#{DEFAULT_DIRECTORY}/.data"
12
- @@listener = nil
13
-
14
11
  Dddr.configure do |config|
15
12
  config.data_dir = DEFAULT_DIRECTORY_DATA_DIR
16
13
  end
17
14
 
18
-
19
15
  no_commands do
20
-
21
- def extract_container_name(path)
22
- match = path.match(/\/var\/harbr\/(?<container_name>.*)\/versions\/\d*\/config\/manifest.yml/)
23
- match ? match[:container_name] : nil
24
- end
25
-
26
16
  def display_containers_table(containers)
27
17
  return puts "No containers available." if containers.empty?
28
18
 
29
19
  # Define headers based on Container attributes
30
- headers = ['Name', 'Host Header', 'IP', 'Port']
20
+ headers = ["Name", "Host Header", "IP", "Port"]
31
21
 
32
22
  rows = containers.map do |container|
33
23
  [container.name, container.host_header, container.ip, container.port]
@@ -41,7 +31,6 @@ class HarbrCLI < Thor
41
31
  puts ""
42
32
  end
43
33
 
44
-
45
34
  def check_and_create_directory(path)
46
35
  unless Dir.exist?(path)
47
36
  puts "Creating directory: #{path}"
@@ -63,83 +52,59 @@ class HarbrCLI < Thor
63
52
  system("sudo apt install #{package}") or raise "Failed to install #{package}"
64
53
  end
65
54
 
55
+ def scan_for_containers
56
+ Dir.glob("/var/harbr/*").each_with_object({}) do |container_path, hash|
57
+ next unless File.directory?(container_path)
58
+ container_name = File.basename(container_path)
59
+ versions = Dir.glob("#{container_path}/versions/*").select { |path| File.directory?(path) }
60
+ versions.each { |version_path| hash["#{container_name}/versions/#{File.basename(version_path)}"] = true }
61
+ end
62
+ end
63
+
64
+ def place(container, version)
65
+ puts "Placing container: '#{container}', Version: '#{version}'"
66
+ end
67
+
66
68
  end
67
69
 
68
70
  desc "setup", "Set up Harbr environment"
69
71
  def setup
70
72
  # Check and create /var/harbr directory
71
- check_and_create_directory('/var/harbr')
73
+ check_and_create_directory("/var/harbr")
72
74
 
73
75
  # Check for Ruby, Traefik, and runit, and install if necessary
74
- install_with_snap('ruby') unless command_exists?('ruby')
75
- install_with_snap('traefik') unless command_exists?('traefik')
76
- install_with_apt('runit') unless command_exists?('runit')
76
+ install_with_snap("ruby") unless command_exists?("ruby")
77
+ install_with_snap("traefik") unless command_exists?("traefik")
78
+ install_with_apt("runit") unless command_exists?("runit")
77
79
 
78
80
  puts "Setup completed successfully."
79
81
  end
80
82
 
81
- desc "start [DIRECTORY]", "Start listening to a directory for changes"
82
- def start(directory = DEFAULT_DIRECTORY)
83
- return if @@listener
83
+ desc "containers", "show all containers"
84
+ def containers
85
+ container_repo = Harbr::Container::Repository.new
86
+ display_containers_table(container_repo.all)
87
+ end
84
88
 
85
- puts "Starting Harbr, listening to #{directory}"
89
+ desc "monitor", "Monitor /var/harbr for new container versions"
90
+ def monitor
91
+ puts "Monitoring /var/harbr for new container versions..."
92
+ last_known_state = {}
86
93
 
87
- @@listener = Listen.to(directory) do |modified, added, removed|
88
- job_created = false
94
+ loop do
95
+ current_state = scan_for_containers
96
+ new_versions = current_state.keys - last_known_state.keys
89
97
 
90
- added.each do |path|
91
- next if job_created
92
- if path.match?(/\/var\/harbr\/.*\/versions\/\d*\/config\/manifest.yml/)
93
- container_name = extract_container_name(path)
94
- if container_name
95
- Harbr::Container::Job.perform_async(container_name)
96
- job_created = true
97
- end
98
- end
98
+ new_versions.each do |container_version|
99
+ container, version = container_version.split("/versions/")
100
+ place(container, version)
99
101
  end
100
- end
101
- @@listener.start # not blocking
102
- sleep
103
- end
104
-
105
- desc "stop", "Stop Harbr"
106
- def stop
107
- if @@listener
108
- @@listener.stop
109
- @@listener = nil
110
- puts "Harbr has been stopped."
111
- else
112
- puts "Harbr is not running."
113
- end
114
- end
115
-
116
- desc "pause", "Pause Harbr"
117
- def pause
118
- if @@listener
119
- @@listener.pause
120
- puts "Harbr has been paused."
121
- else
122
- puts "Harbr is not running or already paused."
123
- end
124
- end
125
102
 
126
- desc "resume", "Resume Harbr"
127
- def resume
128
- if @@listener
129
- @@listener.start
130
- puts "Harbr has been resumed."
131
- else
132
- puts "Harbr is not running or already active."
103
+ last_known_state = current_state
104
+ sleep 10 # Poll every 10 seconds
133
105
  end
134
106
  end
135
107
 
136
- desc "containers", "show all containers"
137
- def containers
138
- container_repo = Harbr::Container::Repository.new
139
- display_containers_table(container_repo.all)
140
- end
141
-
142
108
  end
143
109
 
144
110
  HarbrCLI.start(ARGV)
145
-
data/lib/harbr/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Harbr
4
- VERSION = "0.0.8"
4
+ VERSION = "0.0.9"
5
5
  end
data/lib/harbr.rb CHANGED
@@ -1,59 +1,55 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative "harbr/version"
3
- require 'dddr'
4
- require 'sucker_punch'
4
+ require "dddr"
5
+ require "sucker_punch"
5
6
 
6
7
  module Harbr
7
8
  class Error < StandardError; end
8
- class Container
9
+
10
+ class Container
9
11
  class Job
10
12
  include SuckerPunch::Job
11
-
13
+
12
14
  def perform(config)
13
-
14
15
  puts "Harbr Job!"
15
16
  puts config
16
-
17
17
  end
18
18
  end
19
19
 
20
20
  include Dddr::Entity
21
- attr_accessor :name, :host_header, :ip, :port
22
- end
21
+ attr_accessor :name, :host_header, :ip, :port
22
+ end
23
23
 
24
- class Port
25
-
24
+ class Port
26
25
  include Dddr::Entity
27
26
  attr_accessor :host_header, :number
28
27
 
29
28
  queries do
30
29
  def has_port_number?(number)
31
- all.find {|port| port.number == number.to_i}
30
+ all.find { |port| port.number == number.to_i }
32
31
  end
32
+
33
33
  def assigned_a_port?(host_header)
34
- all.find {|port| port.host_header == host_header}
34
+ all.find { |port| port.host_header == host_header }
35
35
  end
36
36
  end
37
37
  class Pool
38
- def initialize(port_range=50000..51000)
39
-
38
+ def initialize(port_range = 50000..51000)
40
39
  @repository = Port::Repository.new
41
40
 
42
41
  port_range.each do |number|
43
-
44
- port = Port.new
42
+ port = Port.new
45
43
  port.number = number
46
-
44
+
47
45
  unless @repository.has_port_number? number
48
- @repository.add(port)
46
+ @repository.add(port)
49
47
  puts port.number.to_s + " added!"
50
48
  end
51
49
  end
52
-
53
50
  end
54
-
51
+
55
52
  def get_port(host_header)
56
-
57
53
  port = @repository.assigned_a_port?(host_header)
58
54
  return port unless port.nil?
59
55
 
@@ -68,16 +64,12 @@ module Harbr
68
64
  @repository.update(port)
69
65
  port.host_header.nil?
70
66
  end
71
-
67
+
72
68
  def ports
73
69
  @repository.all
74
70
  end
75
-
76
71
  end
77
-
78
-
79
72
  end
80
-
81
-
82
- # Your code goes here...
73
+
74
+ # Your code goes here...
83
75
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harbr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delaney Kuldvee Burke
@@ -90,6 +90,10 @@ executables:
90
90
  extensions: []
91
91
  extra_rdoc_files: []
92
92
  files:
93
+ - ".data/development/Harbr::Container.dir"
94
+ - ".data/development/Harbr::Container.pag"
95
+ - ".data/development/Harbr::Port.dir"
96
+ - ".data/development/Harbr::Port.pag"
93
97
  - ".rspec"
94
98
  - ".standard.yml"
95
99
  - CHANGELOG.md