harbr 0.0.7 → 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: 7f443b2cf3d0a2248b626944763782d7dc765f2bd83502d2920df8b8f736c648
4
- data.tar.gz: fe4ba28730e10fce57824b766e5ca095104144d190df1cbb794ba94195012bdb
3
+ metadata.gz: ba1c2de0c57a31b1b85b0f7140e05995404a1a013502c6d01a965f709bb8b3b3
4
+ data.tar.gz: 95d574f90f0c21d580a924f3e8318b8af529ff2ded73574825bda2c65aa30640
5
5
  SHA512:
6
- metadata.gz: 229b3eb7da67df05de20323697246bf0a0375818a0ff5fcadee0fc1566477bff58fe633334277ac7668805862b22e862cfe80de3c4eacf39dada6c499ebc8069
7
- data.tar.gz: 78958f5ef51f6f0efa87e8be314bdc45ca72dd1381ea4ba447e347fa41b8237c1ec3ef854add085dc69e52c6295c0efb3dcdd9ea27a684138c42688ba724aafb
6
+ metadata.gz: f5b081f4e73595bd8597fa05aa97dc2612869f9a96340df638fb6109859657e34909c3b0532d5bc2b1b76a67e07cb31d3e52c868f0740de5fbcad26ea118a37f
7
+ data.tar.gz: 5c99af944a71d9f31ef2412bdeb1cdbef04ed32e81df82259596a82397f90a21aac10770cffd196616e149ba4291fe10d94ed6aec3058f6c888004aaacd31a42
File without changes
File without changes
Binary file
Binary file
data/exe/harbr CHANGED
@@ -1,28 +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
16
  def display_containers_table(containers)
22
17
  return puts "No containers available." if containers.empty?
23
18
 
24
19
  # Define headers based on Container attributes
25
- headers = ['Name', 'Host Header', 'IP', 'Port']
20
+ headers = ["Name", "Host Header", "IP", "Port"]
26
21
 
27
22
  rows = containers.map do |container|
28
23
  [container.name, container.host_header, container.ip, container.port]
@@ -36,7 +31,6 @@ class HarbrCLI < Thor
36
31
  puts ""
37
32
  end
38
33
 
39
-
40
34
  def check_and_create_directory(path)
41
35
  unless Dir.exist?(path)
42
36
  puts "Creating directory: #{path}"
@@ -58,81 +52,59 @@ class HarbrCLI < Thor
58
52
  system("sudo apt install #{package}") or raise "Failed to install #{package}"
59
53
  end
60
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
+
61
68
  end
62
69
 
63
70
  desc "setup", "Set up Harbr environment"
64
71
  def setup
65
72
  # Check and create /var/harbr directory
66
- check_and_create_directory('/var/harbr')
73
+ check_and_create_directory("/var/harbr")
67
74
 
68
75
  # Check for Ruby, Traefik, and runit, and install if necessary
69
- install_with_snap('ruby') unless command_exists?('ruby')
70
- install_with_snap('traefik') unless command_exists?('traefik')
71
- 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")
72
79
 
73
80
  puts "Setup completed successfully."
74
81
  end
75
- desc "start [DIRECTORY]", "Start listening to a directory for changes"
76
- def start(directory = DEFAULT_DIRECTORY)
77
- return if @@listener
78
-
79
- puts "Starting Harbr, listening to #{directory}"
80
-
81
- @@listener = Listen.to(directory) do |modified, added, removed|
82
- unless added.empty?
83
- added.each do |path|
84
- /\/var\/harbr\/(?<container>.*)\/versions\/(?<version>\d*)\/config\/manifest.yml/.match(path)
85
- if $1
86
- Harbr::Container::Job.perform_async($1)
87
- break
88
- end
89
-
90
- end
91
- end
92
82
 
93
- end
94
- @@listener.start # not blocking
95
- sleep
83
+ desc "containers", "show all containers"
84
+ def containers
85
+ container_repo = Harbr::Container::Repository.new
86
+ display_containers_table(container_repo.all)
96
87
  end
97
88
 
98
- desc "stop", "Stop Harbr"
99
- def stop
100
- if @@listener
101
- @@listener.stop
102
- @@listener = nil
103
- puts "Harbr has been stopped."
104
- else
105
- puts "Harbr is not running."
106
- end
107
- end
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 = {}
108
93
 
109
- desc "pause", "Pause Harbr"
110
- def pause
111
- if @@listener
112
- @@listener.pause
113
- puts "Harbr has been paused."
114
- else
115
- puts "Harbr is not running or already paused."
116
- end
117
- end
94
+ loop do
95
+ current_state = scan_for_containers
96
+ new_versions = current_state.keys - last_known_state.keys
118
97
 
119
- desc "resume", "Resume Harbr"
120
- def resume
121
- if @@listener
122
- @@listener.start
123
- puts "Harbr has been resumed."
124
- else
125
- puts "Harbr is not running or already active."
126
- end
127
- end
98
+ new_versions.each do |container_version|
99
+ container, version = container_version.split("/versions/")
100
+ place(container, version)
101
+ end
128
102
 
129
- desc "containers", "show all containers"
130
- def containers
131
- container_repo = Harbr::Container::Repository.new
132
- display_containers_table(container_repo.all)
103
+ last_known_state = current_state
104
+ sleep 10 # Poll every 10 seconds
105
+ end
133
106
  end
134
107
 
135
108
  end
136
109
 
137
110
  HarbrCLI.start(ARGV)
138
-
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.7"
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.7
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