lbhrr 1.0.6 → 1.0.10

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: 14f484333308696cc1f728428f328b3c8330b466ddd7dabbcf0bfe7bf61f22fb
4
- data.tar.gz: b0b574e3cc24289433bf65f312812732615f8e62045b2c31e84068a38eaeb0c3
3
+ metadata.gz: '008a4e46f26124d5ddb1ff4a332779770038696ed6a2cfb2b1c8a6de7dddefdc'
4
+ data.tar.gz: 41a0c0acd33bd7a31c361fa6f626909011e69be41933c77e688544ecc5800991
5
5
  SHA512:
6
- metadata.gz: f861df26bfb215ecfa3adff8fabb2887df18dfd70dfe7f6ab5abf5dbda58419554db12ac3dfb067ae5849a49f52122504d2688afdcf7fa056b5237ee3f563c3b
7
- data.tar.gz: 3eac4bdf9442f160a75c8e6a22e8e28169d7c0b14c71572a1361d1c6d6cbabaf18d96a37caa0b0f6f69c80e5e3d169036c33d6f8102ce05a133edf05f4f367dd
6
+ metadata.gz: 807c2b1f37b43aad26e88c195250452635107b12e32e15dd5f48894ef50c37e10b36620ec84844f1734becc133a32e970e179f774b071718b79f278d68b689dd
7
+ data.tar.gz: a40ef0cbf0be98afff535f95b864988cf022a8ba35d8e5909715eeaab866791eed1bdf0290dc483d17e2a333b3fbb7fb4fcb44ce88fd9714d9a0be470a1a7ada
@@ -0,0 +1,5 @@
1
+ ---
2
+ name: lbhrr
3
+ version: '0'
4
+ port:
5
+ host: lbhrr.harbr.zero2one.ee
data/exe/lbhrr CHANGED
@@ -1,31 +1,53 @@
1
1
  #!/usr/bin/env ruby
2
- require 'thor'
3
- require 'yaml'
4
- require 'tempfile'
5
- require 'fileutils'
2
+ require_relative "../lib/lbhrr"
6
3
 
7
4
  class LbhrrCLI < Thor
8
5
  no_commands do
6
+ def package
7
+ # Load configuration
8
+ config = load_configuration
9
+ host = config["host"]
10
+ user = config["user"]
11
+ port = config["port"]
12
+ version = config["version"].to_i
13
+ raise "Configuration error: Host, User, or Version missing" unless host && port && user && version > 0
14
+
15
+ # Check for a git repository
16
+ unless `git rev-parse --is-inside-work-tree > /dev/null 2>&1`
17
+ raise "No Git repository found in the current directory"
18
+ end
19
+
20
+ # Delete vendor directory if it exists
21
+ vendor_path = File.join(Dir.pwd, "vendor")
22
+ FileUtils.rm_rf(vendor_path) if Dir.exist?(vendor_path)
23
+ `bundle config set --local path 'vendor/bundle'`
24
+ `bundle install` or raise "Bundle install failed"
25
+ # Check if the repository is clean
26
+ puts "Git repository is dirty, committing changes..."
27
+ `git add .` or raise "Failed to add changes to Git"
28
+ `git commit -m 'packaged #{version}'` or raise "Failed to commit changes to Git"
29
+ puts "Packaging completed successfully."
30
+ rescue => e
31
+ puts "Packaging error: #{e.message}"
32
+ end
9
33
 
10
34
  def amend_last_commit(new_message)
11
- begin
12
- # Ensure we are in a git repository
13
- system("git rev-parse --git-dir > /dev/null 2>&1") or raise "Not a git repository"
35
+ # Ensure we are in a git repository
36
+ system("git rev-parse --git-dir > /dev/null 2>&1") or raise "Not a git repository"
14
37
 
15
- # Amend the last commit with the new message
16
- system("git commit --amend -m \"#{new_message}\"") or raise "Failed to amend the last commit"
38
+ # Amend the last commit with the new message
39
+ system("git commit --amend -m \"#{new_message}\"") or raise "Failed to amend the last commit"
17
40
 
18
- puts "Successfully amended the last commit."
19
- rescue => e
20
- puts "Error during commit amend: #{e.message}"
21
- end
41
+ puts "Successfully amended the last commit."
42
+ rescue => e
43
+ puts "Error during commit amend: #{e.message}"
22
44
  end
23
45
 
24
46
  def create_gitignore
25
- gitignore_path = File.join(Dir.pwd, '.gitignore')
47
+ gitignore_path = File.join(Dir.pwd, ".gitignore")
26
48
  return if File.exist?(gitignore_path)
27
49
 
