firespring_dev_commands 2.1.28 → 2.1.29.pre.alpha.2

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: 887cf6fa6942ca683459b0a7325fee216656f7575f750932a0236a3a67246f4c
4
- data.tar.gz: b238f37f30f93e543018915924c8a2aefde74b771400846804bf974649711a76
3
+ metadata.gz: baa5ac0c4b177560aa4b26d69a90e73922c0d08f1754998810e4340506ca4c4f
4
+ data.tar.gz: e5fc7ec49280a1a12b960d95f8c1247372d463ca55d4df175064d60337fad6fe
5
5
  SHA512:
6
- metadata.gz: b2e3bd5b15893d2397969c0cc5a7f1aa1c64603dec853b415f81d71fac90450126ee68ffa8a4f1d20093e44453a2ad1a501529c2defca1f8689b67456760ccf9
7
- data.tar.gz: a845da667386b9c289ce4dfc4f121a734271b8ef6347f1ab77aa08f179e77947c4c6c80176cae6407aacb068d0c6058c75d836ace68cf4b6cd97fb595bd22372
6
+ metadata.gz: 3c72a389ad590e3359ee71f2be1824d806bc5fc82e8ec8154d3c268ee39a1bca8c68e810e15b38f1d04542c809bf7bdbe623639c4e9202fcb40e7825e5e423e4
7
+ data.tar.gz: 15a2b5e3560c8f813f501c0e41094571149cf35003cb2733a66e1de45c127074fdad3371de92aab18aaeb6831c9ae013e52f41d03a59813fc6cb3e20b8e169b6
@@ -196,5 +196,16 @@ module Dev
196
196
  center_str = string.length / 2
197
197
  string.rjust(center_dash + center_str - 1, pad).ljust(len - 1, pad)
198
198
  end
199
+
200
+ # Print the given filesize using the most appropriate units
201
+ def filesize(size)
202
+ return '0.0 B' if size.to_i.zero?
203
+
204
+ units = %w(B KB MB GB TB Pb EB)
205
+ exp = (Math.log(size) / Math.log(1024)).to_i
206
+ exp = 6 if exp > 6
207
+
208
+ format('%.1f %s', size.to_f / (1024**exp), units[exp])
209
+ end
199
210
  end
200
211
  end
@@ -103,7 +103,7 @@ module Dev
103
103
  LOG.info "\nDeleted #{type.capitalize}"
104
104
  deleted_items = info["#{type}Deleted"] || []
105
105
  deleted_items.each { |it| LOG.info " #{it}" }
106
- LOG.info "Total reclaimed space: #{filesize(info['SpaceReclaimed'])}"
106
+ LOG.info "Total reclaimed space: #{Dev::Common.new.filesize(info['SpaceReclaimed'])}"
107
107
  end
108
108
 
109
109
  # Print the given filesize using the most appropriate units
@@ -182,28 +182,53 @@ module Dev
182
182
  end
183
183
 
184
184
  # Copies the source path on your local machine to the destination path on the container
