impl test, log patterns when .daggerignore found, lint, fix stdlib/file test imports
Signed-off-by: Tony Worm <tony@hofstadter.io>
This commit is contained in:
parent
a1ba7aa59c
commit
3dab86694e
@ -7,15 +7,16 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/distribution/reference"
|
||||
bk "github.com/moby/buildkit/client"
|
||||
"github.com/moby/buildkit/client/llb"
|
||||
dockerfilebuilder "github.com/moby/buildkit/frontend/dockerfile/builder"
|
||||
"github.com/moby/buildkit/frontend/dockerfile/dockerignore"
|
||||
bkgw "github.com/moby/buildkit/frontend/gateway/client"
|
||||
bkpb "github.com/moby/buildkit/solver/pb"
|
||||
"github.com/moby/buildkit/frontend/dockerfile/dockerignore"
|
||||
"github.com/rs/zerolog/log"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
@ -271,29 +272,26 @@ func (p *Pipeline) Local(ctx context.Context, op *compiler.Value, st llb.State)
|
||||
llb.SessionID(p.s.SessionID()),
|
||||
llb.FollowPaths([]string{daggerignoreFilename}),
|
||||
llb.SharedKeyHint(dir+"-"+daggerignoreFilename),
|
||||
llb.WithCustomName(p.vertexNamef("Load %s", daggerignoreFilename)),
|
||||
llb.WithCustomName(p.vertexNamef("Try loading %s", path.Join(dir, daggerignoreFilename))),
|
||||
)
|
||||
|
||||
var daggerignore []byte
|
||||
|
||||
def, err := p.s.Marshal(ctx, daggerignoreState)
|
||||
if err != nil {
|
||||
return st, err
|
||||
}
|
||||
ref, err := p.s.SolveRequest(ctx, bkgw.SolveRequest{
|
||||
Definition: def,
|
||||
})
|
||||
ref, err := p.s.Solve(ctx, daggerignoreState)
|
||||
if err != nil {
|
||||
return st, err
|
||||
}
|
||||
|
||||
// try to read file
|
||||
var daggerignore []byte
|
||||
// bool in case file is empty
|
||||
ignorefound := true
|
||||
daggerignore, err = ref.ReadFile(ctx, bkgw.ReadRequest{
|
||||
Filename: daggerignoreFilename,
|
||||
})
|
||||
// hack for string introspection because !errors.Is(err, os.ErrNotExist) does not work, same for fs
|
||||
if err != nil && !strings.Contains(err.Error(), ".daggerignore: no such file or directory") {
|
||||
return st, err
|
||||
if err != nil {
|
||||
if !strings.Contains(err.Error(), ".daggerignore: no such file or directory") {
|
||||
return st, err
|
||||
}
|
||||
ignorefound = false
|
||||
}
|
||||
|
||||
// parse out excludes, works even if file does not exist
|
||||
@ -303,6 +301,14 @@ func (p *Pipeline) Local(ctx context.Context, op *compiler.Value, st llb.State)
|
||||
return st, fmt.Errorf("%w failed to parse daggerignore", err)
|
||||
}
|
||||
|
||||
// log out patterns if file exists
|
||||
if ignorefound {
|
||||
log.
|
||||
Ctx(ctx).
|
||||
Debug().
|
||||
Str("patterns", fmt.Sprint(excludes)).
|
||||
Msg("daggerignore exclude patterns")
|
||||
}
|
||||
// FIXME: Remove the `Copy` and use `Local` directly.
|
||||
//
|
||||
// Copy'ing is a costly operation which should be unnecessary.
|
||||
|
@ -1,21 +1,41 @@
|
||||
package main
|
||||
package test
|
||||
|
||||
import (
|
||||
"dagger.io/alpine"
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/llb"
|
||||
)
|
||||
|
||||
dir: dagger.#Artifact
|
||||
TestData: dagger.#Artifact
|
||||
|
||||
ignore: {
|
||||
_expected: """
|
||||
/src/b.txt
|
||||
|
||||
/src/foo:
|
||||
bar.txt
|
||||
|
||||
"""
|
||||
|
||||
TestIgnore: {
|
||||
string
|
||||
#compute: [
|
||||
llb.#FetchContainer & { ref: "debian:buster" },
|
||||
llb.#Load & {from: alpine.#Image},
|
||||
llb.#Exec & {
|
||||
args: ["bash", "-c", "ls -lh /src > /out.txt"]
|
||||
mount: "/src": { from: dir }
|
||||
args: ["sh", "-c", "ls /src/* > /out.txt"]
|
||||
mount: "/src": from: TestData
|
||||
},
|
||||
llb.#Export & {source: "/out.txt"},
|
||||
llb.#Exec & {
|
||||
args: [
|
||||
"sh",
|
||||
"-ec",
|
||||
"""
|
||||
cat > /test.txt << EOF
|
||||
\(_expected)
|
||||
EOF
|
||||
test "$(cat /out.txt)" = "$(cat /test.txt)"
|
||||
""",
|
||||
]
|
||||
},
|
||||
llb.#Export & { source: "/out.txt" },
|
||||
]
|
||||
}
|
||||
|
||||
|
2
tests/ignore/testdata/.daggerignore
vendored
Normal file
2
tests/ignore/testdata/.daggerignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
a.txt
|
||||
*/*.json
|
0
tests/ignore/testdata/a.txt
vendored
Normal file
0
tests/ignore/testdata/a.txt
vendored
Normal file
0
tests/ignore/testdata/b.txt
vendored
Normal file
0
tests/ignore/testdata/b.txt
vendored
Normal file
0
tests/ignore/testdata/foo/bar.txt
vendored
Normal file
0
tests/ignore/testdata/foo/bar.txt
vendored
Normal file
0
tests/ignore/testdata/foo/cow.json
vendored
Normal file
0
tests/ignore/testdata/foo/cow.json
vendored
Normal file
@ -1,7 +1,7 @@
|
||||
package f
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/llb"
|
||||
"dagger.io/alpine"
|
||||
"dagger.io/file"
|
||||
)
|
||||
@ -15,8 +15,8 @@ TestCreate: {
|
||||
}
|
||||
|
||||
test: #compute: [
|
||||
dagger.#Load & {from: alpine.#Image},
|
||||
dagger.#Exec & {
|
||||
llb.#Load & {from: alpine.#Image},
|
||||
llb.#Exec & {
|
||||
args: [
|
||||
"sh",
|
||||
"-ec",
|
||||
@ -38,8 +38,8 @@ TestRead: {
|
||||
from: alpine.#Image & {version: "3.10.6"}
|
||||
}
|
||||
test: #compute: [
|
||||
dagger.#Load & {from: alpine.#Image},
|
||||
dagger.#Exec & {
|
||||
llb.#Load & {from: alpine.#Image},
|
||||
llb.#Exec & {
|
||||
args: [
|
||||
"sh",
|
||||
"-ec",
|
||||
@ -64,8 +64,8 @@ TestRead2: {
|
||||
}
|
||||
|
||||
test: #compute: [
|
||||
dagger.#Load & {from: alpine.#Image},
|
||||
dagger.#Exec & {
|
||||
llb.#Load & {from: alpine.#Image},
|
||||
llb.#Exec & {
|
||||
args: [
|
||||
"sh",
|
||||
"-ec",
|
||||
@ -101,23 +101,6 @@ TestAppend: {
|
||||
new: read.contents
|
||||
|
||||
test: new & "hello worldfoo bar"
|
||||
|
||||
//test: #compute: [
|
||||
//dagger.#Load & {from: alpine.#Image},
|
||||
//dagger.#Exec & {
|
||||
//args: [
|
||||
//"sh",
|
||||
//"-ec",
|
||||
//"""
|
||||
//test "$(cat /file.txt)" = "hello worldfoo bar"
|
||||
//""",
|
||||
//]
|
||||
//mount: "/file.txt": {
|
||||
//from: append
|
||||
//path: "/file.txt"
|
||||
//}
|
||||
//},
|
||||
//]
|
||||
}
|
||||
|
||||
TestGlob: {
|
||||
|
@ -247,6 +247,11 @@ test::dockerbuild() {
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute --input-dir TestData="$d"/dockerbuild/testdata "$d"/dockerbuild
|
||||
}
|
||||
|
||||
test::daggerignore() {
|
||||
test::one "Dagger Ignore" --exit=0 \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute --input-dir TestData="$d"/ignore/testdata "$d"/ignore
|
||||
}
|
||||
|
||||
test::all(){
|
||||
local dagger="$1"
|
||||
|
||||
@ -264,6 +269,7 @@ test::all(){
|
||||
test::input "$dagger"
|
||||
test::subdir "$dagger"
|
||||
test::dockerbuild "$dagger"
|
||||
test::daggerignore "$dagger"
|
||||
|
||||
test::stdlib "$dagger"
|
||||
}
|
||||
|
Reference in New Issue
Block a user