grim/convey

Parents b441ef947b60
Children 056ca5e1a940
Make the docker/build task call docker/export to get it's files out of the workspace
--- a/docker/build.go Thu Feb 15 01:27:37 2018 -0600
+++ b/docker/build.go Thu Feb 15 17:23:51 2018 -0600
@@ -61,21 +61,18 @@
return err
}
- // grab the dirname of the dockerfile to keep paths correct
- base := filepath.Dir(dockerfile)
-
- // export the files to it
- for _, src := range files {
- src, dest := tasks.ParseFilePath(base, src)
- cleanDest := filepath.Clean(filepath.Join(buildDir, dest))
-
- if err = exportFile(name, st.Workspace.Name(), src, cleanDest, st); err != nil {
- return err
- }
+ // Export the files from the workspace
+ fileExport := &Export{
+ Files: append(files, dockerfile),
+ Path: buildDir,
+ }
+ err = fileExport.Valid()
+ if err != nil {
+ return err
}
- // copy the dockerfile to the temp directory
- if err := exportFile(name, st.Workspace.Name(), dockerfile, buildDir, st); err != nil {
+ err = fileExport.Execute(name, logger, fullEnv, st)
+ if err != nil {
return err
}
--- a/docker/environment.go Thu Feb 15 01:27:37 2018 -0600
+++ b/docker/environment.go Thu Feb 15 17:23:51 2018 -0600
@@ -64,15 +64,21 @@
// Export the file into the temp directory and maintain the
// structure of the file (for ease of error messages, so we
// get the file a/b/c/env instead of env).
- dest := filepath.Clean(filepath.Join(envDir, file))
- if err = exportFile(name, st.Workspace.Name(), file, dest, st); err != nil {
+ e := Export{
+ Files: []string{file},
+ Path: envDir,
+ }
+
+ err = e.Execute(name, logger, env, st)
+ if err != nil {
return err
}
// Process the entries of the file and apply them to the
// state's base environment immediately.
+ dest := filepath.Clean(filepath.Join(envDir, file))
entries, err := processFile(dest, file, prefix)
if err != nil {
return err
--- a/docker/export.go Thu Feb 15 01:27:37 2018 -0600
+++ b/docker/export.go Thu Feb 15 17:23:51 2018 -0600
@@ -35,6 +35,7 @@
// the host.
type Export struct {
Files yaml.StringOrSlice `yaml:"files"`
+ Path string
}
func checkFilePattern(file string) error {
@@ -45,7 +46,7 @@
return nil
}
-func exportFile(name, workSpace, src, dest string, st *state.State) error {
+func (e *Export) file(name, workSpace, src, dest string, st *state.State) error {
dir := filepath.Dir(dest)
if err := os.MkdirAll(dir, 0777); err != nil {
return err
@@ -54,6 +55,11 @@
// build out the source path
source := workSpace + ":" + filepath.Join("/workspace", src)
+ // if we have an explict path we but the file directly in that directory
+ if e.Path != "" {
+ dest = filepath.Join(e.Path, filepath.Base(dest))
+ }
+
cmdv := []string{
"cp",
source,
@@ -63,7 +69,7 @@
return Docker(name, cmdv, st)
}
-func exportGlob(name, workSpace, mountPoint, pattern string, st *state.State) error {
+func (e *Export) glob(name, workSpace, mountPoint, pattern string, st *state.State) error {
cmdv := []string{
"run",
"--rm",
@@ -84,7 +90,7 @@
continue
}
- exportFile(name, workSpace, match, tasks.DestFromSrc(match), st)
+ e.file(name, workSpace, match, tasks.DestFromSrc(match), st)
}
return nil
@@ -112,7 +118,7 @@
return err
}
- if err := exportGlob(name, st.Workspace.Name(), mountPoint, file, st); err != nil {
+ if err := e.glob(name, st.Workspace.Name(), mountPoint, file, st); err != nil {
return err
}
} else {
@@ -124,7 +130,7 @@
return err
}
- if err := exportFile(name, st.Workspace.Name(), src, realDest, st); err != nil {
+ if err := e.file(name, st.Workspace.Name(), src, realDest, st); err != nil {
return err
}
}