dagger_ruby 0.6.0 → 0.9.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.
@@ -4,12 +4,6 @@ require_relative "dagger_object"
4
4
 
5
5
  module DaggerRuby
6
6
  class File < DaggerObject
7
- def self.from_id(id, client)
8
- query = QueryBuilder.new("file")
9
- query.load_from_id(id)
10
- new(query, client)
11
- end
12
-
13
7
  def self.root_field_name
14
8
  "file"
15
9
  end
@@ -18,20 +12,15 @@ module DaggerRuby
18
12
  chain_operation("withName", { "name" => name })
19
13
  end
20
14
 
21
- def with_contents(contents)
22
- chain_operation("withContents", { "contents" => contents })
23
- end
24
-
25
15
  def with_timestamps(timestamp)
26
16
  chain_operation("withTimestamps", { "timestamp" => timestamp })
27
17
  end
28
18
 
29
- def with_secret(secret)
30
- chain_operation("withSecret", { "secret" => secret })
31
- end
32
-
33
- def contents
34
- get_scalar("contents")
19
+ def contents(offset_lines: nil, limit_lines: nil)
20
+ args = {}
21
+ args["offsetLines"] = offset_lines if offset_lines
22
+ args["limitLines"] = limit_lines if limit_lines
23
+ get_scalar("contents", args)
35
24
  end
36
25
 
37
26
  def size
@@ -42,48 +31,27 @@ module DaggerRuby
42
31
  get_scalar("name")
43
32
  end
44
33
 
34
+ def chown(owner)
35
+ chain_operation("chown", { "owner" => owner })
36
+ end
37
+
38
+ def with_replaced(search, replacement, opts = {})
39
+ args = { "search" => search, "replacement" => replacement }
40
+ args["all"] = opts[:all] if opts.key?(:all)
41
+ args["firstFrom"] = opts[:first_from] if opts[:first_from]
42
+ chain_operation("withReplaced", args)
43
+ end
44
+
45
45
  def export(path, opts = {})
46
46
  args = { "path" => path }
47
47
  args["allowParentDirPath"] = opts[:allow_parent_dir_path] if opts.key?(:allow_parent_dir_path)
48
48
 
49
- query = @query_builder.build_query_with_selection("export(#{format_arguments(args)})")
50
- result = @client.execute(query)
51
- extract_value_from_result(result, "export")
49
+ get_scalar("export", args)
52
50
  end
53
51
 
54
52
  def sync
55
53
  get_scalar("id")
56
54
  self
57
55
  end
58
-
59
- private
60
-
61
- def format_arguments(args)
62
- return "" if args.empty?
63
-
64
- args.map { |key, value| "#{key}: #{format_value(value)}" }.join(", ")
65
- end
66
-
67
- def format_value(value)
68
- case value
69
- when String
70
- "\"#{value}\""
71
- when Integer, Float
72
- value.to_s
73
- when TrueClass, FalseClass
74
- value.to_s
75
- when NilClass
76
- "null"
77
- when Array
78
- "[#{value.map { |v| format_value(v) }.join(", ")}]"
79
- when Hash
80
- formatted_pairs = value.map { |k, v| "#{k}: #{format_value(v)}" }
81
- "{ #{formatted_pairs.join(", ")} }"
82
- when DaggerObject
83
- value.id
84
- else
85
- "\"#{value}\""
86
- end
87
- end
88
56
  end
89
57
  end
@@ -4,12 +4,6 @@ require_relative "dagger_object"
4
4
 
5
5
  module DaggerRuby
6
6
  class GitRepository < DaggerObject
7
- def self.from_id(id, client)
8
- query = QueryBuilder.new("gitRepository")
9
- query.load_from_id(id)
10
- new(query, client)
11
- end
12
-
13
7
  def self.root_field_name
14
8
  "gitRepository"
15
9
  end
@@ -30,20 +24,16 @@ module DaggerRuby
30
24
  get_object("head", GitRef)
31
25
  end
32
26
 
33
- def branches
34
- get_scalar("branches")
35
- end
36
-
37
- def tags
38
- get_scalar("tags")
39
- end
40
-
41
- def with_auth_token(token)
42
- chain_operation("withAuthToken", { "token" => token.is_a?(DaggerObject) ? token.id : token })
27
+ def branches(patterns: nil)
28
+ args = {}
29
+ args["patterns"] = patterns if patterns
30
+ get_scalar("branches", args)
43
31
  end
44
32
 
45
- def with_auth_header(header)
46
- chain_operation("withAuthHeader", { "header" => header.is_a?(DaggerObject) ? header.id : header })
33
+ def tags(patterns: nil)
34
+ args = {}
35
+ args["patterns"] = patterns if patterns
36
+ get_scalar("tags", args)
47
37
  end