28
- gitignore_content = %q{
50
+ gitignore_content = '
29
51
  # Ignore bundler config and installed gems.
30
52
  /.bundle
31
53
  # Ignore all logfiles and tempfiles.
@@ -42,7 +64,7 @@ class LbhrrCLI < Thor
42
64
  .DS_Store
43
65
  .idea
44
66
  .byebug_history
45
- }
67
+ '
46
68
 
47
69
  File.write(gitignore_path, gitignore_content.strip)
48
70
  puts ".gitignore created for Rack project."
@@ -50,11 +72,10 @@ class LbhrrCLI < Thor
50
72
  puts "Error creating .gitignore: #{e.message}"
51
73
  end
52
74
 
53
- def deployed(version)
75
+ def deployed(local_manifest_path, version)
54
76
  # Git add all changes
77
+ increment_version(local_manifest_path, version)
55
78
  system("git add .") or raise "Failed to add changes to Git"
56
-
57
-
58
79
  # Commit changes with a message
59
80
  commit_message = "Deployed version #{version}"
60
81
  amend_last_commit commit_message
@@ -69,26 +90,41 @@ class LbhrrCLI < Thor
69
90
 
70
91
  def create_example_global_config
71
92
  example_global_config = {
72
- 'user' => 'root',
73
- 'host' => 'harbr.zero2one.ee'
93
+ "user" => "root",
94
+ "host" => "harbr.zero2one.ee"
74
95
  }
75
96
  YAML.dump(example_global_config)
76
97
  end
77
98
 
99
+ def create_run_file
100
+ run_file_path = File.join(Dir.pwd, "exe", "run")
101
+ run_file_content = "#!/bin/sh\nbundle exec puma -p $1"
102
+ exe_directory = File.join(Dir.pwd, "exe")
103
+
104
+ Dir.mkdir(exe_directory) unless Dir.exist?(exe_directory)
105
+ File.write(run_file_path, run_file_content)
106
+ File.chmod(0o755, run_file_path) # Set executable permission
107
+
108
+ puts "Created ./exe/run file."
109
+ rescue => e
110
+ puts "Error creating ./exe/run file: #{e.message}"
111
+ end
112
+
78
113
  def create_example_local_config
79
114
  example_local_config = {
80
- 'name' => File.basename(Dir.pwd),
81
- 'version' => '0',
82
- 'host' => "#{File.basename(Dir.pwd)}.harbr.zero2one.ee'"
115
+ "name" => File.basename(Dir.pwd),
116
+ "version" => "0",
117
+ "port" => "#{File.basename(Dir.pwd)}.app",
118
+ "host" => "#{File.basename(Dir.pwd)}.harbr.zero2one.ee"
83
119
  }
84
120
 
85
121
  YAML.dump(example_local_config)
86
122
  end
87
123
 
88
124
  def load_configuration
89
- global_config_dir = File.expand_path('~/.config/harbr')
90
- global_config_path = File.join(global_config_dir, 'harbr.manifest.yml')
91
- local_config_path = File.join(Dir.pwd, 'config', 'manifest.yml')
125
+ global_config_dir = File.expand_path("~/.config/harbr")
126
+ global_config_path = File.join(global_config_dir, "harbr.manifest.yml")
127
+ local_config_path = File.join(Dir.pwd, "config", "manifest.yml")
92
128
 
93
129
  # Ensure global configuration exists
94
130
  unless File.exist?(global_config_path)
@@ -99,7 +135,7 @@ class LbhrrCLI < Thor
99
135
  # Ensure local configuration exists
100
136
  unless File.exist?(local_config_path)
101
137
  FileUtils.mkdir_p(File.dirname(local_config_path)) unless Dir.exist?(File.dirname(local_config_path))
102
- File.write(local_config_path, create_example_local_config())
138
+ File.write(local_config_path, create_example_local_config)
103
139
  end
104
140
 
105
141
  # Load and merge configurations
@@ -112,108 +148,134 @@ class LbhrrCLI < Thor
112
148
  new_version = current_version + 1
113
149
 
114
150
  manifest = YAML.load_file(manifest_path)
115
- manifest['version'] = new_version
116
- File.open(manifest_path, 'w') { |file| file.write(manifest.to_yaml) }
151
+ manifest["version"] = new_version
152
+ File.write(manifest_path, manifest.to_yaml)
117
153
  puts "Version incremented to #{new_version}"
118
-
119
154
  end
120
-
121
155
  end
122
156
 
123
157
  desc "init", "Initialize project with .gitignore"
124
158
  def init
125
-
126
- local_config_path = File.join(Dir.pwd, 'config', 'manifest.yml')
159
+ local_config_path = File.join(Dir.pwd, "config", "manifest.yml")
127
160
 
128
161
  unless File.exist?(local_config_path)
