lbhrr 0.0.0.alpha → 1.0.0
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 +4 -4
- data/exe/lbhrr +177 -27
- data/lib/lbhrr/version.rb +1 -1
- metadata +3 -4
- data/config/manifest.yml +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fffc06ffb0010dbc2c65b66567a13f3da1ec40c38455e94752759b6c7e9b2d92
|
4
|
+
data.tar.gz: 89ca58e74fbdcd9e7bc2bd46b972c39249d510e3d3a1731dffc57f1edcce45e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90ab791268e10b4846a8679a66ab1a666e9c3bf16f753681babe97f7c2ca2e2baf457b454763ce0407635f2dc423fdcc9011f0abbfacf4963fa168b237222169
|
7
|
+
data.tar.gz: 39021ee7bbf173c16e2afd5a89ba7cfe1d38c1834f984fd91493cb15225d2f27a05c92d9d58a6f45a7b0df317487ab90c159156cb8d03a2ad689f97747aab899
|
data/exe/lbhrr
CHANGED
@@ -1,74 +1,224 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'thor'
|
3
3
|
require 'yaml'
|
4
|
+
require 'tempfile'
|
4
5
|
require 'fileutils'
|
5
6
|
|
6
7
|
class LbhrrCLI < Thor
|
7
8
|
no_commands do
|
8
9
|
|
10
|
+
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"
|
14
|
+
|
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"
|
17
|
+
|
18
|
+
puts "Successfully amended the last commit."
|
19
|
+
rescue => e
|
20
|
+
puts "Error during commit amend: #{e.message}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_gitignore
|
25
|
+
gitignore_path = File.join(Dir.pwd, '.gitignore')
|
26
|
+
return if File.exist?(gitignore_path)
|
27
|
+
|
28
|
+
gitignore_content = %q{
|
29
|
+
# Ignore bundler config and installed gems.
|
30
|
+
/.bundle
|
31
|
+
# Ignore all logfiles and tempfiles.
|
32
|
+
/log/*
|
33
|
+
/tmp/*
|
34
|
+
!/log/.keep
|
35
|
+
!/tmp/.keep
|
36
|
+
|
37
|
+
# Ignore other unneeded files.
|
38
|
+
*.pid
|
39
|
+
*.swap
|
40
|
+
*.gem
|
41
|
+
*.rbc
|
42
|
+
.DS_Store
|
43
|
+
.idea
|
44
|
+
.byebug_history
|
45
|
+
}
|
46
|
+
|
47
|
+
File.write(gitignore_path, gitignore_content.strip)
|
48
|
+
puts ".gitignore created for Rack project."
|
49
|
+
rescue => e
|
50
|
+
puts "Error creating .gitignore: #{e.message}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def deployed(version)
|
54
|
+
# Git add all changes
|
55
|
+
system("git add .") or raise "Failed to add changes to Git"
|
56
|
+
|
57
|
+
|
58
|
+
# Commit changes with a message
|
59
|
+
commit_message = "Deployed version #{version}"
|
60
|
+
amend_last_commit commit_message
|
61
|
+
# Create a Git tag for the version
|
62
|
+
tag_message = "Deployment for version #{version}"
|
63
|
+
system("git tag -a 'v#{version}' -m '#{tag_message}'") or raise "Failed to create Git tag"
|
64
|
+
|
65
|
+
puts "Deployment changes committed and tagged as v#{version}."
|
66
|
+
rescue => e
|
67
|
+
puts "Error during post-deployment process: #{e.message}"
|
68
|
+
end
|
69
|
+
|
9
70
|
def create_example_global_config
|
10
71
|
example_global_config = {
|
11
|
-
'
|
72
|
+
'user' => 'root',
|
73
|
+
'host' => 'harbr.zero2one.ee'
|
12
74
|
}
|
13
75
|
YAML.dump(example_global_config)
|
14
76
|
end
|
15
77
|
|
16
78
|
def create_example_local_config
|
17
79
|
example_local_config = {
|
18
|
-
'
|
19
|
-
'host' =>
|
80
|
+
'version' => '0',
|
81
|
+
'host' => "#{File.basename(Dir.pwd)}.harbr.zero2one.ee'"
|
20
82
|
}
|
21
83
|
|
22
84
|
YAML.dump(example_local_config)
|
23
85
|
end
|
24
|
-
|
86
|
+
|
25
87
|
def load_configuration
|
26
88
|
global_config_dir = File.expand_path('~/.config/harbr')
|
27
89
|
global_config_path = File.join(global_config_dir, 'harbr.manifest.yml')
|
28
90
|
local_config_path = File.join(Dir.pwd, 'config', 'manifest.yml')
|
29
|
-
|
91
|
+
|
30
92
|
# Ensure global configuration exists
|
31
93
|
unless File.exist?(global_config_path)
|
32
94
|
FileUtils.mkdir_p(global_config_dir) unless Dir.exist?(global_config_dir)
|
33
95
|
File.write(global_config_path, create_example_global_config)
|
34
96
|
end
|
35
|
-
|
97
|
+
|
36
98
|
# Ensure local configuration exists
|
37
99
|
unless File.exist?(local_config_path)
|
38
100
|
FileUtils.mkdir_p(File.dirname(local_config_path)) unless Dir.exist?(File.dirname(local_config_path))
|
39
|
-
File.write(local_config_path, create_example_local_config)
|
101
|
+
File.write(local_config_path, create_example_local_config())
|
40
102
|
end
|
41
|
-
|
103
|
+
|
42
104
|
# Load and merge configurations
|
43
105
|
global_config = YAML.load_file(global_config_path) || {}
|
44
106
|
local_config = YAML.load_file(local_config_path) || {}
|
45
107
|
global_config.merge(local_config)
|
46
108
|
end
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
109
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
110
|
+
def increment_version(manifest_path, current_version)
|
111
|
+
new_version = current_version + 1
|
112
|
+
|
113
|
+
manifest = YAML.load_file(manifest_path)
|
114
|
+
manifest['version'] = new_version
|
115
|
+
File.open(manifest_path, 'w') { |file| file.write(manifest.to_yaml) }
|
116
|
+
puts "Version incremented to #{new_version}"
|
117
|
+
|
118
|
+
end
|
119
|
+
|
58
120
|
end
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
121
|
+
|
122
|
+
desc "init", "Initialize project with .gitignore"
|
123
|
+
def init
|
124
|
+
|
125
|
+
local_config_path = File.join(Dir.pwd, 'config', 'manifest.yml')
|
126
|
+
|
127
|
+
unless File.exist?(local_config_path)
|
128
|
+
FileUtils.mkdir_p(File.dirname(local_config_path)) unless Dir.exist?(File.dirname(local_config_path))
|
129
|
+
File.write(local_config_path, create_example_local_config())
|
130
|
+
end
|
131
|
+
# Load and merge configurations
|
132
|
+
local_config = YAML.load_file(local_config_path) || {}
|
133
|
+
create_gitignore
|
134
|
+
|
135
|
+
# Include other initialization tasks if necessary
|
136
|
+
end
|
137
|
+
|
138
|
+
desc "package", "Prepare the application for deployment"
|
139
|
+
def package
|
140
|
+
begin
|
141
|
+
# Load configuration
|
142
|
+
config = load_configuration
|
143
|
+
host = config['host']
|
144
|
+
user = config['user']
|
145
|
+
version = config['version'].to_i
|
146
|
+
raise "Configuration error: Host, User, or Version missing" unless host && user && version > 0
|
147
|
+
|
148
|
+
# Check for a git repository
|
149
|
+
unless system("git rev-parse --is-inside-work-tree > /dev/null 2>&1")
|
150
|
+
raise "No Git repository found in the current directory"
|
151
|
+
end
|
152
|
+
|
153
|
+
# Delete vendor directory if it exists
|
154
|
+
vendor_path = File.join(Dir.pwd, 'vendor')
|
155
|
+
FileUtils.rm_rf(vendor_path) if Dir.exist?(vendor_path)
|
156
|
+
system("bundle install --path vendor/bundle") or raise "Bundle install failed"
|
157
|
+
# Check if the repository is clean
|
158
|
+
puts "Git repository is dirty, committing changes..."
|
159
|
+
system("git add .") or raise "Failed to add changes to Git"
|
160
|
+
system("git commit -m 'packaged #{version}'") or raise "Failed to commit changes to Git"
|
161
|
+
|
162
|
+
puts "Packaging completed successfully."
|
163
|
+
rescue => e
|
164
|
+
puts "Packaging error: #{e.message}"
|
165
|
+
end
|
63
166
|
end
|
64
167
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
168
|
+
|
169
|
+
|
170
|
+
desc "deploy", "Deploy an application using the configuration from config/manifest.yml"
|
171
|
+
def deploy
|
172
|
+
begin
|
173
|
+
package
|
174
|
+
|
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
|
+
previous_version_path = "#{versions_directory}/#{version - 1}"
|
191
|
+
destination_path = "#{versions_directory}/#{version}"
|
192
|
+
current_path = "#{base_directory}/current"
|
193
|
+
|
194
|
+
# Check and create the versions directory on the server
|
195
|
+
system("ssh #{user}@#{host} 'mkdir -p #{versions_directory}'")
|
196
|
+
|
197
|
+
# Copy the previous version to the new version directory if it exists
|
198
|
+
system("ssh #{user}@#{host} '[ -d #{previous_version_path} ] && cp -R #{previous_version_path} #{destination_path} || mkdir -p #{destination_path}'")
|
199
|
+
|
200
|
+
# Obtain the list of files tracked by Git and write to a temp file
|
201
|
+
git_tracked_files = `git ls-files`.split("\n")
|
202
|
+
Tempfile.create('git_files') do |tempfile|
|
203
|
+
git_tracked_files.each { |file| tempfile.puts(file) }
|
204
|
+
tempfile.close
|
205
|
+
|
206
|
+
# Rsync files to the new version directory and update the symlink
|
207
|
+
if system("rsync -avz --files-from=#{tempfile.path} ./ #{user}@#{host}:#{destination_path}") &&
|
208
|
+
system("ssh #{user}@#{host} 'ln -sfn #{destination_path} #{current_path}'")
|
209
|
+
puts "Successfully deployed application version #{version} to #{host}"
|
210
|
+
increment_version(local_manifest_path, version)
|
211
|
+
deployed(version)
|
212
|
+
else
|
213
|
+
puts "Failed to deploy application version #{version} to #{host}"
|
214
|
+
end
|
215
|
+
end
|
216
|
+
rescue => e
|
217
|
+
puts "Deployment error: #{e.message}"
|
218
|
+
end
|
69
219
|
end
|
220
|
+
# new method goes here
|
70
221
|
|
71
|
-
# ... additional commands ...
|
72
222
|
end
|
73
223
|
|
74
224
|
LbhrrCLI.start(ARGV)
|
data/lib/lbhrr/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lbhrr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Delaney Kuldvee Burke
|
@@ -47,7 +47,6 @@ files:
|
|
47
47
|
- Rakefile
|
48
48
|
- bin/console
|
49
49
|
- bin/setup
|
50
|
-
- config/manifest.yml
|
51
50
|
- exe/lbhrr
|
52
51
|
- hero.png
|
53
52
|
- lbhrr.gemspec
|
@@ -72,9 +71,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
71
|
version: 2.6.0
|
73
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
73
|
requirements:
|
75
|
-
- - "
|
74
|
+
- - ">="
|
76
75
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
76
|
+
version: '0'
|
78
77
|
requirements: []
|
79
78
|
rubygems_version: 3.4.21
|
80
79
|
signing_key:
|
data/config/manifest.yml
DELETED