185
- def copy_to_container(container, source_path, dest_path)
186
- dest_path = File.join(working_dir(container), dest_path) unless dest_path.start_with?(File::SEPARATOR)
187
- LOG.info "Copying #{source_path} to #{dest_path}... "
188
-
189
- container.archive_in(source_path, dest_path, overwrite: true)
190
- return unless File.directory?(source_path)
191
-
192
- dest_file = File.basename(source_path)
193
- # TODO: Can we find a better solution for this? Seems pretty brittle
194
- retcode = container.exec(['bash', '-c', "cd #{dest_path}; tar -xf #{dest_file}; rm -f #{dest_file}"])[-1]
195
- raise 'Unable to unpack on container' unless retcode.zero?
185
+ def copy_to_container(container, source, destination)
186
+ # Add the working dir of the container onto the destination (if it doesn't start a path separator)
187
+ destination = File.join(working_dir(container), destination) unless destination.start_with?(File::SEPARATOR)
188
+ LOG.info "Copying #{source} to #{destination}..."
189
+
190
+ # Need to determine the type of the destination (file or directory or nonexistant)
191
+ noexist_code = 22
192
+ file_code = 33
193
+ directory_code = 44
194
+ unknown_code = 55
195
+ filetype_cmd = [
196
+ 'bash',
197
+ '-c',
198
+ "set -e; [ ! -e '#{destination}' ] && exit #{noexist_code}; [ -f '#{destination}' ] " \
199
+ "&& exit #{file_code}; [ -d '#{destination}' ] && exit #{directory_code}; exit #{unknown_code}"
200
+ ]
201
+ destination_filetype_code = container.exec(filetype_cmd).last
202
+
203
+ # If destination_filetype_code is a file - that means the user passed in a destination filename
204
+ # Unfortunately the archive_in command does not support that so we will strip it off and use it later (if needed)
205
+ source_filename = File.basename(source)
206
+ destination_filename = File.basename(source)
207
+ destination, _, destination_filename = destination.rpartition(File::SEPARATOR) if destination_filetype_code == file_code
208
+
209
+ container.archive_in(source, destination, overwrite: true)
210
+
211
+ if File.directory?(source)
212
+ # If the source was a directory, then the archive_in command leaves it as a tar on the system - so we need to unpack it
213
+ # TODO: Can we find a better solution for this? Seems pretty brittle
214
+ retcode = container.exec(['bash', '-c', "cd #{destination}; tar -xf #{destination_filename}; rm -f #{destination_filename}"]).last
215
+ raise 'Unable to unpack on container' unless retcode.zero?
216
+ elsif destination_filetype_code == file_code && source_filename != destination_filename
217
+ # If the destination was a file _and_ the filename is different than the source filename, then we need to rename it
218
+ retcode = container.exec(['bash', '-c', "cd #{destination}; mv #{source_filename} #{destination_filename}"]).last
219
+ raise "Unable to rename '#{source_filename}' to '#{destination_filename}' on container" unless retcode.zero?
220
+ end
196
221
  end
197
222
 
198
223
  # Copies the source path on the container to the destination path on your local machine
199
224
  # If required is set to true, the command will fail if the source path does not exist on the container
200
- def copy_from_container(container, source_path, dest_path, required: true)
201
- source_path = File.join(working_dir(container), source_path) unless source_path.start_with?(File::SEPARATOR)
202
- LOG.info "Copying #{source_path} to #{dest_path}... "
225
+ def copy_from_container(container, source, destination, required: true)
226
+ source = File.join(working_dir(container), source) unless source.start_with?(File::SEPARATOR)
227
+ LOG.info "Copying #{source} to #{destination}..."
203
228
 
204
229
  tar = StringIO.new
205
230
  begin
206
- container.archive_out(source_path) do |chunk|
231
+ container.archive_out(source) do |chunk|
207
232
  tar.write(chunk)
208
233
  end
209
234
  rescue => e
@@ -212,7 +237,7 @@ module Dev
212
237
  puts 'Not Found'
213
238
  end
214
239
 
215
- Dev::Tar.new(tar).unpack(source_path, dest_path)
240
+ Dev::Tar.new(tar).unpack(source, destination)
216
241
  end
217
242
 
218
243
  # rubocop:disable Metrics/ParameterLists
@@ -250,7 +275,7 @@ module Dev
250
275
  arch = "#{arch}/#{variant}" if variant
251
276
  id = image.info&.dig('id')&.split(':')&.last&.slice(0..11)
252
277
  created = timesince(Time.at(image.info&.dig('Created')))
253
- size = filesize(image.info&.dig('Size'))
278
+ size = Dev::Common.new.filesize(image.info&.dig('Size'))
254
279
 
255
280
  repo_urls = image.info&.dig('RepoTags')
256
281
  repo_urls ||= ["#{image.info&.dig('RepoDigests')&.first&.split(':')&.first&.split('@')&.first}:<none>"]
@@ -6,6 +6,6 @@ module Dev
6
6
  # Use 'v.v.v.pre.alpha.v' for pre-release vesions
7
7
  # Use 'v.v.v.beta.v for beta versions
8
8
  # Use semantic versioning for any releases (https://semver.org/)
9
- VERSION = '2.1.28'.freeze
9
+ VERSION = '2.1.29.pre.alpha.2'.freeze
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firespring_dev_commands
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.28
4
+ version: 2.1.29.pre.alpha.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firespring
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-25 00:00:00.000000000 Z
11
+ date: 2024-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -412,9 +412,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
412
412
  version: '3.1'
413
413
  required_rubygems_version: !ruby/object:Gem::Requirement
414
414
  requirements:
415
- - - ">="
415
+ - - ">"
416
416
  - !ruby/object:Gem::Version
417
- version: '0'
417
+ version: 1.3.1
418
418
  requirements: []
419
419
  rubygems_version: 3.4.10
420
420
  signing_key: