stdlib package: llb

Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
This commit is contained in:
Solomon Hykes 2021-03-13 08:04:03 +00:00
parent b1b534992a
commit 54a2fe4393
13 changed files with 145 additions and 132 deletions

View File

@ -1,7 +1,7 @@
package alpine package alpine
import ( import (
"dagger.io/dagger" "dagger.io/llb"
) )
let defaultVersion = "3.13.2@sha256:a75afd8b57e7f34e4dad8d65e2c7ba2e1975c795ce1ee22fa34f8cf46f96a3be" let defaultVersion = "3.13.2@sha256:a75afd8b57e7f34e4dad8d65e2c7ba2e1975c795ce1ee22fa34f8cf46f96a3be"
@ -11,17 +11,17 @@ let defaultVersion = "3.13.2@sha256:a75afd8b57e7f34e4dad8d65e2c7ba2e1975c795ce1e
version: string | *defaultVersion version: string | *defaultVersion
#compute: [ #compute: [
dagger.#FetchContainer & { llb.#FetchContainer & {
ref: "index.docker.io/alpine:\(version)" ref: "index.docker.io/alpine:\(version)"
}, },
for pkg, info in package { for pkg, info in package {
if (info & true) != _|_ { if (info & true) != _|_ {
dagger.#Exec & { llb.#Exec & {
args: ["apk", "add", "-U", "--no-cache", pkg] args: ["apk", "add", "-U", "--no-cache", pkg]
} }
} }
if (info & string) != _|_ { if (info & string) != _|_ {
dagger.#Exec & { llb.#Exec & {
args: ["apk", "add", "-U", "--no-cache", "\(pkg)\(info)"] args: ["apk", "add", "-U", "--no-cache", "\(pkg)\(info)"]
} }
} }

View File

@ -3,9 +3,9 @@ package cloudformation
import ( import (
"encoding/json" "encoding/json"
"dagger.io/dagger"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/aws" "dagger.io/aws"
"dagger.io/llb"
) )
// AWS CloudFormation Stack // AWS CloudFormation Stack
@ -49,23 +49,23 @@ import (
[string]: string [string]: string
#compute: [ #compute: [
dagger.#Load & { llb.#Load & {
from: alpine.#Image & { from: alpine.#Image & {
package: bash: "=5.1.0-r0" package: bash: "=5.1.0-r0"
package: jq: "=1.6-r1" package: jq: "=1.6-r1"
package: "aws-cli": "=1.18.177-r0" package: "aws-cli": "=1.18.177-r0"
} }
}, },
dagger.#Mkdir & { llb.#Mkdir & {
path: "/src" path: "/src"
}, },
for dest, content in #files { for dest, content in #files {
dagger.#WriteFile & { llb.#WriteFile & {
"dest": dest "dest": dest
"content": content "content": content
} }
}, },
dagger.#Exec & { llb.#Exec & {
args: [ args: [
"/bin/bash", "/bin/bash",
"--noprofile", "--noprofile",
@ -92,7 +92,7 @@ import (
dir: "/src" dir: "/src"
mount: "/cache/aws": "cache" mount: "/cache/aws": "cache"
}, },
dagger.#Export & { llb.#Export & {
source: "/outputs.json" source: "/outputs.json"
format: "json" format: "json"
}, },

View File