48
38
 
49
39
  def sync
@@ -53,12 +43,6 @@ module DaggerRuby
53
43
  end
54
44
 
55
45
  class GitRef < DaggerObject
56
- def self.from_id(id, client)
57
- query = QueryBuilder.new("gitRef")
58
- query.load_from_id(id)
59
- new(query, client)
60
- end
61
-
62
46
  def self.root_field_name
63
47
  "gitRef"
64
48
  end
@@ -73,11 +57,14 @@ module DaggerRuby
73
57
 
74
58
  def tree(opts = {})
75
59
  args = {}
76
- args["path"] = opts[:path] if opts[:path]
77
- args["exclude"] = opts[:exclude] if opts[:exclude]
78
- args["include"] = opts[:include] if opts[:include]
79
-
80
- get_object("tree", Directory, args)
60
+ args["discardGitDir"] = opts[:discard_git_dir] if opts.key?(:discard_git_dir)
61
+ args["depth"] = opts[:depth] if opts[:depth]
62
+ args["includeTags"] = opts[:include_tags] if opts.key?(:include_tags)
63
+
64
+ directory = get_object("tree", Directory, args)
65
+ directory = directory.directory(opts[:path]) if opts[:path]
66
+ directory = directory.filter(exclude: opts[:exclude], include: opts[:include]) if opts[:exclude] || opts[:include]
67
+ directory
81
68
  end
82
69
 
83
70
  def sync
@@ -5,12 +5,6 @@ require_relative "dagger_object"
5
5
 
6
6
  module DaggerRuby
7
7
  class Host < DaggerObject
8
- def self.from_id(id, client)
9
- query = QueryBuilder.new("host")
10
- query.load_from_id(id)
11
- new(query, client)
12
- end
13
-
14
8
  def self.root_field_name
15
9
  "host"
16
10
  end
@@ -19,22 +13,22 @@ module DaggerRuby
19
13
  args = { "path" => path }
20
14
  args["exclude"] = opts[:exclude] if opts[:exclude]
21
15
  args["include"] = opts[:include] if opts[:include]
16
+ args["noCache"] = opts[:no_cache] if opts.key?(:no_cache)
17
+ args["gitignore"] = opts[:gitignore] if opts[:gitignore]
22
18
 
23
19
  get_object("directory", Directory, args)
24
20
  end
25
21
 
26
- def file(path)
27
- get_object("file", File, { "path" => path })
22
+ def file(path, no_cache: nil)
23
+ args = { "path" => path }
24
+ args["noCache"] = no_cache unless no_cache.nil?
25
+ get_object("file", File, args)
28
26
  end
29
27
 
30
28
  def unix_socket(path)
31
29
  get_object("unixSocket", Socket, { "path" => path })
32
30
  end
33
31
 
34
- def workdir
35
- get_scalar("workdir")
36
- end
37
-
38
32
  def sync
39
33
  get_scalar("id")
40
34
  self
@@ -42,12 +36,6 @@ module DaggerRuby
42
36
  end
43
37
 
44
38
  class Socket < DaggerObject
45
- def self.from_id(id, client)
46
- query = QueryBuilder.new("socket")
47
- query.load_from_id(id)
48
- new(query, client)
49
- end
50
-
51
39
  def self.root_field_name
52
40
  "socket"
53
41
  end
@@ -7,6 +7,10 @@ module DaggerRuby
7
7
  class QueryBuilder
8
8
  attr_reader :root_field, :operation_chain, :variables
9
9
 
10
+ def self.enum_value(value)
11
+ value.is_a?(Hash) ? value : value.to_sym
12
+ end
13
+
10
14
  def initialize(root_field = nil)
11
15
  @root_field = root_field
12
16
  @operation_chain = []
@@ -20,10 +24,6 @@ module DaggerRuby
20
24
  new_query
21
25
  end
22
26
 
23
- def load_from_id(id)
24
- chain_operation("loadFromId", { "id" => id })
25
- end
26
-
27
27
  def variable(name, type)
28
28
  new_query = QueryBuilder.new(@root_field)
29
29
  new_query.instance_variable_set(:@operation_chain, @operation_chain.dup)
@@ -31,7 +31,8 @@ module DaggerRuby
31
31
  new_query
32
32
  end
33
33
 
34
- def build_query_with_selection(field)
34
+ def build_query_with_selection(field, args = {})
35
+ selection = field_selection(field, args)
35
36
  query_parts = []
36
37
 
37
38
  if @variables.any?
@@ -43,21 +44,25 @@ module DaggerRuby
43
44
 
