func (ctx *BuildContext) Cleanup() error {
	return os.RemoveAll(ctx.stagesDir)
}
Cleanup cleans up files kept across stages after the build is completed.
package context
import (
	"encoding/base64"
	"fmt"
	"os"
	"path/filepath"
	"github.com/uber/makisu/lib/pathutils"
	"github.com/uber/makisu/lib/snapshot"
	"github.com/uber/makisu/lib/storage"
	"github.com/andres-erbsen/clock"
)
const (
	_stagesDir = "stages"
)
type BuildContext struct {
	RootDir    string  
	ContextDir string  
	StageVars map[string]string
	MemFS      *snapshot.MemFS      
	ImageStore *storage.ImageStore  
	CopyOps   []*snapshot.CopyOperation
	MustScan  bool
	stagesDir string  
}
func NewBuildContext(
	rootDir, contextDir string, imageStore *storage.ImageStore) (*BuildContext, error) {
	stagesDir := filepath.Join(imageStore.SandboxDir, _stagesDir)
	if err := os.MkdirAll(stagesDir, os.ModePerm); err != nil {
		return nil, fmt.Errorf("create stages dir: %s", err)
	}
	blacklist := append(pathutils.DefaultBlacklist, contextDir, imageStore.RootDir)
	memFS, err := snapshot.NewMemFS(clock.New(), rootDir, blacklist)
	if err != nil {
		return nil, fmt.Errorf("init memfs: %s", err)
	}
	return &BuildContext{
		RootDir:    rootDir,
		ContextDir: contextDir,
		StageVars:  make(map[string]string, 0),
		MemFS:      memFS,
		ImageStore: imageStore,
		CopyOps:    make([]*snapshot.CopyOperation, 0),
		MustScan:   false,
		stagesDir:  stagesDir,
	}, nil
}
func (ctx *BuildContext) CopyFromRoot(alias string) string {
	dirname := base64.URLEncoding.EncodeToString([]byte(alias))
	return filepath.Join(ctx.stagesDir, string(dirname))
}