harbr 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28f2c1235e59113b8c839c9415029ee430dd17a7f5b9faee3c7b87e702d1985c
4
- data.tar.gz: 4fb3a9e958c0409d63e04e2430cfb0d5133991e4971fde94f41c9e5b79ecf0f6
3
+ metadata.gz: 404dd9eb4cb65cc4ac7b36714df63e448ba9270eada369ae8085ab759d446979
4
+ data.tar.gz: def2e1ab1ddceb9b13515f3549cb2b305afd42041e77677a20e2da01d9f668d5
5
5
  SHA512:
6
- metadata.gz: 8982a2e3d0fc1373af022ef5bace65c89fa4113539bc09606e4d58d8cb491b21c4de980638a1543747588230558013fbc1248be62fb50fbe6ece2d0d31d850cf
7
- data.tar.gz: ea16bacf0c5a6f444a9cf946443bd01eeea71147cf0e7ffff751c44264c891aa9b0001de094980851d87fc6621562eed0938df2ca76f2911c121bf6a162634bd
6
+ metadata.gz: dcb225f086234af69a9e54f4d332db6d7d42e801c033c94d3aa083cfae9e95527e8fbf04e05c42a263509c12e979da04b8b295541f29f78bf4c5c2da0f6993bc
7
+ data.tar.gz: 47d50a64f88e3a450e804d4df365ce68aa4c0ce2a03699c8261de168cdb332f77fea703379d9c232ee74d0653a8f204aae1401a680df18aabaf1cd509af6fd3d
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,74 @@ 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
+ PLACED_FILE = '/var/harbr/.placed'
65
+
66
+ def place(container, version)
67
+ placed_containers = File.exist?(PLACED_FILE) ? File.read(PLACED_FILE).split("\n") : []
68
+
69
+ if placed_containers.include?("#{container}/#{version}")
70
+ puts "Container '#{container}', Version '#{version}' is already placed."
71
+ else
72
+ puts "Placing container: '#{container}', Version: '#{version}'"
73
+ run_tasks(container, version)
74
+ File.open(PLACED_FILE, 'a') { |file| file.puts("#{container}/#{version}") }
75
+ end
76
+ end
77
+
78
+ def run_tasks(container, version)
79
+ # Your logic for processing the container and version
80
+ puts "Running tasks for container: '#{container}', Version: '#{version}'"
81
+ end
82
+
66
83
  end
67
84
 
68
85
  desc "setup", "Set up Harbr environment"
69
86
  def setup
70
87
  # Check and create /var/harbr directory
71
- check_and_create_directory('/var/harbr')
88
+ check_and_create_directory("/var/harbr")
72
89
 
73
90
  # 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')
91
+ install_with_snap("ruby") unless command_exists?("ruby")
92
+ install_with_snap("traefik") unless command_exists?("traefik")
93
+ install_with_apt("runit") unless command_exists?("runit")
77
94
 
78
95
  puts "Setup completed successfully."
79
96
  end
80
97
 
81
- desc "start [DIRECTORY]", "Start listening to a directory for changes"
82
- def start(directory = DEFAULT_DIRECTORY)
83
- return if @@listener
98
+ desc "containers", "show all containers"
99
+ def containers
100
+ container_repo = Harbr::Container::Repository.new
101
+ display_containers_table(container_repo.all)
102
+ end
84
103
 
85
- puts "Starting Harbr, listening to #{directory}"
104
+ desc "monitor", "Monitor /var/harbr for new container versions"
105
+ def monitor
106
+ puts "Monitoring /var/harbr for new container versions..."
107
+ last_known_state = {}
86
108
 
87
- @@listener = Listen.to(directory) do |modified, added, removed|
88
- job_created = false
109
+ loop do
110
+ current_state = scan_for_containers
111
+ new_versions = current_state.keys - last_known_state.keys
89
112
 
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
113
+ new_versions.each do |container_version|
114
+ container, version = container_version.split("/versions/")
115
+ place(container, version)
99
116
  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
117
 
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."
118
+ last_known_state = current_state
119
+ sleep 10 # Poll every 10 seconds
133
120
  end
134
121
  end
135
122
 
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
123
  end
143
124
 
144
125
  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.10"
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.10
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