dagger_ruby 0.7.0 → 0.10.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.
data/lib/dagger_ruby.rb CHANGED
@@ -4,69 +4,88 @@ require_relative "dagger_ruby/version"
4
4
  require_relative "dagger_ruby/client"
5
5
  require_relative "dagger_ruby/config"
6
6
  require_relative "dagger_ruby/errors"
7
+ require "open3"
7
8
 
8
9
  module DaggerRuby
9
10
  class << self
10
- def connection(config = nil)
11
- if existing_session?
12
- handle_existing_session(config)
13
- else
14
- start_new_session(config)
15
- end
11
+ def connection(config = nil, &)
12
+ config ||= Config.new
13
+ return connection_in_current_session(config, &) if dagger_session?
14
+
15
+ verify_cli_version!(config) if config.verify_version
16
+ exec(config.environment, *dagger_run_command(config))
16
17
  end
17
18
 
18
19
  private
19
20
 
20
- def existing_session?
21
+ def dagger_session?
21
22
  ENV.fetch("DAGGER_SESSION_PORT", nil) && ENV.fetch("DAGGER_SESSION_TOKEN", nil)
22
23
  end
23
24
 
24
- def handle_existing_session(config)
25
+ def connection_in_current_session(config)
25
26
  client = Client.new(config: config)
26
- if block_given?
27
- begin
28
- yield client
29
- ensure
30
- client.close
31
- end
32
- else
33
- client
27
+ begin
28
+ verify_engine_version!(client, config) if config.verify_version
29
+ rescue StandardError
30
+ client.close
31
+ raise
34
32
  end
35
- end
33
+ return client unless block_given?
36
34
 
37
- def start_new_session(config)
38
- require "open3"
39
- cmd = build_dagger_command(config)
40
- exec(cmd)
35
+ begin
36
+ yield client
37
+ ensure
38
+ client.close
39
+ end
41
40
  end
42
41
 
43
- def build_dagger_command(config)
44
- ruby_cmd = build_ruby_command
45
- dagger_options = build_dagger_options(config)
42
+ def verify_engine_version!(client, config)
43
+ actual = client.execute_query("query { version }").fetch("version")
44
+ return if actual == config.expected_engine_version
46
45
 
47
- cmd_parts = ["dagger"] + dagger_options + ["run", ruby_cmd]
48
- cmd_parts.join(" ")
46
+ raise VersionMismatchError,
47
+ "Dagger engine #{actual} is incompatible with this client; expected #{config.expected_engine_version}"
49
48
  end
50
49
 
51
- def build_ruby_command
52
- script = $PROGRAM_NAME
53
- args = ARGV
54
- ["ruby", script, *args].join(" ")
50
+ def dagger_run_command(config)
51
+ [
52
+ "dagger",
53
+ *quiet_flags(config),
54
+ *silent_flag(config),
55
+ *progress_option(config),
56
+ "run",
57
+ "--",
58
+ "ruby",
59
+ $PROGRAM_NAME,
60
+ *ARGV,
61
+ ]
55
62
  end
56
63
 
57
- def build_dagger_options(config)
58
- options = []
64
+ def verify_cli_version!(config)
65
+ stdout, stderr, status = Open3.capture3("dagger", "version")
66
+ output = [stdout, stderr].join(" ").strip
67
+ actual = output[/\bv\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?\b/]
68
+ return if status.success? && actual == config.expected_engine_version
59
69
 
70
+ found = actual || (output.empty? ? "an unreadable version" : output)
71
+ raise VersionMismatchError,
72
+ "Dagger CLI #{found} is incompatible with this client; install #{config.expected_engine_version}"
73
+ rescue Errno::ENOENT
74
+ raise VersionMismatchError, "Dagger CLI is not installed; install #{config.expected_engine_version}"
75
+ end
76
+
77
+ def quiet_flags(config)
60
78
  quiet = config&.quiet || ENV["DAGGER_QUIET"]&.to_i
61
- options += ["-q"] * quiet if quiet&.positive?
79
+ quiet&.positive? ? ["-q"] * quiet : []
80
+ end
62
81
 
63
- silent = config&.silent || ENV["DAGGER_SILENT"] == "true"
64
- options += ["--silent"] if silent
82
+ def silent_flag(config)
83
+ config&.silent || ENV["DAGGER_SILENT"] == "true" ? ["--silent"] : []
84
+ end
65
85
 
86
+ def progress_option(config)
66
87
  progress = config&.progress || ENV.fetch("DAGGER_PROGRESS", nil)
67
- options += ["--progress", progress] if progress
68
-
69
- options
88
+ progress ? ["--progress", progress] : []
70
89
  end
71
90
  end
72
91
  end
metadata CHANGED
@@ -1,12 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dagger_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
- - Gaurav Tiwari
8
- - Claude Sonnet 4 + GPT-4
9
- bindir: exe
7
+ - BoringCache
8
+ bindir: bin
10
9
  cert_chain: []
11
10
  date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
@@ -16,47 +15,46 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '0.1'
18
+ version: '0.3'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '0.1'
25
+ version: '0.3'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: json
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '2.6'
32
+ version: '2.21'
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '2.6'
39
+ version: '2.21'
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: logger
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: '1.4'
46
+ version: '1.7'
48
47
  type: :runtime
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: '1.4'
55
- description: DaggerRuby provides a fluent, idiomatic Ruby interface to Dagger's container-based
56
- CI/CD engine. Define build pipelines programmatically with Ruby instead of YAML.
57
- Features lazy execution, caching, secrets, and service orchestration.
53
+ version: '1.7'
54
+ description: DaggerRuby provides a small, chainable Ruby interface for running container
55
+ builds, services, caches, secrets, and filesystem operations with the Dagger engine.
58
56
  email:
59
- - gaurav@gauravtiwari.co.uk
57
+ - oss@boringcache.com
60
58
  executables: []
61
59
  extensions: []
62
60
  extra_rdoc_files: []
@@ -64,6 +62,7 @@ files:
64
62
  - CHANGELOG.md
65
63
  - LICENSE.txt
66
64
  - README.md
65
+ - SECURITY.md
67
66
  - dagger_ruby.gemspec
68
67
  - lib/dagger_ruby.rb
69
68
  - lib/dagger_ruby/cache_volume.rb
@@ -86,8 +85,11 @@ licenses:
86
85
  metadata:
87
86
  allowed_push_host: https://rubygems.org
88
87
  homepage_uri: https://github.com/boringcache/dagger_ruby
89
- source_code_uri: https://github.com/boringcache/dagger_ruby
88
+ source_code_uri: https://github.com/boringcache/dagger_ruby/tree/v0.10.0
90
89
  changelog_uri: https://github.com/boringcache/dagger_ruby/blob/main/CHANGELOG.md
90
+ bug_tracker_uri: https://github.com/boringcache/dagger_ruby/issues
91
+ documentation_uri: https://github.com/boringcache/dagger_ruby#readme
92
+ security_policy_uri: https://github.com/boringcache/dagger_ruby/security/policy
91
93
  rubygems_mfa_required: 'true'
92
94
  rdoc_options: []
93
95
  require_paths:
@@ -96,14 +98,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
98
  requirements:
97
99
  - - ">="
98
100
  - !ruby/object:Gem::Version
99
- version: 3.1.0
101
+ version: 3.2.0
100
102
  required_rubygems_version: !ruby/object:Gem::Requirement
101
103
  requirements:
102
104
  - - ">="
103
105
  - !ruby/object:Gem::Version
104
106
  version: '0'
105
107
  requirements: []
106
- rubygems_version: 3.6.7
108
+ rubygems_version: 4.0.16
107
109
  specification_version: 4
108
- summary: A Ruby SDK for Dagger - build powerful CI/CD pipelines using Ruby
110
+ summary: A Ruby client for Dagger's GraphQL API
109
111
  test_files: []