From 5abd77f4f26edb58fbea0acaea31da1902c6a0c0 Mon Sep 17 00:00:00 2001 From: Helder Correia <174525+helderco@users.noreply.github.com> Date: Mon, 28 Mar 2022 12:02:39 +0000 Subject: [PATCH] Move types and plan back to main dagger package Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com> --- ci/main.cue | 3 +- pkg/dagger.io/dagger/core/exec.cue | 14 ++-- pkg/dagger.io/dagger/core/fs.cue | 38 ++++----- pkg/dagger.io/dagger/core/git.cue | 12 +-- pkg/dagger.io/dagger/core/http.cue | 4 +- pkg/dagger.io/dagger/core/image.cue | 78 ++++++------------- pkg/dagger.io/dagger/core/secrets.cue | 16 ++-- pkg/dagger.io/dagger/dagger.cue | 26 ------- pkg/dagger.io/dagger/image.cue | 36 +++++++++ pkg/dagger.io/dagger/{core => }/plan.cue | 2 +- pkg/dagger.io/dagger/{core => }/types.cue | 2 +- pkg/pkg.go | 3 +- .../examples/todoapp/todoapp.cue | 4 +- pkg/universe.dagger.io/go/container.cue | 3 +- plan/task/task.go | 22 ++++-- 15 files changed, 132 insertions(+), 131 deletions(-) delete mode 100644 pkg/dagger.io/dagger/dagger.cue create mode 100644 pkg/dagger.io/dagger/image.cue rename pkg/dagger.io/dagger/{core => }/plan.cue (99%) rename pkg/dagger.io/dagger/{core => }/types.cue (98%) diff --git a/ci/main.cue b/ci/main.cue index 798f5ccc..6abdcaa0 100644 --- a/ci/main.cue +++ b/ci/main.cue @@ -2,6 +2,7 @@ package main import ( "dagger.io/dagger" + "dagger.io/dagger/core" "universe.dagger.io/bash" ) @@ -19,7 +20,7 @@ dagger.#Plan & { _mountGoCache: { mounts: "go mod cache": { dest: "/root/.gocache" - contents: dagger.#CacheDir & { + contents: core.#CacheDir & { id: "go mod cache" } } diff --git a/pkg/dagger.io/dagger/core/exec.cue b/pkg/dagger.io/dagger/core/exec.cue index b2278f59..3bcdfc3d 100644 --- a/pkg/dagger.io/dagger/core/exec.cue +++ b/pkg/dagger.io/dagger/core/exec.cue @@ -1,11 +1,13 @@ package core +import "dagger.io/dagger" + // Execute a command in a container #Exec: { $dagger: task: _name: "Exec" // Container filesystem - input: #FS + input: dagger.#FS // Transient filesystem mounts // Key is an arbitrary name, for example "app source code" @@ -17,7 +19,7 @@ package core args: [...string] // Environment variables - env: [key=string]: string | #Secret + env: [key=string]: string | dagger.#Secret // Working directory workdir: string | *"/" @@ -33,7 +35,7 @@ package core hosts: [hostname=string]: string // Modified filesystem - output: #FS + output: dagger.#FS // Command exit code // Currently this field can only ever be zero. @@ -54,15 +56,15 @@ package core contents: #TempDir } | { type: "service" - contents: #Service + contents: dagger.#Service } | { type: "fs" - contents: #FS + contents: dagger.#FS source?: string ro?: true | *false } | { type: "secret" - contents: #Secret + contents: dagger.#Secret uid: int | *0 gid: int | *0 mask: int | *0o400 diff --git a/pkg/dagger.io/dagger/core/fs.cue b/pkg/dagger.io/dagger/core/fs.cue index fe9cef75..77efee8c 100644 --- a/pkg/dagger.io/dagger/core/fs.cue +++ b/pkg/dagger.io/dagger/core/fs.cue @@ -1,5 +1,7 @@ package core +import "dagger.io/dagger" + // Access the source directory for the current CUE package // This may safely be called from any package #Source: { @@ -12,7 +14,7 @@ package core // Optionally include certain files exclude: [...string] - output: #FS + output: dagger.#FS } // Create one or multiple directory in a container @@ -20,7 +22,7 @@ package core $dagger: task: _name: "Mkdir" // Container filesystem - input: #FS + input: dagger.#FS // Path of the directory to create // It can be nested (e.g : "/foo" or "/foo/bar") @@ -33,14 +35,14 @@ package core parents: *true | false // Modified filesystem - output: #FS + output: dagger.#FS } #ReadFile: { $dagger: task: _name: "ReadFile" // Filesystem tree holding the file - input: #FS + input: dagger.#FS // Path of the file to read path: string // Contents of the file @@ -52,7 +54,7 @@ package core $dagger: task: _name: "WriteFile" // Input filesystem tree - input: #FS + input: dagger.#FS // Path of the file to write path: string // Contents to write @@ -60,27 +62,27 @@ package core // Permissions of the file permissions: *0o600 | int // Output filesystem tree - output: #FS + output: dagger.#FS } // Copy files from one FS tree to another #Copy: { $dagger: task: _name: "Copy" // Input of the operation - input: #FS + input: dagger.#FS // Contents to copy - contents: #FS + contents: dagger.#FS // Source path (optional) source: string | *"/" // Destination path (optional) dest: string | *"/" // Output of the operation - output: #FS + output: dagger.#FS } #CopyInfo: { source: { - root: #FS + root: dagger.#FS path: string | *"/" } dest: string @@ -89,22 +91,22 @@ package core // Merge multiple FS trees into one #Merge: { $dagger: task: _name: "Merge" - inputs: [...#FS] - output: #FS + inputs: [...dagger.#FS] + output: dagger.#FS } // Extract the difference from lower FS to upper FS as its own FS #Diff: { $dagger: task: _name: "Diff" - lower: #FS - upper: #FS - output: #FS + lower: dagger.#FS + upper: dagger.#FS + output: dagger.#FS } // Select a subdirectory from a filesystem tree #Subdir: { // Input tree - input: #FS + input: dagger.#FS // Path of the subdirectory // Example: "/build" @@ -112,12 +114,12 @@ package core // Copy action _copy: #Copy & { - "input": #Scratch + "input": dagger.#Scratch contents: input source: path dest: "/" } // Subdirectory tree - output: #FS & _copy.output + output: dagger.#FS & _copy.output } diff --git a/pkg/dagger.io/dagger/core/git.cue b/pkg/dagger.io/dagger/core/git.cue index 2d688fd6..d07017ed 100644 --- a/pkg/dagger.io/dagger/core/git.cue +++ b/pkg/dagger.io/dagger/core/git.cue @@ -1,11 +1,13 @@ package core +import "dagger.io/dagger" + // Push a directory to a git remote #GitPush: { @dagger(notimplemented) $dagger: task: _name: "GitPush" - input: #FS + input: dagger.#FS remote: string ref: string } @@ -20,11 +22,11 @@ package core keepGitDir: true | *false auth?: { username: string - password: #Secret // can be password or personal access token + password: dagger.#Secret // can be password or personal access token } | { - authToken: #Secret + authToken: dagger.#Secret } | { - authHeader: #Secret + authHeader: dagger.#Secret } - output: #FS + output: dagger.#FS } diff --git a/pkg/dagger.io/dagger/core/http.cue b/pkg/dagger.io/dagger/core/http.cue index 500e978e..fc3958e7 100644 --- a/pkg/dagger.io/dagger/core/http.cue +++ b/pkg/dagger.io/dagger/core/http.cue @@ -16,6 +16,8 @@ package core // func Chown(uid, gid int) HTTPOption // func Filename(name string) HTTPOption +import "dagger.io/dagger" + // Fetch a file over HTTP #HTTPFetch: { $dagger: task: _name: "HTTPFetch" @@ -43,5 +45,5 @@ package core gid?: int // New filesystem state containing the downloaded file - output: #FS + output: dagger.#FS } diff --git a/pkg/dagger.io/dagger/core/image.cue b/pkg/dagger.io/dagger/core/image.cue index b36ec7f8..345be094 100644 --- a/pkg/dagger.io/dagger/core/image.cue +++ b/pkg/dagger.io/dagger/core/image.cue @@ -1,63 +1,31 @@ package core -import "list" - -// A ref is an address for a remote container image -// -// Examples: -// - "index.docker.io/dagger" -// - "dagger" -// - "index.docker.io/dagger:latest" -// - "index.docker.io/dagger:latest@sha256:a89cb097693dd354de598d279c304a1c73ee550fbfff6d9ee515568e0c749cfe" -#Ref: string - -// Container image config. See [OCI](https://www.opencontainers.org/). -#ImageConfig: { - user?: string - expose?: [string]: {} - env?: [string]: string - entrypoint?: [...string] - cmd?: [...string] - volume?: [string]: {} - workdir?: string - label?: [string]: string - stopsignal?: string - healthcheck?: #HealthCheck - argsescaped?: bool - onbuild?: [...string] - stoptimeout?: int - shell?: [...string] -} - -#HealthCheck: { - test?: [...string] - interval?: int - timeout?: int - startperiod?: int - retries?: int -} +import ( + "list" + "dagger.io/dagger" +) // Upload a container image to a remote repository #Push: { $dagger: task: _name: "Push" // Target repository address - dest: #Ref + dest: dagger.#Ref // Filesystem contents to push - input: #FS + input: dagger.#FS // Container image config - config: #ImageConfig + config: dagger.#ImageConfig // Authentication auth?: { username: string - secret: #Secret + secret: dagger.#Secret } // Complete ref of the pushed image, including digest - result: #Ref + result: dagger.#Ref } // Download a container image from a remote repository @@ -65,22 +33,22 @@ import "list" $dagger: task: _name: "Pull" // Repository source ref - source: #Ref + source: dagger.#Ref // Authentication auth?: { username: string - secret: #Secret + secret: dagger.#Secret } // Root filesystem of downloaded image - output: #FS + output: dagger.#FS // Image digest digest: string // Downloaded container image config - config: #ImageConfig + config: dagger.#ImageConfig } // Build a container image using a Dockerfile @@ -88,7 +56,7 @@ import "list" $dagger: task: _name: "Dockerfile" // Source directory to build - source: #FS + source: dagger.#FS dockerfile: *{ path: string | *"Dockerfile" @@ -99,7 +67,7 @@ import "list" // Authentication auth: [registry=string]: { username: string - secret: #Secret + secret: dagger.#Secret } platforms?: [...string] @@ -109,10 +77,10 @@ import "list" hosts?: [string]: string // Root filesystem produced - output: #FS + output: dagger.#FS // Container image config produced - config: #ImageConfig + config: dagger.#ImageConfig } // Export an image as a tar archive @@ -120,10 +88,10 @@ import "list" $dagger: task: _name: "Export" // Filesystem contents to export - input: #FS + input: dagger.#FS // Container image config - config: #ImageConfig + config: dagger.#ImageConfig // Name and optionally a tag in the 'name:tag' format tag: string @@ -138,19 +106,19 @@ import "list" imageID: string // Root filesystem with exported file - output: #FS + output: dagger.#FS } // Change image config #Set: { // The source image config - input: #ImageConfig + input: dagger.#ImageConfig // The config to merge - config: #ImageConfig + config: dagger.#ImageConfig // Resulting config - output: #ImageConfig & { + output: dagger.#ImageConfig & { let structs = ["env", "label", "volume", "expose"] let lists = ["onbuild"] diff --git a/pkg/dagger.io/dagger/core/secrets.cue b/pkg/dagger.io/dagger/core/secrets.cue index 8f6de379..623cca83 100644 --- a/pkg/dagger.io/dagger/core/secrets.cue +++ b/pkg/dagger.io/dagger/core/secrets.cue @@ -1,17 +1,19 @@ package core +import "dagger.io/dagger" + // Decode the contents of a secrets without leaking it. // Supported formats: json, yaml #DecodeSecret: { $dagger: task: _name: "DecodeSecret" - // A #Secret whose plain text is a JSON or YAML string - input: #Secret + // A dagger.#Secret whose plain text is a JSON or YAML string + input: dagger.#Secret format: "json" | "yaml" // A new secret or (map of secrets) derived from unmarshaling the input secret's plain text - output: #Secret | {[string]: output} + output: dagger.#Secret | {[string]: output} } // Create a new a secret from a filesystem tree @@ -19,13 +21,13 @@ package core $dagger: task: _name: "NewSecret" // Filesystem tree holding the secret - input: #FS + input: dagger.#FS // Path of the secret to read path: string // Whether to trim leading and trailing space characters from secret value trimSpace: *true | false // Contents of the secret - output: #Secret + output: dagger.#Secret } // Trim leading and trailing space characters from a secret @@ -33,8 +35,8 @@ package core $dagger: task: _name: "TrimSecret" // Original secret - input: #Secret + input: dagger.#Secret // New trimmed secret - output: #Secret + output: dagger.#Secret } diff --git a/pkg/dagger.io/dagger/dagger.cue b/pkg/dagger.io/dagger/dagger.cue deleted file mode 100644 index 644e3115..00000000 --- a/pkg/dagger.io/dagger/dagger.cue +++ /dev/null @@ -1,26 +0,0 @@ -package dagger - -import "dagger.io/dagger/core" - -#Plan: core.#Plan - -// Types - -#FS: core.#FS -#Scratch: core.#Scratch -#Secret: core.#Secret -#Service: core.#Service - -#Address: core.#Address - -// Image - -#Ref: core.#Ref -#ImageConfig: core.#ImageConfig - -#HealthCheck: core.#HealthCheck - -// Mounts - -#CacheDir: core.#CacheDir -#TempDir: core.#TempDir diff --git a/pkg/dagger.io/dagger/image.cue b/pkg/dagger.io/dagger/image.cue new file mode 100644 index 00000000..66a6e508 --- /dev/null +++ b/pkg/dagger.io/dagger/image.cue @@ -0,0 +1,36 @@ +package dagger + +// A ref is an address for a remote container image +// +// Examples: +// - "index.docker.io/dagger" +// - "dagger" +// - "index.docker.io/dagger:latest" +// - "index.docker.io/dagger:latest@sha256:a89cb097693dd354de598d279c304a1c73ee550fbfff6d9ee515568e0c749cfe" +#Ref: string + +// Container image config. See [OCI](https://www.opencontainers.org/). +#ImageConfig: { + user?: string + expose?: [string]: {} + env?: [string]: string + entrypoint?: [...string] + cmd?: [...string] + volume?: [string]: {} + workdir?: string + label?: [string]: string + stopsignal?: string + healthcheck?: #HealthCheck + argsescaped?: bool + onbuild?: [...string] + stoptimeout?: int + shell?: [...string] +} + +#HealthCheck: { + test?: [...string] + interval?: int + timeout?: int + startperiod?: int + retries?: int +} diff --git a/pkg/dagger.io/dagger/core/plan.cue b/pkg/dagger.io/dagger/plan.cue similarity index 99% rename from pkg/dagger.io/dagger/core/plan.cue rename to pkg/dagger.io/dagger/plan.cue index 468b21e5..f85400bf 100644 --- a/pkg/dagger.io/dagger/core/plan.cue +++ b/pkg/dagger.io/dagger/plan.cue @@ -1,4 +1,4 @@ -package core +package dagger // A special kind of program which `dagger` can execute. #Plan: { diff --git a/pkg/dagger.io/dagger/core/types.cue b/pkg/dagger.io/dagger/types.cue similarity index 98% rename from pkg/dagger.io/dagger/core/types.cue rename to pkg/dagger.io/dagger/types.cue index f9404fce..0e54e442 100644 --- a/pkg/dagger.io/dagger/core/types.cue +++ b/pkg/dagger.io/dagger/types.cue @@ -1,4 +1,4 @@ -package core +package dagger // A reference to a filesystem tree. // For example: diff --git a/pkg/pkg.go b/pkg/pkg.go index c25913a4..829f334b 100644 --- a/pkg/pkg.go +++ b/pkg/pkg.go @@ -31,7 +31,8 @@ var ( UniverseModule, } - DaggerPackage = fmt.Sprintf("%s/dagger/core", DaggerModule) + DaggerPackage = fmt.Sprintf("%s/dagger", DaggerModule) + DaggerCorePackage = fmt.Sprintf("%s/core", DaggerPackage) lockFilePath = "dagger.lock" ) diff --git a/pkg/universe.dagger.io/examples/todoapp/todoapp.cue b/pkg/universe.dagger.io/examples/todoapp/todoapp.cue index ae09cbc7..378f4e89 100644 --- a/pkg/universe.dagger.io/examples/todoapp/todoapp.cue +++ b/pkg/universe.dagger.io/examples/todoapp/todoapp.cue @@ -13,7 +13,7 @@ dagger.#Plan & { _nodeModulesMount: "/src/node_modules": { dest: "/src/node_modules" type: "cache" - contents: dagger.#CacheDir & { + contents: core.#CacheDir & { id: "todoapp-modules-cache" } @@ -57,7 +57,7 @@ dagger.#Plan & { "/cache/yarn": { dest: "/cache/yarn" type: "cache" - contents: dagger.#CacheDir & { + contents: core.#CacheDir & { id: "todoapp-yarn-cache" } } diff --git a/pkg/universe.dagger.io/go/container.cue b/pkg/universe.dagger.io/go/container.cue index b4338cf0..d53009dd 100644 --- a/pkg/universe.dagger.io/go/container.cue +++ b/pkg/universe.dagger.io/go/container.cue @@ -3,6 +3,7 @@ package go import ( "dagger.io/dagger" + "dagger.io/dagger/core" "universe.dagger.io/docker" ) @@ -30,7 +31,7 @@ import ( contents: source } "go assets cache": { - contents: dagger.#CacheDir & { + contents: core.#CacheDir & { id: "\(name)_assets" } dest: _cachePath diff --git a/plan/task/task.go b/plan/task/task.go index 516b7d70..937a4a9b 100644 --- a/plan/task/task.go +++ b/plan/task/task.go @@ -20,6 +20,11 @@ var ( cue.Str("$dagger"), cue.Str("task"), cue.Hid("_name", pkg.DaggerPackage)) + corePath = cue.MakePath( + cue.Str("$dagger"), + cue.Str("task"), + cue.Hid("_name", pkg.DaggerCorePackage)) + paths = []cue.Path{corePath, typePath} ) // State is the state of the task. @@ -64,12 +69,7 @@ func Lookup(v *compiler.Value) (Task, error) { return nil, ErrNotTask } - typ := v.LookupPath(typePath) - if !typ.Exists() { - return nil, ErrNotTask - } - - typeString, err := typ.String() + typeString, err := lookupType(v) if err != nil { return nil, err } @@ -81,3 +81,13 @@ func Lookup(v *compiler.Value) (Task, error) { return t, nil } + +func lookupType(v *compiler.Value) (string, error) { + for _, path := range paths { + typ := v.LookupPath(path) + if typ.Exists() { + return typ.String() + } + } + return "", ErrNotTask +}