44
45
  if @root_field
45
46
  if @operation_chain.empty?
46
- query_parts << "{ #{@root_field} { #{field} } }"
47
+ query_parts << "{ #{@root_field} { #{selection} } }"
47
48
  else
48
- operations_str = build_operations_chain_with_selection(field)
49
+ operations_str = build_operations_chain_with_selection(selection)
49
50
  query_parts << "{ #{@root_field} { #{operations_str} } }"
50
51
  end
51
52
  elsif @operation_chain.any?
52
- operations_str = build_operations_chain_with_selection(field)
53
+ operations_str = build_operations_chain_with_selection(selection)
53
54
  query_parts << "{ #{operations_str} }"
54
55
  else
55
- query_parts << "{ #{field} }"
56
+ query_parts << "{ #{selection} }"
56
57
  end
57
58
 
58
59
  query_parts.join(" ")
59
60
  end
60
61
 
62
+ def field_selection(field, args = {})
63
+ "#{field}#{format_arguments(args)}"
64
+ end
65
+
61
66
  private
62
67
 
63
68
  def build_operations_chain_with_selection(field)
@@ -4,24 +4,10 @@ require_relative "dagger_object"
4
4
 
5
5
  module DaggerRuby
6
6
  class Secret < DaggerObject
7
- def self.from_id(id, client)
8
- query = QueryBuilder.new("secret")
9
- query.load_from_id(id)
10
- new(query, client)
11
- end
12
-
13
7
  def self.root_field_name
14
8
  "secret"
15
9
  end
16
10
 
17
- def with_name(name)
18
- chain_operation("withName", { "name" => name })
19
- end
20
-
21
- def with_plaintext(plaintext)
22
- chain_operation("withPlaintext", { "plaintext" => plaintext })
23
- end
24
-
25
11
  def name
26
12
  get_scalar("name")
27
13
  end
@@ -4,12 +4,6 @@ require_relative "dagger_object"
4
4
 
5
5
  module DaggerRuby
6
6
  class Service < DaggerObject
7
- def self.from_id(id, client)
8
- query = QueryBuilder.new("service")
9
- query.load_from_id(id)
10
- new(query, client)
11
- end
12
-
13
7
  def self.root_field_name
14
8
  "service"
15
9
  end
@@ -19,13 +13,7 @@ module DaggerRuby
19
13
  args["port"] = opts[:port] if opts[:port]
20
14
  args["scheme"] = opts[:scheme] if opts[:scheme]
21
15
 
22
- if args.empty?
23
- get_scalar("endpoint")
24
- else
25
- query = @query_builder.build_query_with_selection("endpoint(#{format_arguments(args)})")
26
- result = @client.execute(query)
27
- extract_value_from_result(result, "endpoint")
28
- end
16
+ get_scalar("endpoint", args)
29
17
  end
30
18
 
31
19
  def hostname
@@ -33,42 +21,26 @@ module DaggerRuby
33
21
  end
34
22
 
35
23
  def ports
36
- get_scalar("ports")
24
+ get_selection("ports", "port protocol description experimentalSkipHealthcheck")
37
25
  end
38
26
 
39
27
  def start
40
- query = @query_builder.build_query_with_selection("start")
41
- result = @client.execute(query)
42
- extract_value_from_result(result, "start")
28
+ get_scalar("start")
43
29
  end
44
30
 
45
31
  def stop(opts = {})
46
32
  args = {}
47
33
  args["kill"] = opts[:kill] if opts.key?(:kill)
48
34
 
49
- query = if args.empty?
50
- @query_builder.build_query_with_selection("stop")
51
- else
52
- @query_builder.build_query_with_selection("stop(#{format_arguments(args)})")
53
- end
54
-
55
- result = @client.execute(query)
56
- extract_value_from_result(result, "stop")
35
+ get_scalar("stop", args)
57
36
  end
58
37
 
59
38
  def up(opts = {})
60
39
  args = {}
61
- args["ports"] = opts[:ports] if opts[:ports]
40
+ args["ports"] = opts[:ports].map { |port| normalize_port_forward(port) } if opts[:ports]
62
41
  args["random"] = opts[:random] if opts.key?(:random)
63
42
 
64
- query = if args.empty?
65
- @query_builder.build_query_with_selection("up")
66
- else
67
- @query_builder.build_query_with_selection("up(#{format_arguments(args)})")
68
- end
69
-
70
- result = @client.execute(query)
71
- extract_value_from_result(result, "up")
43
+ get_scalar("up", args)
72
44
  end
73
45
 
74
46
  def with_hostname(hostname)
@@ -82,31 +54,10 @@ module DaggerRuby
82
54
 
