github.com/apptainer/singularity@v3.1.1+incompatible/internal/pkg/build/sources/conveyorPacker_shub.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 "fmt" 10 "io/ioutil" 11 "os" 12 13 "github.com/sylabs/singularity/internal/pkg/sylog" 14 "github.com/sylabs/singularity/pkg/build/types" 15 "github.com/sylabs/singularity/pkg/client/shub" 16 ) 17 18 // ShubConveyorPacker only needs to hold the conveyor to have the needed data to pack 19 type ShubConveyorPacker struct { 20 recipe types.Definition 21 b *types.Bundle 22 LocalPacker 23 } 24 25 // Get downloads container from Singularityhub 26 func (cp *ShubConveyorPacker) Get(b *types.Bundle) (err error) { 27 sylog.Debugf("Getting container from Shub") 28 29 cp.b = b 30 31 src := `shub://` + b.Recipe.Header["from"] 32 33 //create file for image download 34 f, err := ioutil.TempFile(cp.b.Path, "shub-img") 35 if err != nil { 36 return 37 } 38 defer f.Close() 39 40 cp.b.FSObjects["shubImg"] = f.Name() 41 42 // get image from singularity hub 43 if err = client.DownloadImage(cp.b.FSObjects["shubImg"], src, true, cp.b.Opts.NoHTTPS); err != nil { 44 sylog.Fatalf("failed to Get from %s: %v\n", src, err) 45 } 46 47 // insert base metadata before unpacking fs 48 if err = makeBaseEnv(cp.b.Rootfs()); err != nil { 49 return fmt.Errorf("While inserting base environment: %v", err) 50 } 51 52 cp.LocalPacker, err = GetLocalPacker(cp.b.FSObjects["shubImg"], cp.b) 53 54 return err 55 } 56 57 // CleanUp removes any tmpfs owned by the conveyorPacker on the filesystem 58 func (cp *ShubConveyorPacker) CleanUp() { 59 os.RemoveAll(cp.b.Path) 60 }