129
162
  FileUtils.mkdir_p(File.dirname(local_config_path)) unless Dir.exist?(File.dirname(local_config_path))
130
- File.write(local_config_path, create_example_local_config())
163
+ File.write(local_config_path, create_example_local_config)
131
164
  end
132
165
  # Load and merge configurations
133
166
  local_config = YAML.load_file(local_config_path) || {}
134
167
  create_gitignore
168
+ create_run_file
169
+
135
170
 
136
171
  # Include other initialization tasks if necessary
137
172
  end
138
173
 
139
- desc "package", "Prepare the application for deployment"
140
- def package
141
- begin
142
- # Load configuration
143
- config = load_configuration
144
- host = config['host']
145
- user = config['user']
146
- version = config['version'].to_i
147
- raise "Configuration error: Host, User, or Version missing" unless host && user && version > 0
174
+ desc "containers", "list all containers"
175
+ def containers
176
+ config = load_configuration
177
+ host = config["host"]
178
+ user = config["user"]
179
+ puts `ssh #{user}@#{host} 'harbr containers'`
180
+ end
148
181
 
149
- # Check for a git repository
150
- unless system("git rev-parse --is-inside-work-tree > /dev/null 2>&1")
151
- raise "No Git repository found in the current directory"
152
- end
182
+ desc "drop", "Destroy an app and remove all traces"
183
+ def drop
184
+ container_name = File.basename(Dir.pwd)
185
+ config = load_configuration
186
+ host = config["host"]
187
+ user = config["user"]
188
+ puts "Destroying app: #{container_name}"
189
+ `ssh #{user}@#{host} 'harbr destroy #{container_name}'`
153
190
 
154
- # Delete vendor directory if it exists
155
- vendor_path = File.join(Dir.pwd, 'vendor')
156
- FileUtils.rm_rf(vendor_path) if Dir.exist?(vendor_path)
157
- system("bundle install --path vendor/bundle") or raise "Bundle install failed"
158
- # Check if the repository is clean
159
- puts "Git repository is dirty, committing changes..."
160
- system("git add .") or raise "Failed to add changes to Git"
161
- system("git commit -m 'packaged #{version}'") or raise "Failed to commit changes to Git"
191
+ current_dir = Dir.pwd
192
+ parent_dir = File.dirname(current_dir)
193
+
194
+ # Requesting confirmation
195
+ if yes? "Are you sure you want to delete the directory: #{current_dir}? [y/N]"
196
+ # Proceeding with deletion
197
+ puts "Changing directory to the parent directory..."
198
+ Dir.chdir(parent_dir)
199
+
200
+ puts "Deleting the directory: #{current_dir}"
201
+ FileUtils.rm_rf(current_dir)
202
+
203
+ Dir.chdir(parent_dir)
204
+
205
+ puts "#{current_dir} has been deleted."
162
206
 
163
- puts "Packaging completed successfully."
164
- rescue => e
165
- puts "Packaging error: #{e.message}"
166
207
  end
208
+
209
+ puts "App #{container_name} has been successfully destroyed."
167
210
  end
168
211
 
212
+ desc "raise", "Deploy an application using the configuration from config/manifest.yml to staging"
213
+ def raise
214
+ package
169
215
 
170
- desc "deploy", "Deploy an application using the configuration from config/manifest.yml"
171
- def deploy
172
- begin
173
- package
216
+ config = load_configuration
217
+ host = config["host"]
218
+ user = config["user"]
219
+ raise "Host configuration missing" unless host
174
220
 