83
55
  private
84
56
 
85
- def format_arguments(args)
86
- return "" if args.empty?
87
-
88
- args.map { |key, value| "#{key}: #{format_value(value)}" }.join(", ")
89
- end
90
-
91
- def format_value(value)
92
- case value
93
- when String
94
- "\"#{value}\""
95
- when Integer, Float
96
- value.to_s
97
- when TrueClass, FalseClass
98
- value.to_s
99
- when NilClass
100
- "null"
101
- when Array
102
- "[#{value.map { |v| format_value(v) }.join(", ")}]"
103
- when Hash
104
- formatted_pairs = value.map { |k, v| "#{k}: #{format_value(v)}" }
105
- "{ #{formatted_pairs.join(", ")} }"
106
- when DaggerObject
107
- value.id
108
- else
109
- "\"#{value}\""
57
+ def normalize_port_forward(port)
58
+ port.to_h do |key, value|
59
+ normalized = key.to_s == "protocol" ? QueryBuilder.enum_value(value) : value
60
+ [key, normalized]
110
61
  end
111
62
  end
112
63
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DaggerRuby
4
- VERSION = "0.6.0"
4
+ VERSION = "0.9.0"
5
+ DAGGER_VERSION = "0.21.8"
5
6
  end
data/lib/dagger_ruby.rb CHANGED
@@ -7,46 +7,55 @@ require_relative "dagger_ruby/errors"
7
7
 
8
8
  module DaggerRuby
9
9
  class << self
10
- def connection(config = nil)
11
- # If we're already in a dagger session, use it
12
- if ENV["DAGGER_SESSION_PORT"] && ENV["DAGGER_SESSION_TOKEN"]
13
- client = Client.new(config: config)
14
- if block_given?
15
- begin
16
- yield client
17
- ensure
18
- client.close
19
- end
20
- else
21
- client
22
- end
23
- else
24
- # Otherwise, start a new dagger session
25
- require "open3"
26
-
27
- # Get the current script and its arguments
28
- script = $PROGRAM_NAME
29
- args = ARGV
30
-
31
- # Construct the command that dagger should run
32
- ruby_cmd = ["ruby", script, *args].join(" ")
33
-
34
- # Get verbosity options from config or environment
35
- quiet = config&.quiet || ENV["DAGGER_QUIET"]&.to_i
36
- silent = config&.silent || ENV["DAGGER_SILENT"] == "true"
37
- progress = config&.progress || ENV.fetch("DAGGER_PROGRESS", nil)
38
-
39
- # Build dagger command with options
40
- cmd_parts = ["dagger"]
41
- cmd_parts += ["-q"] * quiet if quiet&.positive?
42
- cmd_parts += ["--silent"] if silent
43
- cmd_parts += ["--progress", progress] if progress
44
- cmd_parts += ["run", ruby_cmd]
45
- cmd = cmd_parts.join(" ")
46
-
47
- # Execute the command
48
- exec(cmd)
10
+ def connection(config = nil, &)
11
+ return connection_in_current_session(config, &) if dagger_session?
12
+
13
+ exec(*dagger_run_command(config))
14
+ end
15
+
16
+ private
17
+
18
+ def dagger_session?
19
+ ENV.fetch("DAGGER_SESSION_PORT", nil) && ENV.fetch("DAGGER_SESSION_TOKEN", nil)
20
+ end
21
+
22
+ def connection_in_current_session(config)
23
+ client = Client.new(config: config)
24
+ return client unless block_given?
25
+
26
+ begin
27
+ yield client
28
+ ensure
29
+ client.close
49
30
  end
50
31
  end
32
+
33
+ def dagger_run_command(config)
34
+ [
35
+ "dagger",
36
+ *quiet_flags(config),
37
+ *silent_flag(config),
38
+ *progress_option(config),
39
+ "run",
40
+ "--",
41
+ "ruby",
42
+ $PROGRAM_NAME,
43
+ *ARGV,
44
+ ]
45
+ end
46
+
47
+ def quiet_flags(config)
48
+ quiet = config&.quiet || ENV["DAGGER_QUIET"]&.to_i
49
+ quiet&.positive? ? ["-q"] * quiet : []
50
+ end
51
+
52
+ def silent_flag(config)
53
+ config&.silent || ENV["DAGGER_SILENT"] == "true" ? ["--silent"] : []
54
+ end
55
+
56
+ def progress_option(config)
57
+ progress = config&.progress || ENV.fetch("DAGGER_PROGRESS", nil)
58
+ progress ? ["--progress", progress] : []
59
+ end
51
60
  end
52
61
  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.6.0
4
+ version: 0.9.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.9.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: 4.0.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: []