[ARVADOS] updated: 2.1.0-1077-ga2dcdbb41

Git user git at public.arvados.org
Mon Jul 19 20:14:17 UTC 2021


Summary of changes:
 lib/crunchrun/crunchrun.go   |   8 ++--
 lib/crunchrun/docker.go      |   2 +-
 lib/crunchrun/executor.go    |   2 +-
 lib/crunchrun/singularity.go | 100 ++++++++++++++++++++++++++++++++++++++-----
 4 files changed, 96 insertions(+), 16 deletions(-)

       via  a2dcdbb414a73f4b4d4c395c823a07b929358aae (commit)
      from  6766d1b04bd238d05890f3ec221c65e84920dde6 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit a2dcdbb414a73f4b4d4c395c823a07b929358aae
Author: Peter Amstutz <peter.amstutz at curii.com>
Date:   Mon Jul 19 16:13:33 2021 -0400

    17813: Upload .sif file to cache project & read it from keep
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz at curii.com>

diff --git a/lib/crunchrun/crunchrun.go b/lib/crunchrun/crunchrun.go
index 59ef73e65..1937b8815 100644
--- a/lib/crunchrun/crunchrun.go
+++ b/lib/crunchrun/crunchrun.go
@@ -270,7 +270,7 @@ func (runner *ContainerRunner) LoadImage() (string, error) {
 			return "", err
 		}
 	} else {
-		runner.CrunchLog.Print("Docker image is available")
+		runner.CrunchLog.Print("Container image is available")
 	}
 	return imageID, nil
 }
@@ -1458,6 +1458,10 @@ func (runner *ContainerRunner) Run() (err error) {
 		return
 	}
 
+	// Communicate some additional configuration to the executor
+	runner.executor.SetArvadoClient(runner.containerClient, runner.ContainerKeepClient,
+		runner.Container, runner.ArvMountPoint)
+
 	// check for and/or load image
 	imageID, err := runner.LoadImage()
 	if err != nil {
@@ -1559,8 +1563,6 @@ func (runner *ContainerRunner) fetchContainerRecord() error {
 	}
 	runner.SecretMounts = sm.SecretMounts
 
-	runner.executor.SetArvadoClient(runner.containerClient, runner.Container)
-
 	return nil
 }
 
diff --git a/lib/crunchrun/docker.go b/lib/crunchrun/docker.go
index 05e540da8..4d3f7caf9 100644
--- a/lib/crunchrun/docker.go
+++ b/lib/crunchrun/docker.go
@@ -254,5 +254,5 @@ func (e *dockerExecutor) Close() {
 	e.dockerclient.ContainerRemove(context.TODO(), e.containerID, dockertypes.ContainerRemoveOptions{Force: true})
 }
 
-func (e *dockerExecutor) SetArvadoClient(containerClient *arvados.Client, container arvados.Container) {
+func (e *dockerExecutor) SetArvadoClient(containerClient *arvados.Client, keepClient IKeepClient, container arvados.Container, keepMount string) {
 }
diff --git a/lib/crunchrun/executor.go b/lib/crunchrun/executor.go
index 09258ed9d..05e9adefe 100644
--- a/lib/crunchrun/executor.go
+++ b/lib/crunchrun/executor.go
@@ -63,5 +63,5 @@ type containerExecutor interface {
 	Close()
 
 	// Give the executor access to arvados client & container info
-	SetArvadoClient(containerClient *arvados.Client, container arvados.Container)
+	SetArvadoClient(containerClient *arvados.Client, keepClient IKeepClient, container arvados.Container, keepMount string)
 }
diff --git a/lib/crunchrun/singularity.go b/lib/crunchrun/singularity.go
index 45926b065..cd03e32e5 100644
--- a/lib/crunchrun/singularity.go
+++ b/lib/crunchrun/singularity.go
@@ -6,6 +6,7 @@ package crunchrun
 
 import (
 	"fmt"
+	"io"
 	"io/ioutil"
 	"os"
 	"os/exec"
@@ -25,6 +26,8 @@ type singularityExecutor struct {
 	imageFilename   string // "sif" image
 	containerClient *arvados.Client
 	container       arvados.Container
+	keepClient      IKeepClient
+	keepMount       string
 }
 
 func newSingularityExecutor(logf func(string, ...interface{})) (*singularityExecutor, error) {
@@ -47,11 +50,12 @@ func (e *singularityExecutor) getOrCreateProject(ownerUuid string, name string,
 			arvados.Filter{"owner_uuid", "=", ownerUuid},
 			arvados.Filter{"name", "=", name},
 			arvados.Filter{"group_class", "=", "project"},
-		}})
+		},
+			Limit: 1})
 	if err != nil {
 		return nil, err
 	}
-	if len(gp.Items) > 0 {
+	if len(gp.Items) == 1 {
 		return &gp.Items[0], nil
 	}
 	if !create {
@@ -74,16 +78,56 @@ func (e *singularityExecutor) getOrCreateProject(ownerUuid string, name string,
 	return &rgroup, nil
 }
 
-func (e *singularityExecutor) ImageLoaded(string) bool {
+func (e *singularityExecutor) ImageLoaded(imageId string) bool {
 	// Check if docker image is cached in keep & if so set imageFilename
 
-	return false
+	// Cache the image to keep
+	cacheGroup, err := e.getOrCreateProject(e.container.RuntimeUserUUID, ".cache", false)
+	if err != nil {
+		e.logf("error getting '.cache' project: %v", err)
+		return false
+	}
+	imageGroup, err := e.getOrCreateProject(cacheGroup.UUID, "auto-generated singularity images", false)
+	if err != nil {
+		e.logf("error getting 'auto-generated singularity images' project: %s", err)
+		return false
+	}
+
+	collectionName := fmt.Sprintf("singularity image for %v", imageId)
+	var cl arvados.CollectionList
+	err = e.containerClient.RequestAndDecode(&cl,
+		arvados.EndpointCollectionList.Method,
+		arvados.EndpointCollectionList.Path,
+		nil, arvados.ListOptions{Filters: []arvados.Filter{
+			arvados.Filter{"owner_uuid", "=", imageGroup.UUID},
+			arvados.Filter{"name", "=", collectionName},
+		},
+			Limit: 1})
+	if err != nil {
+		e.logf("error getting collection '%v' project: %v", err)
+		return false
+	}
+	if len(cl.Items) == 0 {
+		e.logf("no cached image '%v' found", collectionName)
+		return false
+	}
+
+	path := fmt.Sprintf("%s/by_id/%s/image.sif", e.keepMount, cl.Items[0].PortableDataHash)
+	e.logf("Looking for %v", path)
+	if _, err = os.Stat(path); os.IsNotExist(err) {
+		return false
+	}
+	e.imageFilename = path
+
+	return true
 }
 
 // LoadImage will satisfy ContainerExecuter interface transforming
 // containerImage into a sif file for later use.
 func (e *singularityExecutor) LoadImage(imageTarballPath string) error {
 	if e.imageFilename != "" {
+		e.logf("using singularity image %v", e.imageFilename)
+
 		// was set by ImageLoaded
 		return nil
 	}
@@ -118,30 +162,62 @@ func (e *singularityExecutor) LoadImage(imageTarballPath string) error {
 	// Cache the image to keep
 	cacheGroup, err := e.getOrCreateProject(e.container.RuntimeUserUUID, ".cache", true)
 	if err != nil {
-		e.logf("error getting '.cache' project: %s", err)
+		e.logf("error getting '.cache' project: %v", err)
 		return nil
 	}
 	imageGroup, err := e.getOrCreateProject(cacheGroup.UUID, "auto-generated singularity images", true)
 	if err != nil {
-		e.logf("error getting 'auto-generated singularity images' project: %s", err)
+		e.logf("error getting 'auto-generated singularity images' project: %v", err)
 		return nil
 	}
 
 	parts := strings.Split(imageTarballPath, "/")
 	imageId := parts[len(parts)-1]
+	if strings.HasSuffix(imageId, ".tar") {
+		imageId = imageId[0 : len(imageId)-4]
+	}
+
+	fs, err := (&arvados.Collection{ManifestText: ""}).FileSystem(e.containerClient, e.keepClient)
+	if err != nil {
+		e.logf("error creating FileSystem: %s", err)
+	}
+
+	dst, err := fs.OpenFile("image.sif", os.O_CREATE|os.O_WRONLY, 0666)
+	if err != nil {
+		e.logf("error creating opening collection file for writing: %s", err)
+	}
+
+	src, err := os.Open(e.imageFilename)
+	if err != nil {
+		dst.Close()
+		return nil
+	}
+	defer src.Close()
+	_, err = io.Copy(dst, src)
+	if err != nil {
+		dst.Close()
+		return nil
+	}
+
+	manifestText, err := fs.MarshalManifest(".")
+	if err != nil {
+		e.logf("error creating manifest text: %s", err)
+	}
 
 	var imageCollection arvados.Collection
+	collectionName := fmt.Sprintf("singularity image for %s", imageId)
 	err = e.containerClient.RequestAndDecode(&imageCollection,
 		arvados.EndpointCollectionCreate.Method,
 		arvados.EndpointCollectionCreate.Path,
 		nil, map[string]interface{}{
 			"collection": map[string]string{
-				"owner_uuid": imageGroup.UUID,
-				"name": fmt.Sprintf("singularity image for %s", imageId),
-			}
+				"owner_uuid":    imageGroup.UUID,
+				"name":          collectionName,
+				"manifest_text": manifestText,
+			},
 		})
 	if err != nil {
-		e.logf("error creating 'auto-generated singularity images' collection: %s", err)
+		e.logf("error creating '%v' collection: %s", collectionName, err)
 	}
 
 	return nil
@@ -232,7 +308,9 @@ func (e *singularityExecutor) Close() {
 	}
 }
 
-func (e *singularityExecutor) SetArvadoClient(containerClient *arvados.Client, container arvados.Container) {
+func (e *singularityExecutor) SetArvadoClient(containerClient *arvados.Client, keepClient IKeepClient, container arvados.Container, keepMount string) {
 	e.containerClient = containerClient
 	e.container = container
+	e.keepClient = keepClient
+	e.keepMount = keepMount
 }

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list