When exporting files for the build task, keep them relative to the dockerfile. Fixes #80

Fri, 28 Apr 2017 00:00:24 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Fri, 28 Apr 2017 00:00:24 -0500
changeset 309
2ba30683686f
parent 308
b9db1550f3df
child 310
56d7992d1219

When exporting files for the build task, keep them relative to the dockerfile. Fixes #80

ChangeLog file | annotate | diff | comparison | revisions
config/override_test.go file | annotate | diff | comparison | revisions
convey.yml file | annotate | diff | comparison | revisions
docker/build.go file | annotate | diff | comparison | revisions
docker/export.go file | annotate | diff | comparison | revisions
docker/import.go file | annotate | diff | comparison | revisions
tasks/util.go file | annotate | diff | comparison | revisions
tasks/util_test.go file | annotate | diff | comparison | revisions
--- a/ChangeLog	Thu Apr 27 22:52:03 2017 -0500
+++ b/ChangeLog	Fri Apr 28 00:00:24 2017 -0500
@@ -9,6 +9,7 @@
     bunch more colors.  (Fixes #77)
   * Fixed the graphviz output so that plans with graphviz reserved words no
     longer cause issues.  (Fixes #76)
+  * Fixed the build task to keep files relative to the dockerfile.  (Fixes #80)
 
 0.4.0: 20170406
   * Added convey/go-vet image
--- a/config/override_test.go	Thu Apr 27 22:52:03 2017 -0500
+++ b/config/override_test.go	Fri Apr 28 00:00:24 2017 -0500
@@ -38,8 +38,8 @@
 	return "-test-override"
 }
 
-func (l *testLoader) Filename() string {
-	return "test-loader.yml"
+func (l *testLoader) Filenames() []string {
+	return []string{"test-loader.yml"}
 }
 
 func (l *testLoader) DefaultPlan() string {
--- a/convey.yml	Thu Apr 27 22:52:03 2017 -0500
+++ b/convey.yml	Fri Apr 28 00:00:24 2017 -0500
@@ -76,14 +76,14 @@
     type: build
     dockerfile: images/bitbucket-upload/Dockerfile
     files:
-      - images/bitbucket-upload/run.sh:run.sh
+      - images/bitbucket-upload/run.sh
     tag: convey/bitbucket-upload
   build-image-checksum:
     type: build
     dockerfile: images/checksum/Dockerfile
     tag: convey/checksum
     files:
-      - images/checksum/run.sh:run.sh
+      - images/checksum/run.sh
   build-image-env:
     type: build
     dockerfile: images/env/Dockerfile
@@ -93,37 +93,37 @@
     dockerfile: images/go-build/Dockerfile
     tag: convey/go-build
     files:
-      - images/go-build/run.sh:run.sh
+      - images/go-build/run.sh
   build-image-go-build-alpine:
     type: build
     dockerfile: images/go-build-alpine/Dockerfile
     tag: convey/go-build:alpine
     files:
-      - images/go-build-alpine/run.sh:run.sh
+      - images/go-build-alpine/run.sh
   build-image-go-test:
     type: build
     dockerfile: images/go-test/Dockerfile
     tag: convey/go-test
     files:
-      - images/go-test/run.sh:run.sh
+      - images/go-test/run.sh
   build-image-go-vet:
     type: build
     dockerfile: images/go-vet/Dockerfile
     tag: convey/go-vet:latest
     files:
-      - images/go-vet/run.sh:.
+      - images/go-vet/run.sh
   build-image-rust-build-linux:
     type: build
     dockerfile: images/rust-build-linux/Dockerfile
     tag: convey/rust-build-linux
     files:
-      - images/rust-build-linux/run.sh:run.sh
+      - images/rust-build-linux/run.sh
   build-image-template:
     type: build
     dockerfile: images/template/Dockerfile
     tag: convey/template
     files:
-      - images/template/run.sh:run.sh
+      - images/template/run.sh
   build-image-workspace:
     type: build
     dockerfile: images/workspace/Dockerfile
@@ -133,7 +133,7 @@
     dockerfile: images/workspace-tools/Dockerfile
     tag: convey/workspace-tools
     files:
-      - images/workspace-tools/zglob.go:zglob.go
+      - images/workspace-tools/zglob.go
 
   # debugging tasks
   debug-env:
--- a/docker/build.go	Thu Apr 27 22:52:03 2017 -0500
+++ b/docker/build.go	Fri Apr 28 00:00:24 2017 -0500
@@ -50,9 +50,12 @@
 	}
 	defer os.RemoveAll(tmpDir)
 
+	// grab the dirname of the dockerfile to keep paths correct
+	base := filepath.Dir(b.Dockerfile)
+
 	// export the files to it
 	for _, src := range b.Files {
-		src, dest := tasks.ParseFilePath(environment.Mapper(src, fullEnv))
+		src, dest := tasks.ParseFilePath(base, environment.Mapper(src, fullEnv))
 		cleanDest := filepath.Clean(filepath.Join(tmpDir, dest))
 
 		if err = exportFile(name, ws.Name, src, cleanDest, opts.TaskTimeout); err != nil {
--- a/docker/export.go	Thu Apr 27 22:52:03 2017 -0500
+++ b/docker/export.go	Fri Apr 28 00:00:24 2017 -0500
@@ -103,7 +103,7 @@
 				return err
 			}
 		} else {
-			src, dest := tasks.ParseFilePath(file)
+			src, dest := tasks.ParseFilePath("", file)
 
 			if err := exportFile(name, ws.Name, src, dest, opts.TaskTimeout); err != nil {
 				return err
--- a/docker/import.go	Thu Apr 27 22:52:03 2017 -0500
+++ b/docker/import.go	Fri Apr 28 00:00:24 2017 -0500
@@ -39,7 +39,7 @@
 	fullEnv := environment.Merge(env, opts.Environment)
 
 	for _, file := range i.Files {
-		src, dest := tasks.ParseFilePath(environment.Mapper(file, fullEnv))
+		src, dest := tasks.ParseFilePath("", environment.Mapper(file, fullEnv))
 
 		params := map[string]interface{}{
 			"source":      src,
--- a/tasks/util.go	Thu Apr 27 22:52:03 2017 -0500
+++ b/tasks/util.go	Fri Apr 28 00:00:24 2017 -0500
@@ -26,15 +26,27 @@
 // If there is no colon, then either "." (the current working directory)
 // will be returned as the destination if the source was an item in the
 // root of the workspace; otherwise, the source will be returned as the
-// destination.
-func ParseFilePath(file string) (string, string) {
+// destination.  If base is specified it will be stripped from the destination.
+func ParseFilePath(base, file string) (string, string) {
 	parts := strings.SplitN(file, ":", 2)
 
 	if len(parts) != 1 {
-		return parts[0], parts[1]
+		return parts[0], trimBase(base, parts[1])
 	}
 
-	return parts[0], DestFromSrc(parts[0])
+	return parts[0], trimBase(base, DestFromSrc(parts[0]))
+}
+
+func trimBase(base, path string) string {
+	if base == "" {
+		return path
+	}
+
+	if !strings.HasSuffix(base, string(os.PathSeparator)) {
+		base += string(os.PathSeparator)
+	}
+
+	return strings.TrimPrefix(path, base)
 }
 
 // DestFromSrc returns "." if the given filename does not reference a
--- a/tasks/util_test.go	Thu Apr 27 22:52:03 2017 -0500
+++ b/tasks/util_test.go	Fri Apr 28 00:00:24 2017 -0500
@@ -38,9 +38,26 @@
 	}
 
 	for in, exp := range tests {
-		src, dest := ParseFilePath(in)
+		src, dest := ParseFilePath("", in)
 
 		Expect(src).To(Equal(exp.src))
 		Expect(dest).To(Equal(exp.dest))
 	}
 }
+
+func (s *tasksSuite) TestParseFilePathWithBase(t *testing.T) {
+	type data struct{ src, dest string }
+
+	tests := map[string]data{
+		"fedora/Dockerfile.fedora-25-amd64": data{"fedora/Dockerfile.fedora-25-amd64", "Dockerfile.fedora-25-amd64"},
+		"fedora/run.sh":                     data{"fedora/run.sh", "run.sh"},
+		"fedora/run.sh:fedora/run2.sh":      data{"fedora/run.sh", "run2.sh"},
+	}
+
+	for in, exp := range tests {
+		src, dest := ParseFilePath("fedora", in)
+
+		Expect(src).To(Equal(exp.src))
+		Expect(dest).To(Equal(exp.dest))
+	}
+}

mercurial