175
- config = load_configuration
176
- host = config['host']
177
- user = config['user']
178
- raise "Host configuration missing" unless host
179
-
180
- local_manifest_path = File.join(Dir.pwd, 'config', 'manifest.yml')
181
- raise "Local manifest file not found at #{local_manifest_path}" unless File.exist?(local_manifest_path)
182
-
183
- local_config = YAML.load_file(local_manifest_path) || {}
184
- version = local_config['version'].to_i
185
- raise "Version not specified in manifest.yml" unless version
186
-
187
- basename = File.basename(Dir.pwd)
188
- base_directory = "/var/harbr/#{basename}"
189
- versions_directory = "#{base_directory}/versions"
190
- destination_path = "#{versions_directory}/#{version}"
191
- current_path = "#{base_directory}/current"
192
-
193
- # Check and create the versions directory on the server
194
- system("ssh #{user}@#{host} 'mkdir -p #{versions_directory}'")
195
-
196
- # Prepare the rsync exclude option using .gitignore
197
- gitignore_path = File.join(Dir.pwd, '.gitignore')
198
- exclude_option = File.exist?(gitignore_path) ? "--exclude='.git' --exclude-from='#{gitignore_path}'" : ""
199
-
200
- # Rsync files to the new version directory, excluding files as per .gitignore
201
- rsync_command = "rsync -avz #{exclude_option} ./ #{user}@#{host}:#{destination_path}"
202
-
203
- if system(rsync_command) &&
204
- system("ssh #{user}@#{host} 'ln -sfn #{destination_path} #{current_path}'")
205
- puts "Successfully deployed application version #{version} to #{host}"
206
- increment_version(local_manifest_path, version)
207
- deployed(version)
208
- else
209
- puts "Failed to deploy application version #{version} to #{host}"
210
- end
211
- rescue => e
212
- puts "Deployment error: #{e.message}"
221
+ local_manifest_path = File.join(Dir.pwd, "config", "manifest.yml")
222
+ raise "Local manifest file not found at #{local_manifest_path}" unless File.exist?(local_manifest_path)
223
+
224
+ local_config = YAML.load_file(local_manifest_path) || {}
225
+ version = local_config["version"].to_i
226
+ raise "Version not specified in manifest.yml" unless version
227
+
228
+ basename = File.basename(Dir.pwd)
229
+ base_directory = "/var/harbr/containers/#{basename}"
230
+ versions_directory = "#{base_directory}/versions"
231
+ destination_path = "#{versions_directory}/#{version}"
232
+ current_path = "#{base_directory}/current"
233
+
234
+ # Check and create the versions directory on the server
235
+ `ssh #{user}@#{host} 'mkdir -p #{versions_directory}'`
236
+
237
+ # Prepare the rsync exclude option using .gitignore
238
+ gitignore_path = File.join(Dir.pwd, ".gitignore")
239
+ exclude_option = File.exist?(gitignore_path) ? "--exclude='.git' --exclude-from='#{gitignore_path}'" : ""
240
+
241
+ # Rsync files to the new version directory, excluding files as per .gitignore
242
+ rsync_command = "rsync -avz #{exclude_option} ./ #{user}@#{host}:#{destination_path}"
243
+
244
+ if `#{rsync_command}` &&
245
+ `ssh #{user}@#{host} 'ln -sfn #{destination_path} #{current_path}'`
246
+ puts "Successfully deployed application version #{version} to #{host}"
247
+ deployed(local_manifest_path, version)
248
+ else
249
+ puts "Failed to deploy application version #{version} to #{host}"
213
250
  end
251
+ rescue => e
252
+ puts "Deployment error: #{e.message}"
253
+ end
254
+
255
+ desc "logs", "Show logs for a container"
256
+ def logs
257
+ container_name = File.basename(Dir.pwd)
258
+ config = load_configuration
259
+ host = config["host"]
260
+ user = config["user"]
261
+ exec "ssh #{user}@#{host} 'harbr logs #{container_name}'"
214
262
  end
215
263
 
216
264
 
265
+
266
+ desc "hoist", "Deploy an application using the configuration from config/manifest.yml to production"
267
+ def hoist
268
+ config = load_configuration
269
+ host = config["host"]
270
+ user = config["user"]
271
+ name = config["name"]
272
+
273
+ puts `ssh #{user}@#{host} 'harbr deploy #{name}'`
274
+ end
275
+
276
+ def self.exit_on_failure?
277
+ true
278
+ end
217
279
  end
218
280
 
219
281
  LbhrrCLI.start(ARGV)
data/lbhrr.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/dekubu/lbhrr"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 2.6.0"
16
-
16
+
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = "https://github.com/dekubu/lbhrr"
19
19
  spec.metadata["changelog_uri"] = "https://github.com/dekubu/lbhrr/CHANGELOG.md"
data/lib/lbhrr/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lbhrr
4
- VERSION = "1.0.6"
4
+ VERSION = "1.0.10"
5
5
  end
data/lib/lbhrr.rb CHANGED
@@ -1,9 +1,19 @@
1
1
  # frozen_string_literal: true
2
- require "yaml"
3
2
 
3
+ require "yaml"
4
+ require "thor"
5
+ require "yaml"
6
+ require "tempfile"
7
+ require "fileutils"
4
8
  require_relative "lbhrr/version"
5
9
 
6
10
  module Lbhrr
7
11
  class Error < StandardError; end
12
+
13
+ class SelfDelete
14
+ def delete_current_directory
15
+ end
16
+ end
17
+
8
18
  # Your code goes here...
9
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lbhrr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delaney Kuldvee Burke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-07 00:00:00.000000000 Z
11
+ date: 2023-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -47,6 +47,7 @@ files:
47
47
  - Rakefile
48
48
  - bin/console
49
49
  - bin/setup
50
+ - config/manifest.yml
50
51
  - exe/lbhrr
51
52
  - hero.png
52
53
  - lbhrr.gemspec