Skip to content

Commit

Permalink
Checks if mount's source directory exists (#92)
Browse files Browse the repository at this point in the history
* Checks for mount's source dir existance

If someone removes a bind mount dir of a dependend container, or an exec
container, like `rm -r ${YB_CLI_BUILD_DIR}/containers/<something>`, the
CLI tries to run it, Docker errors saying that this directory doesn't
exist on the host.

This adds a check mounts step when preparing the Exection Environment
for `yb exec`

* PR feedback

Co-authored-by: Ridai Govinda Pombo <[email protected]>
  • Loading branch information
Ridai Govinda Pombo and Ridai Govinda Pombo authored May 25, 2020
1 parent ba322dd commit bf9111e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion workspace/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package workspace
import (
"crypto/sha256"
"fmt"
"github.com/yourbase/narwhal"
. "github.com/yourbase/yb/plumbing"
"github.com/yourbase/yb/plumbing/log"
"github.com/yourbase/yb/runtime"
Expand Down Expand Up @@ -151,6 +152,18 @@ func (p Package) ExecuteToWriter(runtimeCtx *runtime.Runtime, output io.Writer)
return nil
}

func (p Package) checkMounts(cd *narwhal.ContainerDefinition, srcDir string) error {
for _, mount := range cd.Mounts {
parts := strings.Split(mount, ":")
if len(parts) == 2 {
src := filepath.Join(srcDir, parts[0])
err := MkdirAsNeeded(src)
return err
}
}
return nil
}

func (p Package) ExecutionRuntime(environment string) (*runtime.Runtime, error) {
manifest := p.Manifest
containers := manifest.Exec.Dependencies.ContainerList()
Expand All @@ -159,12 +172,18 @@ func (p Package) ExecutionRuntime(environment string) (*runtime.Runtime, error)
runtimeCtx := runtime.NewRuntime(contextId, p.BuildRoot())

localContainerWorkDir := filepath.Join(p.BuildRoot(), "containers")
MkdirAsNeeded(localContainerWorkDir)
if err := MkdirAsNeeded(localContainerWorkDir); err != nil {
return nil, fmt.Errorf("Unable to set host container work dir: %v", err)
}

log.Infof("Will use %s as the dependency work dir", localContainerWorkDir)

for _, cd := range containers {
cd.LocalWorkDir = localContainerWorkDir
if err := p.checkMounts(&cd, localContainerWorkDir); err != nil {
return nil, fmt.Errorf("Unable to set host container mount dir: %v", err)
}

_, err := runtimeCtx.AddContainer(cd)
if err != nil {
return nil, fmt.Errorf("Couldn't start container dependency: %v", err)
Expand Down

0 comments on commit bf9111e

Please sign in to comment.