Merge pull request #1766 from thaJeztah/integrate_dockerignore

Migrate github.com/docker/docker/builder/dockerignore to BuildKit repository
v0.8
Tõnis Tiigi 2020-10-30 12:04:24 -07:00 committed by GitHub
commit cc27ed5212
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 71 additions and 3 deletions

View File

@ -14,11 +14,11 @@ import (
"strings"
"github.com/containerd/containerd/platforms"
"github.com/docker/docker/builder/dockerignore"
controlapi "github.com/moby/buildkit/api/services/control"
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/exporter/containerimage/exptypes"
"github.com/moby/buildkit/frontend/dockerfile/dockerfile2llb"
"github.com/moby/buildkit/frontend/dockerfile/dockerignore"
"github.com/moby/buildkit/frontend/dockerfile/parser"
"github.com/moby/buildkit/frontend/gateway/client"
gwpb "github.com/moby/buildkit/frontend/gateway/pb"

View File

@ -1,4 +1,4 @@
package dockerignore // import "github.com/docker/docker/builder/dockerignore"
package dockerignore
import (
"bufio"

View File

@ -0,0 +1,69 @@
package dockerignore
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
func TestReadAll(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "dockerignore-test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpDir)
di, err := ReadAll(nil)
if err != nil {
t.Fatalf("Expected not to have error, got %v", err)
}
if diLen := len(di); diLen != 0 {
t.Fatalf("Expected to have zero dockerignore entry, got %d", diLen)
}
diName := filepath.Join(tmpDir, ".dockerignore")
content := fmt.Sprintf("test1\n/test2\n/a/file/here\n\nlastfile\n# this is a comment\n! /inverted/abs/path\n!\n! \n")
err = ioutil.WriteFile(diName, []byte(content), 0777)
if err != nil {
t.Fatal(err)
}
diFd, err := os.Open(diName)
if err != nil {
t.Fatal(err)
}
defer diFd.Close()
di, err = ReadAll(diFd)
if err != nil {
t.Fatal(err)
}
if len(di) != 7 {
t.Fatalf("Expected 7 entries, got %v", len(di))
}
if di[0] != "test1" {
t.Fatal("First element is not test1")
}
if di[1] != "test2" { // according to https://docs.docker.com/engine/reference/builder/#dockerignore-file, /foo/bar should be treated as foo/bar
t.Fatal("Second element is not test2")
}
if di[2] != "a/file/here" { // according to https://docs.docker.com/engine/reference/builder/#dockerignore-file, /foo/bar should be treated as foo/bar
t.Fatal("Third element is not a/file/here")
}
if di[3] != "lastfile" {
t.Fatal("Fourth element is not lastfile")
}
if di[4] != "!inverted/abs/path" {
t.Fatal("Fifth element is not !inverted/abs/path")
}
if di[5] != "!" {
t.Fatalf("Sixth element is not !, but %s", di[5])
}
if di[6] != "!" {
t.Fatalf("Seventh element is not !, but %s", di[6])
}
}

1
vendor/modules.txt vendored
View File

@ -177,7 +177,6 @@ github.com/docker/docker/api/types/swarm/runtime
github.com/docker/docker/api/types/time
github.com/docker/docker/api/types/versions
github.com/docker/docker/api/types/volume
github.com/docker/docker/builder/dockerignore
github.com/docker/docker/client
github.com/docker/docker/daemon/cluster/provider
github.com/docker/docker/daemon/network