lbhrr 0.0.0.alpha → 1.0.0

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: 5c9cf9e1c5896965605d6b674480ce633bebb47bb5b6b07a35037d7e609716df
4
- data.tar.gz: 6a89bfd4cf4776703e8e372d4ec4a7ad74e1ca26503fddb720e844d0214e3bf8
3
+ metadata.gz: fffc06ffb0010dbc2c65b66567a13f3da1ec40c38455e94752759b6c7e9b2d92
4
+ data.tar.gz: 89ca58e74fbdcd9e7bc2bd46b972c39249d510e3d3a1731dffc57f1edcce45e5
5
5
  SHA512:
6
- metadata.gz: f3ba873bea875fef4356e0dad0fe63417643e2e93ee1620d98a5c59b4e5a51404fe7d8c5fc139e8b7d9f4c2f4425ebd9f7cac178a3b48837ec2f527e5c7486b3
7
- data.tar.gz: fb0ee262b5b64502920ef69844b1228334de2abb2557ed37e4bc8bdf6074d2f2a771c22767d0fa52651ea2b646612652211f665a9fc5c4bda7fbfec8eee87c69
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
- 'harbr' => 'harbr.zero2one.ee'
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
- 'name' => 'name',
19
- 'host' => 'example.com'
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
- desc "deploy", "Deploy an application using the configuration from harbr.manifest.yml"
52
- def deploy
53
- config = load_configuration
54
- source = config['source']
55
- harbr = config['harbr']
56
- # Implement deployment logic using source and harbr
57
- puts "Deploying application from #{source} to #{harbr}..."
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
- desc "status HARBR", "Check the status of the application on the HARBR server"
60
- def status(harbr)
61
- # Implement status checking logic
62
- puts "Checking application status on #{harbr}..."
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
- desc "rollback HARBR VERSION", "Rollback the application on the HARBR server to a specified VERSION"
66
- def rollback(harbr, version)
67
- # Implement rollback logic
68
- puts "Rolling back application on #{harbr} to version #{version}..."
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lbhrr
4
- VERSION = "0.0.0.alpha"
4
+ VERSION = "1.0.0"
5
5
  end
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: 0.0.0.alpha
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: 1.3.1
76
+ version: '0'
78
77
  requirements: []
79
78
  rubygems_version: 3.4.21
80
79
  signing_key:
data/config/manifest.yml DELETED
@@ -1,3 +0,0 @@
1
- ---
2
- name: name
3
- host: example.com