A bunch of work for dealing with fileio but it's still seriously busted, needs rethinking
--- a/docker/build.go Wed May 27 04:03:24 2020 -0500
+++ b/docker/build.go Wed May 27 05:08:18 2020 -0500
@@ -23,6 +23,7 @@
"keep.imfreedom.org/grim/convey/environment"
"keep.imfreedom.org/grim/convey/exec"
+ "keep.imfreedom.org/grim/convey/path" "keep.imfreedom.org/grim/convey/runtime"
"keep.imfreedom.org/grim/convey/tasks"
"keep.imfreedom.org/grim/convey/yaml"
@@ -43,12 +44,20 @@
func (b *Build) Execute(name string, logger *log.Entry, env *environment.Environment, rt *runtime.Runtime) error {
fullEnv := env.Copy().Merge(rt.Environment)
- // create out task directory
- buildDir, err := rt.State.Workspace.TaskDirectory(name)
+ // create our task directory + td, err := rt.State.Workspace.CreateTaskDirectory(name) + // import all of the declared files to our task directory + for _, filespec := range b.Files { + log.Debugf("filespec: %q", filespec) + src, dst := path.ParseFilePath("", filespec) + log.Debugf("src: %q, dst: %q", src, dst) + rt.State.Workspace.Volume().Export(src, dst) dockerfile := fullEnv.Map(b.Dockerfile)
tags, err := fullEnv.MapSlice(b.Tags)
@@ -66,12 +75,12 @@
- rt.State.Workspace.Import(dockerfile, buildDir)
+ td.Import(dockerfile, filepath.Base(dockerfile)) // create the basic command
cmd := exec.NewGenerator(
- "-f", filepath.Join(buildDir, filepath.Base(dockerfile)),
+ "-f", filepath.Join(td.Path(), filepath.Base(dockerfile)), @@ -95,7 +104,7 @@
// finally add the build context
return Docker(name, cmd.Command(), rt)
--- a/docker/environment.go Wed May 27 04:03:24 2020 -0500
+++ b/docker/environment.go Wed May 27 05:08:18 2020 -0500
@@ -51,7 +51,7 @@
// create a directory in our state for the task
- envDir, err := rt.State.Workspace.TaskDirectory(name)
+ td, err := rt.State.Workspace.CreateTaskDirectory(name) @@ -63,7 +63,7 @@
err = e.Execute(name, logger, env, rt)
@@ -73,7 +73,7 @@
// Process the entries of the file and apply them to the
// state's base environment immediately.
- dest := filepath.Clean(filepath.Join(envDir, file))
+ dest := filepath.Clean(filepath.Join(td.Path(), file)) entries, err := processFile(dest, file, prefix)
--- a/docker/run.go Wed May 27 04:03:24 2020 -0500
+++ b/docker/run.go Wed May 27 05:08:18 2020 -0500
@@ -75,13 +75,13 @@
// writeScript will write a shell script to the given tempfile for the given commands
func (r *Run) writeScript(name string, rt *runtime.Runtime, fullEnv *environment.Environment) (string, string, string, error) {
// create our task directory if it doesn't exist already
- scriptsDir, err := rt.State.Workspace.TaskDirectory(name)
+ td, err := rt.State.Workspace.CreateTaskDirectory(name) // create the temp file to write the script to
- scriptFile := filepath.Join(scriptsDir, "script")
+ scriptFile := filepath.Join(td.Path(), "script") @@ -245,7 +245,7 @@
workspaceMount := fullEnv.Map(workSpace)
- "-v", rt.State.Workspace.Volume()+":"+workspaceMount,
+ "-v", rt.State.Workspace.Volume().Path()+":"+workspaceMount, "-e", "CONVEY_WORKSPACE="+workspaceMount,
--- a/kubectl/command.go Wed May 27 04:03:24 2020 -0500
+++ b/kubectl/command.go Wed May 27 05:08:18 2020 -0500
@@ -164,7 +164,7 @@
// create our scratch directory
- path, err := rt.State.Workspace.TaskDirectory(name)
+ td, err := rt.State.Workspace.CreateTaskDirectory(name) @@ -174,11 +174,11 @@
- err = c.templateNone(name, path, cmd, logger, fullEnv, rt)
+ err = c.templateNone(name, td.Path(), cmd, logger, fullEnv, rt) - err = c.templateEnvironment(name, path, cmd, logger, fullEnv, rt)
+ err = c.templateEnvironment(name, td.Path(), cmd, logger, fullEnv, rt) // if there was an error with templating bail
--- a/tasks/export.go Wed May 27 04:03:24 2020 -0500
+++ b/tasks/export.go Wed May 27 05:08:18 2020 -0500
@@ -54,13 +54,13 @@
pattern = fullEnv.Map(pattern)
src, dst := path.ParseFilePath("", pattern)
- matches, err := filepath.Glob(filepath.Join(rt.State.Workspace.Volume(), src))
+ matches, err := filepath.Glob(filepath.Join(rt.State.Workspace.Volume().Path(), src)) for _, match := range matches {
- err = rt.State.Workspace.Export(match, dst)
+ err = rt.State.Workspace.Volume().Export(match, dst) --- a/tasks/import.go Wed May 27 04:03:24 2020 -0500
+++ b/tasks/import.go Wed May 27 05:08:18 2020 -0500
@@ -61,7 +61,7 @@
for _, match := range matches {
- err = rt.State.Workspace.Import(match, dst)
+ err = rt.State.Workspace.Volume().Import(match, dst) --- a/tasks/import_test.go Wed May 27 04:03:24 2020 -0500
+++ b/tasks/import_test.go Wed May 27 05:08:18 2020 -0500
@@ -44,7 +44,7 @@
rt := runtime.NewWithEnvironment(st, env)
- // create our task and runn it.
+ // create our task and run it. importTask := &Import{Files: files}
err = importTask.Execute("", logging.NewAdapter("test"), env, rt)
@@ -54,7 +54,7 @@
for _, file := range files {
_, dst := path.ParseFilePath(st.CfgPath, file)
- _, err = os.Stat(filepath.Join(st.Workspace.Volume(), dst))
+ _, err = os.Stat(filepath.Join(st.Workspace.Volume().Path(), dst)) assert.NotEqual(t, err, os.IsNotExist(err))
--- a/workspace/fileio.go Wed May 27 04:03:24 2020 -0500
+++ b/workspace/fileio.go Wed May 27 05:08:18 2020 -0500
@@ -27,17 +27,6 @@
log "github.com/sirupsen/logrus"
-func (ws *Workspace) TaskDirectory(name string) (string, error) {
- dir := filepath.Join(ws.path, name)
- if !strings.HasSuffix(dir, "/") {
- err := os.MkdirAll(dir, 0700)
// CopyFile copies the contents from src to dst atomically.
// If dst does not exist, CopyFile creates it with permissions perm.
// If the copy fails, CopyFile aborts and dst is preserved.
@@ -69,7 +58,16 @@
func (ws *Workspace) copyDir(src, dst string, perm os.FileMode) error {
- err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
+ absDst, err := filepath.Abs(dst) + err = filepath.Walk(src, func(path string, info os.FileInfo, err error) error { + log.Debugf("walk: path %q", path) // make sure we're copying files that are at the same level as convey.yml or
if !strings.HasPrefix(path, ws.parent) {
@@ -80,14 +78,17 @@
- // make sure we're don't try to import anything from the .convey directory
- if strings.HasPrefix(path, ws.root) {
+ // make sure we're don't descend into our destination directory. + if strings.HasPrefix(path, absDst) { + log.Debugf("%q is in our destination %q", path, absDst) // at this point we're going to do something so we need to the real
- realDst := filepath.Join(ws.volumePath, strings.TrimPrefix(path, ws.parent))
+ realDst := filepath.Join(dst, strings.TrimPrefix(path, ws.parent)) + log.Debugf("src %q; dst %q; realDst %q", path, dst, realDst) // if path is a directory, create it
@@ -108,35 +109,3 @@
-func (ws *Workspace) Import(src, dst string) error {
- file, err := os.Stat(src)
- realDst := filepath.Join(ws.volumePath, dst)
- log.Debugf("importing directory %q to %q", src, realDst)
- return ws.copyDir(src, realDst, file.Mode())
- log.Debugf("importing file %q to %q", src, realDst)
- return ws.copyFile(src, realDst, file.Mode())
-func (ws *Workspace) Export(src, dst string) error {
- file, err := os.Stat(src)
- return ws.copyDir(src, dst, file.Mode())
- return ws.copyFile(src, dst, file.Mode())
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/workspace/taskdir.go Wed May 27 05:08:18 2020 -0500
@@ -0,0 +1,86 @@
+// Copyright 2016-2020 Gary Kramlich <grim@reaperworld.com> +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + log "github.com/sirupsen/logrus" +type TaskDirectory struct { +func (ws *Workspace) CreateTaskDirectory(name string) (*TaskDirectory, error) { + dir := filepath.Join(ws.path, name) + if !strings.HasSuffix(dir, "/") { + err := os.MkdirAll(dir, 0700) +func (td *TaskDirectory) Import(src, dst string) error { + file, err := os.Stat(src) + realDst := filepath.Join(td.path, dst) + log.Debugf("importing directory %q to %q", src, realDst) + return td.ws.copyDir(src, realDst, file.Mode()) + log.Debugf("importing file %q to %q", src, realDst) + return td.ws.copyFile(src, realDst, file.Mode()) +func (td *TaskDirectory) Export(src, dst string) error { + realSrc := filepath.Join(td.path, src) + file, err := os.Stat(realSrc) + log.Debugf("importing directory %q to %q", realSrc, dst) + return td.ws.copyDir(realSrc, dst, file.Mode()) + log.Debugf("importing file %q to %q", realSrc, dst) + return td.ws.copyFile(realSrc, dst, file.Mode()) +func (td *TaskDirectory) Path() string { --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/workspace/volume.go Wed May 27 05:08:18 2020 -0500
@@ -0,0 +1,71 @@
+// Copyright 2016-2019 Gary Kramlich <grim@reaperworld.com> +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + log "github.com/sirupsen/logrus" +func (vol *Volume) Import(src, dst string) error { + file, err := os.Stat(src) + realDst := filepath.Join(vol.path, dst) + log.Debugf("importing directory %q to %q", src, realDst) + return vol.ws.copyDir(src, realDst, file.Mode()) + log.Debugf("importing file %q to %q", src, realDst) + return vol.ws.copyFile(src, realDst, file.Mode()) +func (vol *Volume) Export(src, dst string) error { + realSrc := filepath.Join(vol.path, src) + file, err := os.Stat(realSrc) + log.Debugf("importing directory %q to %q", realSrc, dst) + return vol.ws.copyDir(realSrc, dst, file.Mode()) + log.Debugf("importing file %q to %q", realSrc, dst) + return vol.ws.copyFile(realSrc, dst, file.Mode()) +func (vol *Volume) Path() string { --- a/workspace/workspace.go Wed May 27 04:03:24 2020 -0500
+++ b/workspace/workspace.go Wed May 27 05:08:18 2020 -0500
@@ -25,10 +25,10 @@
func New(parent string) (*Workspace, error) {
@@ -50,10 +50,14 @@
- volumePath: volumePath,
+ workspace.volume = &Volume{ @@ -76,6 +80,6 @@
-func (ws *Workspace) Volume() string {
+func (ws *Workspace) Volume() *Volume {