fix add command bug when adding remote URLs (#277)
This commit is contained in:
parent
c44c317b00
commit
52e9863810
|
|
@ -30,7 +30,7 @@ RUN make -C /go/src/github.com/awslabs/amazon-ecr-credential-helper linux-amd64
|
||||||
FROM gcr.io/cloud-builders/bazel:latest
|
FROM gcr.io/cloud-builders/bazel:latest
|
||||||
RUN git clone https://github.com/GoogleContainerTools/distroless.git
|
RUN git clone https://github.com/GoogleContainerTools/distroless.git
|
||||||
WORKDIR /distroless
|
WORKDIR /distroless
|
||||||
RUN bazel build //experimental/busybox:busybox.tar
|
RUN bazel build //experimental/busybox:busybox_tar
|
||||||
RUN tar -C /distroless/bazel-genfiles/experimental/busybox/ -xf /distroless/bazel-genfiles/experimental/busybox/busybox.tar
|
RUN tar -C /distroless/bazel-genfiles/experimental/busybox/ -xf /distroless/bazel-genfiles/experimental/busybox/busybox.tar
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
|
|
||||||
|
|
@ -20,3 +20,4 @@ COPY $file /arg
|
||||||
|
|
||||||
# Finally, test adding a remote URL, concurrently with a normal file
|
# Finally, test adding a remote URL, concurrently with a normal file
|
||||||
ADD https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v1.4.3/docker-credential-gcr_linux_386-1.4.3.tar.gz context/foo /test/all/
|
ADD https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v1.4.3/docker-credential-gcr_linux_386-1.4.3.tar.gz context/foo /test/all/
|
||||||
|
ADD https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v1.4.3-static/docker-credential-gcr_linux_amd64-1.4.3.tar.gz /destination
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ func TestRun(t *testing.T) {
|
||||||
|
|
||||||
func TestLayers(t *testing.T) {
|
func TestLayers(t *testing.T) {
|
||||||
offset := map[string]int{
|
offset := map[string]int{
|
||||||
"Dockerfile_test_add": 9,
|
"Dockerfile_test_add": 10,
|
||||||
"Dockerfile_test_scratch": 3,
|
"Dockerfile_test_scratch": 3,
|
||||||
// the Docker built image combined some of the dirs defined by separate VOLUME commands into one layer
|
// the Docker built image combined some of the dirs defined by separate VOLUME commands into one layer
|
||||||
// which is why this offset exists
|
// which is why this offset exists
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,11 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// KanikoBuildFiles is the list of files required to build kaniko
|
// KanikoBuildFiles is the list of files required to build kaniko
|
||||||
var KanikoBuildFiles = []string{"/kaniko/executor", "/kaniko/ssl/certs/ca-certificates.crt"}
|
var KanikoBuildFiles = []string{"/kaniko/executor",
|
||||||
|
"/kaniko/ssl/certs/ca-certificates.crt",
|
||||||
|
"/kaniko/docker-credential-gcr",
|
||||||
|
"/kaniko/docker-credential-ecr-login",
|
||||||
|
"/kaniko/.docker/config.json"}
|
||||||
|
|
||||||
// ScratchEnvVars are the default environment variables needed for a scratch image.
|
// ScratchEnvVars are the default environment variables needed for a scratch image.
|
||||||
var ScratchEnvVars = []string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}
|
var ScratchEnvVars = []string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/GoogleContainerTools/kaniko/pkg/constants"
|
||||||
"github.com/GoogleContainerTools/kaniko/pkg/util"
|
"github.com/GoogleContainerTools/kaniko/pkg/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
@ -94,8 +95,8 @@ func (s *Snapshotter) snapshotFiles(f io.Writer, files []string) (bool, error) {
|
||||||
if val, ok := snapshottedFiles[file]; ok && val {
|
if val, ok := snapshottedFiles[file]; ok && val {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if util.CheckWhitelist(file) {
|
if util.CheckWhitelist(file) && !isBuildFile(file) {
|
||||||
logrus.Debugf("Not adding %s to layer, as it's whitelisted", file)
|
logrus.Infof("Not adding %s to layer, as it's whitelisted", file)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
snapshottedFiles[file] = true
|
snapshottedFiles[file] = true
|
||||||
|
|
@ -118,6 +119,15 @@ func (s *Snapshotter) snapshotFiles(f io.Writer, files []string) (bool, error) {
|
||||||
return filesAdded, nil
|
return filesAdded, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isBuildFile(file string) bool {
|
||||||
|
for _, buildFile := range constants.KanikoBuildFiles {
|
||||||
|
if file == buildFile {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Snapshotter) snapShotFS(f io.Writer) (bool, error) {
|
func (s *Snapshotter) snapShotFS(f io.Writer) (bool, error) {
|
||||||
logrus.Info("Taking snapshot of full filesystem...")
|
logrus.Info("Taking snapshot of full filesystem...")
|
||||||
s.hardlinks = map[uint64]string{}
|
s.hardlinks = map[uint64]string{}
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,11 @@ func IsSrcsValid(srcsAndDest instructions.SourcesAndDest, resolvedSources []stri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there is only one source and it's a directory, docker assumes the dest is a directory
|
||||||
if len(resolvedSources) == 1 {
|
if len(resolvedSources) == 1 {
|
||||||
|
if IsSrcRemoteFileURL(resolvedSources[0]) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
fi, err := os.Lstat(filepath.Join(root, resolvedSources[0]))
|
fi, err := os.Lstat(filepath.Join(root, resolvedSources[0]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -339,6 +339,16 @@ var isSrcValidTests = []struct {
|
||||||
},
|
},
|
||||||
shouldErr: false,
|
shouldErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
srcsAndDest: []string{
|
||||||
|
testUrl,
|
||||||
|
"dest",
|
||||||
|
},
|
||||||
|
resolvedSources: []string{
|
||||||
|
testUrl,
|
||||||
|
},
|
||||||
|
shouldErr: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_IsSrcsValid(t *testing.T) {
|
func Test_IsSrcsValid(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue