-
Notifications
You must be signed in to change notification settings - Fork 63
/
deployer_kraftfile_unikraft.go
73 lines (59 loc) · 1.94 KB
/
deployer_kraftfile_unikraft.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package deploy
import (
"context"
"fmt"
"strings"
kcclient "sdk.kraft.cloud/client"
kcinstances "sdk.kraft.cloud/instances"
kcservices "sdk.kraft.cloud/services"
"kraftkit.sh/internal/cli/kraft/build"
)
type deployerKraftfileUnikraft struct {
args []string
}
func (deployer *deployerKraftfileUnikraft) Name() string {
return "kraftfile-runtime"
}
func (deployer *deployerKraftfileUnikraft) String() string {
if len(deployer.args) == 0 {
return "run the cwd with Kraftfile"
}
return fmt.Sprintf("run the detected Kraftfile in the cwd and use '%s' as arg(s)", strings.Join(deployer.args, " "))
}
func (deployer *deployerKraftfileUnikraft) Deployable(ctx context.Context, opts *DeployOptions, args ...string) (bool, error) {
if opts.Project == nil {
if err := opts.initProject(ctx); err != nil {
return false, err
}
}
if opts.Project.Runtime() != nil {
return false, nil
}
if opts.Project.Unikraft(ctx) == nil {
return false, fmt.Errorf("cannot package without unikraft attribute")
}
deployer.args = args
return true, nil
}
func (deployer *deployerKraftfileUnikraft) Deploy(ctx context.Context, opts *DeployOptions, args ...string) (*kcclient.ServiceResponse[kcinstances.GetResponseItem], *kcclient.ServiceResponse[kcservices.GetResponseItem], error) {
if err := build.Build(ctx, &build.BuildOptions{
Architecture: "x86_64",
DotConfig: opts.DotConfig,
ForcePull: opts.ForcePull,
Jobs: opts.Jobs,
KernelDbg: opts.KernelDbg,
NoCache: opts.NoCache,
NoConfigure: opts.NoConfigure,
NoFast: opts.NoFast,
NoFetch: opts.NoFetch,
NoUpdate: opts.NoUpdate,
Platform: "kraftcloud",
Rootfs: opts.Rootfs,
SaveBuildLog: opts.SaveBuildLog,
Workdir: opts.Workdir,
}); err != nil {
return nil, nil, fmt.Errorf("could not complete build: %w", err)
}
// Re-use the runtime deployer, which also handles packaging.
return (&deployerKraftfileRuntime{}).Deploy(ctx, opts, args...)
}