fix lint errors, enable CI
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
// buildkit
|
||||
bk "github.com/moby/buildkit/client"
|
||||
_ "github.com/moby/buildkit/client/connhelper/dockercontainer"
|
||||
_ "github.com/moby/buildkit/client/connhelper/dockercontainer" // import the container connection driver
|
||||
|
||||
// docker output
|
||||
"github.com/containerd/console"
|
||||
@@ -188,7 +188,7 @@ func (c *Client) buildfn(ctx context.Context, ch chan *bk.SolveStatus, w io.Writ
|
||||
}
|
||||
|
||||
// Read tar export stream from buildkit Build(), and extract cue output
|
||||
func (c *Client) outputfn(ctx context.Context, r io.Reader, out *Value) func() error {
|
||||
func (c *Client) outputfn(_ context.Context, r io.Reader, out *Value) func() error {
|
||||
return func() error {
|
||||
defer debugf("outputfn complete")
|
||||
tr := tar.NewReader(r)
|
||||
@@ -230,7 +230,7 @@ type Node struct {
|
||||
}
|
||||
|
||||
func (n Node) ComponentPath() cue.Path {
|
||||
var parts []cue.Selector
|
||||
parts := []cue.Selector{}
|
||||
for _, sel := range n.Path.Selectors() {
|
||||
if strings.HasPrefix(sel.String(), "#") {
|
||||
break
|
||||
@@ -326,7 +326,6 @@ func (c *Client) printfn(ctx context.Context, ch, ch2 chan *bk.SolveStatus) func
|
||||
// see proto 67
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -14,10 +14,7 @@ func (c *Component) Value() *Value {
|
||||
|
||||
func (c *Component) Exists() bool {
|
||||
// Does #dagger exist?
|
||||
if c.Config().Err() != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return c.Config().Err() == nil
|
||||
}
|
||||
|
||||
// Return the contents of the "#dagger" annotation.
|
||||
|
@@ -32,7 +32,7 @@ func TestValidateSimpleComponent(t *testing.T) {
|
||||
}
|
||||
n := 0
|
||||
if err := s.Walk(func(op *Op) error {
|
||||
n += 1
|
||||
n++
|
||||
return nil
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@@ -138,7 +138,7 @@ func (op *Op) Local(ctx context.Context, fs FS, out Fillable) (FS, error) {
|
||||
}
|
||||
|
||||
func (op *Op) Exec(ctx context.Context, fs FS, out Fillable) (FS, error) {
|
||||
var opts []llb.RunOption
|
||||
opts := []llb.RunOption{}
|
||||
var cmd struct {
|
||||
Args []string
|
||||
Env map[string]string
|
||||
@@ -151,11 +151,6 @@ func (op *Op) Exec(ctx context.Context, fs FS, out Fillable) (FS, error) {
|
||||
opts = append(opts, llb.WithCustomName(op.v.Path().String()))
|
||||
// args
|
||||
opts = append(opts, llb.Args(cmd.Args))
|
||||
// dir
|
||||
dir := cmd.Dir
|
||||
if dir == "" {
|
||||
dir = "/"
|
||||
}
|
||||
// env
|
||||
for k, v := range cmd.Env {
|
||||
opts = append(opts, llb.AddEnv(k, v))
|
||||
|
@@ -17,7 +17,7 @@ func TestLocalMatch(t *testing.T) {
|
||||
}
|
||||
n := 0
|
||||
err = op.Walk(func(op *Op) error {
|
||||
n += 1
|
||||
n++
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -44,7 +44,7 @@ func TestCopyMatch(t *testing.T) {
|
||||
}
|
||||
n := 0
|
||||
err = op.Walk(func(op *Op) error {
|
||||
n += 1
|
||||
n++
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
@@ -18,7 +18,7 @@ func TestLocalScript(t *testing.T) {
|
||||
}
|
||||
n := 0
|
||||
err = s.Walk(func(op *Op) error {
|
||||
n += 1
|
||||
n++
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
@@ -10,14 +10,14 @@ package dagger
|
||||
// The DAG architecture has many benefits:
|
||||
// - Because DAGs are made of nodes executing in parallel, they are easy to scale.
|
||||
// - Because all inputs and outputs are snapshotted and content-addressed, DAGs
|
||||
// can easily be made repeatable, can be cached aggressively, and can be replayed
|
||||
// at will.
|
||||
// can easily be made repeatable, can be cached aggressively, and can be replayed
|
||||
// at will.
|
||||
// - Because nodes are executed by the same container engine as docker-build, DAGs
|
||||
// can be developed using any language or technology capable of running in a docker.
|
||||
// Dockerfiles and docker images are natively supported for maximum compatibility.
|
||||
// can be developed using any language or technology capable of running in a docker.
|
||||
// Dockerfiles and docker images are natively supported for maximum compatibility.
|
||||
//
|
||||
// - Because DAGs are programmed declaratively with a powerful configuration language,
|
||||
// they are much easier to test, debug and refactor than traditional programming languages.
|
||||
// they are much easier to test, debug and refactor than traditional programming languages.
|
||||
//
|
||||
// To execute a DAG, the dagger runtime JIT-compiles it to a low-level format called
|
||||
// llb, and executes it with buildkit.
|
||||
@@ -42,11 +42,9 @@ package dagger
|
||||
// The contents of a #dagger annotation
|
||||
#ComponentConfig: {
|
||||
// script to compute the value
|
||||
compute?: #Script
|
||||
compute?: #Script
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Any component can be referenced as a directory, since
|
||||
// every dagger script outputs a filesystem state (aka a directory)
|
||||
#Dir: #Component
|
||||
@@ -61,19 +59,19 @@ package dagger
|
||||
do: "export"
|
||||
// Source path in the container
|
||||
source: string
|
||||
format: "json"|"yaml"|*"string"|"number"|"boolean"
|
||||
format: "json" | "yaml" | *"string" | "number" | "boolean"
|
||||
}
|
||||
|
||||
#Local: {
|
||||
do: "local"
|
||||
dir: string
|
||||
do: "local"
|
||||
dir: string
|
||||
include?: [...string] | *[]
|
||||
}
|
||||
|
||||
// FIXME: bring back load (more efficient than copy)
|
||||
|
||||
#Load: {
|
||||
do: "load"
|
||||
do: "load"
|
||||
from: #Component | #Script
|
||||
}
|
||||
|
||||
@@ -82,40 +80,40 @@ package dagger
|
||||
args: [...string]
|
||||
env?: [string]: string
|
||||
always?: true | *false
|
||||
dir: string | *"/"
|
||||
dir: string | *"/"
|
||||
mount?: [string]: #MountTmp | #MountCache | #MountComponent | #MountScript
|
||||
}
|
||||
|
||||
#MountTmp: "tmpfs"
|
||||
#MountTmp: "tmpfs"
|
||||
#MountCache: "cache"
|
||||
#MountComponent: {
|
||||
input: #Component
|
||||
path: string | *"/"
|
||||
path: string | *"/"
|
||||
}
|
||||
#MountScript: {
|
||||
input: #Script
|
||||
path: string | *"/"
|
||||
path: string | *"/"
|
||||
}
|
||||
|
||||
#FetchContainer: {
|
||||
do: "fetch-container"
|
||||
do: "fetch-container"
|
||||
ref: string
|
||||
}
|
||||
|
||||
#FetchGit: {
|
||||
do: "fetch-git"
|
||||
do: "fetch-git"
|
||||
remote: string
|
||||
ref: string
|
||||
ref: string
|
||||
}
|
||||
|
||||
#Copy: {
|
||||
do: "copy"
|
||||
from: #Script | #Component
|
||||
src?: string | *"/"
|
||||
do: "copy"
|
||||
from: #Script | #Component
|
||||
src?: string | *"/"
|
||||
dest?: string | *"/"
|
||||
}
|
||||
|
||||
#TestScript: #Script & [
|
||||
{ do: "fetch-container", ref: "alpine:latest" },
|
||||
{ do: "exec", args: ["echo", "hello", "world" ] }
|
||||
{do: "fetch-container", ref: "alpine:latest"},
|
||||
{do: "exec", args: ["echo", "hello", "world"]},
|
||||
]
|
||||
|
@@ -81,7 +81,6 @@ func testMatch(t *testing.T, src interface{}, def string) {
|
||||
t.Errorf("false positive: %s: %q", cmpDef, src)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func compile(t *testing.T, cc *Compiler, src interface{}) *Value {
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
func Fatalf(msg string, args ...interface{}) {
|
||||
if !strings.HasSuffix(msg, "\n") {
|
||||
msg = msg + "\n"
|
||||
msg += "\n"
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, msg, args...)
|
||||
os.Exit(1)
|
||||
@@ -20,7 +20,7 @@ func Fatal(msg interface{}) {
|
||||
|
||||
func Info(msg string, args ...interface{}) {
|
||||
if !strings.HasSuffix(msg, "\n") {
|
||||
msg = msg + "\n"
|
||||
msg += "\n"
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "[info] "+msg, args...)
|
||||
}
|
||||
|
@@ -2,53 +2,27 @@ package dagger
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"cuelang.org/go/cue"
|
||||
cueerrors "cuelang.org/go/cue/errors"
|
||||
cueformat "cuelang.org/go/cue/format"
|
||||
"github.com/moby/buildkit/client/llb"
|
||||
"github.com/moby/buildkit/client/llb/imagemetaresolver"
|
||||
)
|
||||
|
||||
func cuePrint(v cue.Value) (string, error) {
|
||||
b, err := cueformat.Node(v.Syntax())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(b), nil
|
||||
}
|
||||
|
||||
func cueErr(err error) error {
|
||||
return fmt.Errorf("%s", cueerrors.Details(err, &cueerrors.Config{}))
|
||||
}
|
||||
|
||||
func debugJSON(v interface{}) {
|
||||
if os.Getenv("DEBUG") != "" {
|
||||
e := json.NewEncoder(os.Stderr)
|
||||
e.SetIndent("", " ")
|
||||
e.Encode(v)
|
||||
}
|
||||
}
|
||||
|
||||
func debugf(msg string, args ...interface{}) {
|
||||
if !strings.HasSuffix(msg, "\n") {
|
||||
msg = msg + "\n"
|
||||
msg += "\n"
|
||||
}
|
||||
if os.Getenv("DEBUG") != "" {
|
||||
fmt.Fprintf(os.Stderr, msg, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func debug(msg string) {
|
||||
if os.Getenv("DEBUG") != "" {
|
||||
fmt.Fprintln(os.Stderr, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func randomID(size int) (string, error) {
|
||||
b := make([]byte, size)
|
||||
_, err := rand.Read(b)
|
||||
@@ -58,14 +32,6 @@ func randomID(size int) (string, error) {
|
||||
return fmt.Sprintf("%x", b), nil
|
||||
}
|
||||
|
||||
// LLB Helper to pull a Docker image + all its metadata
|
||||
func llbDockerImage(ref string) llb.State {
|
||||
return llb.Image(
|
||||
ref,
|
||||
llb.WithMetaResolver(imagemetaresolver.Default()),
|
||||
)
|
||||
}
|
||||
|
||||
func cueStringsToCuePath(parts ...string) cue.Path {
|
||||
selectors := make([]cue.Selector, 0, len(parts))
|
||||
for _, part := range parts {
|
||||
@@ -82,9 +48,3 @@ func cuePathToStrings(p cue.Path) []string {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Validate a cue path, and return a canonical version
|
||||
func cueCleanPath(p string) (string, error) {
|
||||
cp := cue.ParsePath(p)
|
||||
return cp.String(), cp.Err()
|
||||
}
|
||||
|
@@ -35,7 +35,8 @@ func (v *Value) Unlock() {
|
||||
func (v *Value) Lookup(path ...string) *Value {
|
||||
v.Lock()
|
||||
defer v.Unlock()
|
||||
return v.Wrap(v.Unwrap().Lookup(path...))
|
||||
|
||||
return v.Wrap(v.Unwrap().LookupPath(cueStringsToCuePath(path...)))
|
||||
}
|
||||
|
||||
func (v *Value) LookupPath(p cue.Path) *Value {
|
||||
@@ -176,7 +177,7 @@ func (v *Value) RangeList(fn func(int, *Value) error) error {
|
||||
if err := fn(i, v.Wrap(it.Value())); err != nil {
|
||||
return err
|
||||
}
|
||||
i += 1
|
||||
i++
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user