Repository navigation
Expand file tree
/
Copy pathruby-half.dang
More file actions
59 lines (56 loc) · 2.14 KB
/
Copy pathruby-half.dang
File metadata and controls
59 lines (56 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
The SDK module's Ruby half, lib/ruby_sdk.rb, run in an exec: the request on stdin, objects by ID, the module's own source by ID, the result in a file.
"""
type RubyHalf {
"""
The starter of a new module, as the SDK's setting gives it.
"""
pub template: String!
"""
The Ruby of a new module, as the SDK's setting gives it.
"""
pub rubyVersion: String!
"""
Run one function of the Ruby half, its arguments as JSON with objects by ID; its result as JSON.
"""
pub call(fnName: String!, fnArgs: String!): String! {
let request = JSON.encode({{
template: template,
rubyVersion: rubyVersion,
function: fnName,
args: fnArgs,
moduleSource: currentModule.source.id,
}})
runtime
.withExec(["ruby", "-rbundler/setup", "lib/ruby_sdk/call.rb", "/dagger/result.json"], stdin: request)
.file("/dagger/result.json")
.contents
}
# The gems install from the Gemfiles and gemspecs alone, by content, before
# the rest of the source arrives. Not frozen: after an edit to the Gemfile,
# this install relocks in the container, so that dagger generate still runs
# and relocks the scope for good.
let runtime: Container! {
let source = currentModule.source
let dependencies = [
"Gemfile",
"Gemfile.lock",
"dagger.gemfile",
"sdk/dagger-sdk.gemspec",
"clients/core/dagger-clients-core.gemspec",
"clients/roots/dagger-clients-roots.gemspec",
].reduce(directory) { files, path => files.withNewFile(path, source.file(path).contents) }
source.directory("images/ruby").dockerBuild
.withEnvVariable("BUNDLE_GEMFILE", "/src/Gemfile")
.withEnvVariable("BUNDLE_PATH", "/usr/local/bundle")
.withEnvVariable("BUNDLE_USER_CACHE", "/cache/bundle/ruby-sdk")
.withEnvVariable("DAGGER_MODULE", "ruby-sdk")
.withEnvVariable("DAGGER_MAIN_OBJECT", "RubySdk")
.withEnvVariable("DAGGER_MODULE_FILE", "lib/ruby_sdk.rb")
.withMountedCache("/cache/bundle", cacheVolume("ruby-sdk-bundle"))
.withWorkdir("/src")
.withDirectory("/src", dependencies)
.withExec(["bundle", "install"])
.withDirectory("/src", source)
}
}