github.com/apptainer/singularity@v3.1.1+incompatible/internal/pkg/build/sources/packer_sandbox.go (about)

     1  // Copyright (c) 2018, Sylabs Inc. All rights reserved.
     2  // This software is licensed under a 3-clause BSD license. Please consult the
     3  // LICENSE.md file distributed with the sources of this project regarding your
     4  // rights to use or distribute this software.
     5  
     6  package sources
     7  
     8  import (
     9  	"bytes"
    10  	"fmt"
    11  	"os/exec"
    12  
    13  	"github.com/sylabs/singularity/internal/pkg/sylog"
    14  	"github.com/sylabs/singularity/pkg/build/types"
    15  )
    16  
    17  // SandboxPacker holds the locations of where to pack from and to
    18  // Ext3Packer holds the locations of where to back from and to, aswell as image offset info
    19  type SandboxPacker struct {
    20  	srcdir string
    21  	b      *types.Bundle
    22  }
    23  
    24  // Pack puts relevant objects in a Bundle!
    25  func (p *SandboxPacker) Pack() (*types.Bundle, error) {
    26  	rootfs := p.srcdir
    27  
    28  	// copy filesystem into bundle rootfs
    29  	sylog.Debugf("Copying file system from %s to %s in Bundle\n", rootfs, p.b.Rootfs())
    30  	var stderr bytes.Buffer
    31  	cmd := exec.Command("cp", "-r", rootfs+`/.`, p.b.Rootfs())
    32  	cmd.Stderr = &stderr
    33  	if err := cmd.Run(); err != nil {
    34  		return nil, fmt.Errorf("cp Failed: %v: %v", err, stderr.String())
    35  	}
    36  
    37  	return p.b, nil
    38  }