@ -1,8 +1,12 @@
package dagger package dagger
import (
"dagger.io/llb"
)
// An artifact such as source code checkout, container image, binary archive... // An artifact such as source code checkout, container image, binary archive...
// May be passed as user input, or computed by a buildkit pipeline // May be passed as user input, or computed by a buildkit pipeline
#Artifact: #compute: [...#Op] #Artifact: #compute: [...llb.#Op]
// deprecated, use #Artifact instead. // deprecated, use #Artifact instead.
#Dir: #Artifact #Dir: #Artifact
@ -11,90 +15,3 @@ package dagger
// FIXME: currently aliased as a string to mark secrets // FIXME: currently aliased as a string to mark secrets
// this requires proper support. // this requires proper support.
#Secret: string #Secret: string
// One operation in a script
#Op: #FetchContainer | #FetchGit | #Export | #Exec | #Local | #Copy | #Load | #Subdir | #WriteFile | #Mkdir
// Export a value from fs state to cue
#Export: {
do: "export"
// Source path in the container
source: string
format: "json" | "yaml" | *"string"
}
#Local: {
do: "local"
dir: string
include: [...string]
}
// FIXME: bring back load (more efficient than copy)
#Load: {
do: "load"
from: _
}
#Subdir: {
do: "subdir"
dir: string | *"/"
}
#Exec: {
do: "exec"
args: [...string]
env?: [string]: string
always?: true | *false
dir: string | *"/"
mount: [string]: "tmpfs" | "cache" | {from: _, path: string | *"/"}
}
#FetchContainer: {
do: "fetch-container"
ref: string
}
#PushContainer: {
do: "push-container"
ref: string
}
#FetchGit: {
do: "fetch-git"
remote: string
ref: string
}
#Copy: {
do: "copy"
from: _
src: string | *"/"
dest: string | *"/"
}
#DockerBuild: {
do: "docker-build"
// We accept either a context, a Dockerfile or both together
context?: _
dockerfilePath?: string // path to the Dockerfile (defaults to "Dockerfile")
dockerfile?: string
platforms?: [...string]
buildArg?: [string]: string
label?: [string]: string
}
#WriteFile: {
do: "write-file"
content: string
dest: string
mode: int | *0o644
}
#Mkdir: {
do: "mkdir"
dir: *"/" | string
path: string
mode: int | *0o755
}

View File

@ -2,6 +2,7 @@ package docker
import ( import (
"dagger.io/dagger" "dagger.io/dagger"
"dagger.io/llb"
) )
#Ref: string #Ref: string
@ -11,7 +12,7 @@ import (
source: dagger.#Dir source: dagger.#Dir
image: #compute: [ image: #compute: [
dagger.#DockerBuild & {context: source}, llb.#DockerBuild & {context: source},
] ]
} }
@ -22,15 +23,15 @@ import (
{ {
image: #Ref image: #Ref
out: #compute: [ out: #compute: [
dagger.#FetchContainer & {ref: image}, llb.#FetchContainer & {ref: image},
dagger.#Exec & {"args": args}, llb.#Exec & {"args": args},
] ]
} | { } | {
image: _ image: _
out: #compute: [ out: #compute: [
dagger.#Load & {from: image}, llb.#Load & {from: image},
dagger.#Exec & {"args": args}, llb.#Exec & {"args": args},
] ]
} }
} }

View File

@ -3,6 +3,7 @@ package file
import ( import (
"strings" "strings"
"dagger.io/dagger" "dagger.io/dagger"
"dagger.io/llb"
) )
#Create: { #Create: {
@ -11,7 +12,7 @@ import (
contents: string | bytes contents: string | bytes
#compute: [ #compute: [
dagger.#WriteFile & {dest: filename, content: contents, mode: permissions}, llb.#WriteFile & {dest: filename, content: contents, mode: permissions},
] ]
} }
@ -24,7 +25,7 @@ import (
orig: (#read & {path: filename, "from": from}).data orig: (#read & {path: filename, "from": from}).data
#compute: [ #compute: [
dagger.#WriteFile & {dest: filename, content: "\(orig)\(contents)", mode: permissions}, llb.#WriteFile & {dest: filename, content: "\(orig)\(contents)", mode: permissions},
] ]
} }
@ -40,8 +41,8 @@ import (
data: { data: {
string string
#compute: [ #compute: [
dagger.#Load & {"from": from}, llb.#Load & {"from": from},
dagger.#Export & {source: path}, llb.#Export & {source: path},
] ]
} }
} }
@ -62,11 +63,11 @@ _#glob: {
string string
_tmppath: "/tmp/ls.out" _tmppath: "/tmp/ls.out"
#compute: [ #compute: [
dagger.#Load & {"from": from}, llb.#Load & {"from": from},
dagger.#Exec & { llb.#Exec & {
args: ["sh", "-c", "ls \(glob) > \(_tmppath)"] args: ["sh", "-c", "ls \(glob) > \(_tmppath)"]
}, },
dagger.#Export & {source: _tmppath}, llb.#Export & {source: _tmppath},
] ]
} }
} }

