wslc-wip 0.17.2 → 0.17.3

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: ffab59f2ac2df1c7a566825b0ee97eeff0b515396b42f3b95b1067b361d3aa8c
4
- data.tar.gz: 9500d0b3842aa86f2aaabdc41b89986cad0c66fa0b765b130c6b37679212b985
3
+ metadata.gz: c00368614ae5c01c7f514957368d9533f2faf9be114cfd17c676fc70ebfec138
4
+ data.tar.gz: 86d094ead585366c91633a963d0436a0c68af10f5bda3dace5ab46485f714a4a
5
5
  SHA512:
6
- metadata.gz: 96991898c1e0b423ad14151ee6b7db24bc38c8ea84b7f5213c69d14d83786288faa5b2d1f71c94382611c0f4c569aa939333e66a3e050095b45a1d50b6ef4bb6
7
- data.tar.gz: 963d62e619fab36835541421ce7f1642a98e063ba916a0c466311d6138ddce53bf6cae3660dbdadd779272defe81898fa153d9be17a661c11be4c93bff8179e5
6
+ metadata.gz: 99cd7c6e59ccd6b64667ab7a179c240d96577f24296a93b801484f994570d6262ccc30d1535853a6cd7b4fb2a31f5e8145fa227aa637d7d9960f0aa794756a67
7
+ data.tar.gz: 13a319d2b312f709a5937711bb65d69a560e098bed809e3f5f76fc83bae419983f5f4dbb0ae541e5afa3c93b9a7fd290b9c963378b6f405cd4bb0ceb3900e274
@@ -14,37 +14,39 @@ module Wip
14
14
  @ignore = ignore || DockerIgnore.load(@root.join('.dockerignore'))
15
15
  end
16
16
 
17
- def stage
17
+ # on_progress fires once per file copied, as `|count, total|` — so a caller
18
+ # can show that staging a large context (thousands of small files can take
19
+ # tens of seconds) is still moving instead of looking hung.
20
+ def stage(on_progress: nil)
18
21
  return yield @root.to_s if @ignore.empty?
19
22
 
20
23
  Dir.mktmpdir('wip-build-context-') do |dir|
21
- copy_included_files(Pathname(dir))
24
+ copy_included_files(Pathname(dir), on_progress)
22
25
  yield dir
23
26
  end
24
27
  end
25
28
 
26
29
  private
27
30
 
28
- def copy_included_files(destination)
29
- each_included_file do |relative_path|
31
+ def copy_included_files(destination, on_progress)
32
+ files = included_files
33
+ files.each_with_index do |relative_path, index|
30
34
  target = destination.join(relative_path)
31
35
  FileUtils.mkdir_p(target.dirname)
32
36
  # Keep links as links. Dereferencing a link here could copy arbitrary
33
37
  # host files outside the build context (for example, ~/.ssh/id_rsa)
34
38
  # into the staged directory and expose them to the image build.
35
39
  FileUtils.copy_entry(@root.join(relative_path), target, false, false, false)
40
+ on_progress&.call(index + 1, files.size)
36
41
  end
37
42
  end
38
43
 
39
- def each_included_file
40
- Dir.glob('**/*', File::FNM_DOTMATCH, base: @root.to_s).each do |entry|
41
- next if %w[. ..].include?(entry)
44
+ def included_files
45
+ Dir.glob('**/*', File::FNM_DOTMATCH, base: @root.to_s).select do |entry|
46
+ next false if %w[. ..].include?(entry)
42
47
 
43
48
  path = @root.join(entry)
44
- next unless path.file? || path.symlink?
45
- next if @ignore.ignored?(entry)
46
-
47
- yield entry
49
+ (path.file? || path.symlink?) && !@ignore.ignored?(entry)
48
50
  end
49
51
  end
50
52
  end
data/lib/wip/cli.rb CHANGED
@@ -71,9 +71,13 @@ module Wip
71
71
  settings = load_config.command('build') || {}
72
72
  context = settings['context'] || '.'
73
73
  warn "wip: staging build context (#{context})"
74
- BuildContext.new(context).stage do |staged_context|
74
+ progress = StagingProgress.new
75
+ BuildContext.new(context).stage(on_progress: progress.method(:tick)) do |staged_context|
76
+ progress.finish
75
77
  execute(builder.build(settings: settings.merge('context' => staged_context), extra: extra))
76
78
  end
79
+ ensure
80
+ progress&.finish
77
81
  end
78
82
 
79
83
  desc 'up', 'Start the configured container and its dependencies, creating them if necessary'
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wip
4
+ # Prints a self-overwriting "copying build context files: N/total" line, at
5
+ # most every half second, while a slow, silent step (staging a large build
6
+ # context file by file can take tens of seconds) is still moving — so it
7
+ # doesn't read as hung.
8
+ class StagingProgress
9
+ def initialize(out: $stderr, interval: 0.5)
10
+ @out = out
11
+ @interval = interval
12
+ # Backdated so the very first tick always prints immediately, rather
13
+ # than waiting a full interval before the first sign of life.
14
+ @last = Process.clock_gettime(Process::CLOCK_MONOTONIC) - interval
15
+ @printed = false
16
+ end
17
+
18
+ def tick(count, total)
19
+ now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
20
+ return if now - @last < @interval && count != total
21
+
22
+ @last = now
23
+ @printed = true
24
+ @out.print "\rwip: copying build context files: #{count}/#{total}"
25
+ end
26
+
27
+ # Idempotent: a caller can't know in advance whether tick ever fired.
28
+ def finish
29
+ return unless @printed
30
+
31
+ @printed = false
32
+ @out.puts
33
+ end
34
+ end
35
+ end
data/lib/wip/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wip
4
- VERSION = '0.17.2'
4
+ VERSION = '0.17.3'
5
5
  end
data/lib/wip.rb CHANGED
@@ -9,6 +9,7 @@ require_relative 'wip/environment'
9
9
  require_relative 'wip/dotenv_loader'
10
10
  require_relative 'wip/docker_ignore'
11
11
  require_relative 'wip/build_context'
12
+ require_relative 'wip/staging_progress'
12
13
  require_relative 'wip/command_resolver'
13
14
  require_relative 'wip/error_interpreter'
14
15
  require_relative 'wip/command_builder'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wslc-wip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.2
4
+ version: 0.17.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wip contributors
@@ -52,6 +52,7 @@ files:
52
52
  - lib/wip/errors.rb
53
53
  - lib/wip/initializer.rb
54
54
  - lib/wip/resource_monitor.rb
55
+ - lib/wip/staging_progress.rb
55
56
  - lib/wip/sync_settings.rb
56
57
  - lib/wip/variable_interpolation.rb
57
58
  - lib/wip/version.rb