1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
// Copyright (c) 2018-2022, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package sources
import (
"context"
"fmt"
"os"
"path/filepath"
"github.com/sylabs/singularity/v4/pkg/build/types"
)
// ScratchConveyor only needs to hold the conveyor to have the needed data to pack
type ScratchConveyor struct {
b *types.Bundle
}
// ScratchConveyorPacker only needs to hold the conveyor to have the needed data to pack
type ScratchConveyorPacker struct {
ScratchConveyor
}
// Get just stores the source
func (c *ScratchConveyor) Get(_ context.Context, b *types.Bundle) (err error) {
c.b = b
return nil
}
// Pack puts relevant objects in a Bundle!
func (cp *ScratchConveyorPacker) Pack(context.Context) (b *types.Bundle, err error) {
err = cp.insertBaseEnv()
if err != nil {
return nil, fmt.Errorf("while inserting base environment: %v", err)
}
err = cp.insertRunScript()
if err != nil {
return nil, fmt.Errorf("while inserting runscript: %v", err)
}
return cp.b, nil
}
func (c *ScratchConveyor) insertBaseEnv() (err error) {
if err = makeBaseEnv(c.b.RootfsPath); err != nil {
return
}
return nil
}
func (cp *ScratchConveyorPacker) insertRunScript() (err error) {
err = os.WriteFile(filepath.Join(cp.b.RootfsPath, "/.singularity.d/runscript"), []byte("#!/bin/sh\n"), 0o755)
if err != nil {
return
}
return nil
}
// CleanUp removes any tmpfs owned by the conveyorPacker on the filesystem
func (c *ScratchConveyor) CleanUp() {
c.b.Remove()
}
|