View File

@ -1,7 +1,7 @@
package git package git
import ( import (
"dagger.io/dagger" "dagger.io/llb"
) )
// A git repository // A git repository
@ -11,7 +11,7 @@ import (
ref: string ref: string
#compute: [ #compute: [
dagger.#FetchGit & { llb.#FetchGit & {
"remote": remote "remote": remote
"ref": ref "ref": ref
}, },

View File

@ -2,6 +2,7 @@ package go
import ( import (
"dagger.io/dagger" "dagger.io/dagger"
"dagger.io/llb"
) )
#Go: { #Go: {
@ -18,10 +19,10 @@ import (
env: [string]: string env: [string]: string
#compute: [ #compute: [
dagger.#FetchContainer & { llb.#FetchContainer & {
ref: "docker.io/golang:\(version)-alpine" ref: "docker.io/golang:\(version)-alpine"
}, },
dagger.#Exec & { llb.#Exec & {
"args": ["go"] + args "args": ["go"] + args
"env": env "env": env
@ -63,7 +64,7 @@ import (
env: [string]: string env: [string]: string
#compute: [ #compute: [
dagger.#Copy & { llb.#Copy & {
from: #Go & { from: #Go & {
"version": version "version": version
"source": source "source": source

89
stdlib/llb/llb.cue Normal file
View File

@ -0,0 +1,89 @@
// llb: compile LLB graphs executable by buildkit
package llb
// One operation in a script
#Op: #FetchContainer | #FetchGit | #Export | #Exec | #Local | #Copy | #Load | #Subdir | #WriteFile | #Mkdir
// Export a value from fs state to cue
#Export: {
do: "export"
// Source path in the container
source: string
format: "json" | "yaml" | *"string"
}
#Local: {
do: "local"
dir: string
include: [...string]
}
// FIXME: bring back load (more efficient than copy)
#Load: {
do: "load"
from: _
}
#Subdir: {
do: "subdir"
dir: string | *"/"
}
#Exec: {
do: "exec"
args: [...string]
env?: [string]: string
always?: true | *false
dir: string | *"/"
mount: [string]: "tmpfs" | "cache" | {from: _, path: string | *"/"}
}
#FetchContainer: {
do: "fetch-container"
ref: string
}
#PushContainer: {
do: "push-container"
ref: string
}
#FetchGit: {
do: "fetch-git"
remote: string
ref: string
}
#Copy: {
do: "copy"
from: _
src: string | *"/"
dest: string | *"/"
}
#DockerBuild: {
do: "docker-build"
// We accept either a context, a Dockerfile or both together
context?: _
dockerfilePath?: string // path to the Dockerfile (defaults to "Dockerfile")
dockerfile?: string
platforms?: [...string]
buildArg?: [string]: string
label?: [string]: string
}
#WriteFile: {
do: "write-file"
content: string
dest: string
mode: int | *0o644
}
#Mkdir: {
do: "mkdir"
dir: *"/" | string
path: string
mode: int | *0o755
}

View File

