-
Notifications
You must be signed in to change notification settings - Fork 9
/
exportfs.go
51 lines (39 loc) · 1.21 KB
/
exportfs.go
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
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package buildkit
import (
"context"
"io/fs"
"os"
"github.com/moby/buildkit/client"
"namespacelabs.dev/foundation/internal/compute"
"namespacelabs.dev/foundation/internal/fnfs"
"namespacelabs.dev/foundation/internal/workspace/dirs"
"namespacelabs.dev/foundation/std/tasks"
)
func exportToFS() exporter[fs.FS] { return &exportFS{} }
type exportFS struct {
outputDir string
}
func (e *exportFS) Kind() string { return "local-fs" }
func (e *exportFS) Prepare(ctx context.Context) error {
dir, err := dirs.CreateUserTempDir("buildkit", "fs")
if err != nil {
return err
}
e.outputDir = dir
compute.On(ctx).Cleanup(tasks.Action("buildkit.build-fs.cleanup"), func(ctx context.Context) error {
return os.RemoveAll(dir)
})
return nil
}
func (e *exportFS) Exports() []client.ExportEntry {
return []client.ExportEntry{{
Type: client.ExporterLocal,
OutputDir: e.outputDir,
}}
}
func (e *exportFS) Provide(context.Context, *client.SolveResponse, builtkitOpts) (fs.FS, error) {
return fnfs.Local(e.outputDir), nil
}