workspaces 0.1.4 → 0.1.5
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/lib/workspaces/backend.rb +5 -2
- data/lib/workspaces/child_env.rb +38 -0
- data/lib/workspaces/cli.rb +4 -1
- data/lib/workspaces/command_runner.rb +4 -1
- data/lib/workspaces/version.rb +1 -1
- data/lib/workspaces.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9e8987b36ff8ba5cfd6c039c911012462661c5da01989e84843188e471c58171
|
|
4
|
+
data.tar.gz: 1bae9743875990e29ada15d6b26885d0881eaf84dbf8626bfef1bea779753833
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 173beba79ca2237d5632e06f7abb7edbc0a46f3a17d283bfdead8e59469bb9383d1de2af97f90c8c9c51e24d2b014aa6a21c63dc83f80ac257c488121f7ae909
|
|
7
|
+
data.tar.gz: b98959ea514d65b64d454f928330b86959e417bbf1be83466790ea072cd350757b9daa5ff5c7724877684bc834618eeb6a6d6b20788879dcceba48ca8be32712
|
data/lib/workspaces/backend.rb
CHANGED
|
@@ -4,6 +4,7 @@ require 'time'
|
|
|
4
4
|
require_relative 'config'
|
|
5
5
|
require_relative 'state_store'
|
|
6
6
|
require_relative 'port_allocator'
|
|
7
|
+
require_relative 'child_env'
|
|
7
8
|
|
|
8
9
|
module Workspaces
|
|
9
10
|
class Backend
|
|
@@ -61,8 +62,10 @@ module Workspaces
|
|
|
61
62
|
|
|
62
63
|
def spawn_command(workspace, command, env)
|
|
63
64
|
File.open(Config.backend_log_path(workspace_id), 'a') do |file|
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
child_env = ChildEnv.for_workspace(workspace_path: workspace.path, extra_env: env)
|
|
66
|
+
Process.spawn(child_env, [command.first, command.first], *command.drop(1),
|
|
67
|
+
chdir: workspace.path.to_s, in: File::NULL, out: file, err: file, pgroup: true,
|
|
68
|
+
unsetenv_others: true)
|
|
66
69
|
end
|
|
67
70
|
end
|
|
68
71
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Workspaces
|
|
2
|
+
module ChildEnv
|
|
3
|
+
module_function
|
|
4
|
+
|
|
5
|
+
def for_workspace(workspace_path:, extra_env: {}, parent_env: ENV.to_h)
|
|
6
|
+
env = parent_env.to_h.transform_keys(&:to_s).dup
|
|
7
|
+
if defined?(::Bundler)
|
|
8
|
+
clean = Bundler.unbundled_env
|
|
9
|
+
%w(PATH GEM_HOME GEM_PATH MANPATH RUBYOPT RUBYLIB RB_USER_INSTALL).each do |name|
|
|
10
|
+
clean.key?(name) ? env[name] = clean[name] : env.delete(name)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
env.delete_if { |key, _| bundler_key?(key) }
|
|
14
|
+
|
|
15
|
+
gemfile = File.join(workspace_path.to_s, 'Gemfile')
|
|
16
|
+
env['BUNDLE_GEMFILE'] = gemfile
|
|
17
|
+
env['BUNDLE_LOCKFILE'] = File.join(workspace_path.to_s, 'Gemfile.lock')
|
|
18
|
+
|
|
19
|
+
extra_env.to_h.each do |name, value|
|
|
20
|
+
key = name.to_s
|
|
21
|
+
next if bundler_key?(key)
|
|
22
|
+
|
|
23
|
+
if value.nil?
|
|
24
|
+
env.delete(key)
|
|
25
|
+
else
|
|
26
|
+
env[key] = value
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
env
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def bundler_key?(key)
|
|
34
|
+
%w(BUNDLE_GEMFILE BUNDLE_LOCKFILE BUNDLER_SETUP BUNDLER_VERSION).include?(key) ||
|
|
35
|
+
key.start_with?('BUNDLER_ORIG_')
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/lib/workspaces/cli.rb
CHANGED
|
@@ -6,6 +6,7 @@ require_relative 'registry'
|
|
|
6
6
|
require_relative 'coordinator'
|
|
7
7
|
require_relative 'front_door'
|
|
8
8
|
require_relative 'tls'
|
|
9
|
+
require_relative 'child_env'
|
|
9
10
|
|
|
10
11
|
module Workspaces
|
|
11
12
|
class Cli
|
|
@@ -149,7 +150,9 @@ module Workspaces
|
|
|
149
150
|
end
|
|
150
151
|
|
|
151
152
|
registry.with_lock(id) do |workspace|
|
|
152
|
-
|
|
153
|
+
child_env = ChildEnv.for_workspace(workspace_path: workspace.path)
|
|
154
|
+
pid = Process.spawn(child_env, [argv.first, argv.first], *argv.drop(1),
|
|
155
|
+
chdir: workspace.path.to_s, unsetenv_others: true)
|
|
153
156
|
_, status = Process.wait2(pid)
|
|
154
157
|
status.exitstatus || (128 + status.termsig)
|
|
155
158
|
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'open3'
|
|
2
2
|
require 'timeout'
|
|
3
|
+
require_relative 'child_env'
|
|
3
4
|
|
|
4
5
|
module Workspaces
|
|
5
6
|
class CommandRunner
|
|
@@ -12,7 +13,9 @@ module Workspaces
|
|
|
12
13
|
|
|
13
14
|
def run!(command, env:, timeout:)
|
|
14
15
|
executable = [command.first, command.first]
|
|
15
|
-
|
|
16
|
+
child_env = ChildEnv.for_workspace(workspace_path: @path, extra_env: env)
|
|
17
|
+
Open3.popen2e(child_env, executable, *command.drop(1), chdir: @path.to_s, pgroup: true,
|
|
18
|
+
unsetenv_others: true) do |input, output, child|
|
|
16
19
|
input.close
|
|
17
20
|
output.set_encoding(Encoding::UTF_8, invalid: :replace, undef: :replace)
|
|
18
21
|
run_child(output, child, timeout)
|
data/lib/workspaces/version.rb
CHANGED
data/lib/workspaces.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: workspaces
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Workspaces contributors
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rack
|
|
@@ -71,6 +71,7 @@ files:
|
|
|
71
71
|
- exe/workspaces
|
|
72
72
|
- lib/workspaces.rb
|
|
73
73
|
- lib/workspaces/backend.rb
|
|
74
|
+
- lib/workspaces/child_env.rb
|
|
74
75
|
- lib/workspaces/cli.rb
|
|
75
76
|
- lib/workspaces/command_runner.rb
|
|
76
77
|
- lib/workspaces/config.rb
|