@ -3,6 +3,7 @@ package netlify
import ( import (
"dagger.io/dagger" "dagger.io/dagger"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/llb"
) )
// A Netlify account // A Netlify account
@ -37,7 +38,7 @@ import (
string string
#compute: [ #compute: [
dagger.#Load & { llb.#Load & {
from: alpine.#Image & { from: alpine.#Image & {
package: bash: "=~5.1" package: bash: "=~5.1"
package: jq: "=~1.6" package: jq: "=~1.6"
@ -45,10 +46,10 @@ import (
package: yarn: "=~1.22" package: yarn: "=~1.22"
} }
}, },
dagger.#Exec & { llb.#Exec & {
args: ["yarn", "global", "add", "netlify-cli@2.47.0"] args: ["yarn", "global", "add", "netlify-cli@2.47.0"]
}, },
dagger.#Exec & { llb.#Exec & {
args: [ args: [
"/bin/bash", "/bin/bash",
"--noprofile", "--noprofile",
@ -72,7 +73,7 @@ import (
dir: "/src" dir: "/src"
mount: "/src": from: contents mount: "/src": from: contents
}, },
dagger.#Export & { llb.#Export & {
source: "/url" source: "/url"
format: "string" format: "string"
}, },

View File

@ -3,6 +3,7 @@ package yarn
import ( import (
"dagger.io/dagger" "dagger.io/dagger"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/llb"
) )
// Yarn Script // Yarn Script
@ -21,13 +22,13 @@ import (
env?: [string]: string env?: [string]: string
#compute: [ #compute: [
dagger.#Load & { llb.#Load & {
from: alpine.#Image & { from: alpine.#Image & {
package: bash: "=~5.1" package: bash: "=~5.1"
package: yarn: "=~1.22" package: yarn: "=~1.22"
} }
}, },
dagger.#Exec & { llb.#Exec & {
args: [ args: [
"/bin/bash", "/bin/bash",
"--noprofile", "--noprofile",
@ -55,7 +56,7 @@ import (
"/cache/yarn": "cache" "/cache/yarn": "cache"
} }
}, },
dagger.#Subdir & { llb.#Subdir & {
dir: "/build" dir: "/build"
}, },
] ]

View File

@ -1,8 +1,8 @@
package alpine package alpine
import ( import (
"dagger.io/dagger"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/llb"
) )
TestImageVersion: { TestImageVersion: {
@ -12,8 +12,8 @@ TestImageVersion: {
} }
test: #compute: [ test: #compute: [
dagger.#Load & {from: image}, llb.#Load & {from: image},
dagger.#Exec & { llb.#Exec & {
args: [ args: [
"sh", "sh",
"-ec", "-ec",
@ -32,11 +32,11 @@ TestPackageInstall: {
} }
test: #compute: [ test: #compute: [
dagger.#Load & {from: image}, llb.#Load & {from: image},
dagger.#Exec & { llb.#Exec & {
args: ["jq", "--version"] args: ["jq", "--version"]
}, },
dagger.#Exec & { llb.#Exec & {
args: ["sh", "-ec", "curl --version | grep -q 7.74.0"] args: ["sh", "-ec", "curl --version | grep -q 7.74.0"]
}, },
] ]

View File

@ -4,6 +4,7 @@ import (
"dagger.io/dagger" "dagger.io/dagger"
"dagger.io/go" "dagger.io/go"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/llb"
) )
TestData: dagger.#Artifact TestData: dagger.#Artifact
@ -15,8 +16,8 @@ TestGoBuild: {
} }
test: #compute: [ test: #compute: [
dagger.#Load & {from: alpine.#Image}, llb.#Load & {from: alpine.#Image},
dagger.#Exec & { llb.#Exec & {
args: [ args: [
"sh", "sh",
"-ec", "-ec",

View File

@ -4,6 +4,7 @@ import (
"dagger.io/dagger" "dagger.io/dagger"
"dagger.io/yarn" "dagger.io/yarn"
"dagger.io/alpine" "dagger.io/alpine"
"dagger.io/llb"
) )
TestData: dagger.#Artifact TestData: dagger.#Artifact
@ -14,10 +15,10 @@ TestYarn: {
} }
test: #compute: [ test: #compute: [
dagger.#Load & {from: alpine.#Image & { llb.#Load & {from: alpine.#Image & {
package: bash: "=5.1.0-r0" package: bash: "=5.1.0-r0"
}}, }},
dagger.#Exec & { llb.#Exec & {
mount: "/build": from: run mount: "/build": from: run
args: [ args: [
"/bin/bash", "/bin/bash",