-
Notifications
You must be signed in to change notification settings - Fork 8
/
create.go
51 lines (41 loc) · 1.49 KB
/
create.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 terminal
import (
"context"
"github.com/spf13/cobra"
"namespacelabs.dev/foundation/internal/cli/cmd/cluster"
"namespacelabs.dev/foundation/internal/cli/fncobra"
"namespacelabs.dev/foundation/internal/fnerrors"
"namespacelabs.dev/go-ids"
)
func newCreateCmd() *cobra.Command {
run := &cobra.Command{
Use: "create",
Short: "Creates a new instance that can be used as a terminal.",
Args: cobra.NoArgs,
}
image := run.Flags().String("image", "", "Which image to run.")
machineType := run.Flags().String("machine_type", "", "Specify the machine type.")
duration := run.Flags().Duration("duration", 0, "For how long to run the ephemeral environment.")
run.RunE = fncobra.RunE(func(ctx context.Context, args []string) error {
if *image == "" {
return fnerrors.New("--image is required")
}
opts := cluster.CreateContainerOpts{
Name: ids.NewRandomBase32ID(6),
Image: *image,
Args: []string{"sleep", "infinity"},
EnableDocker: true,
ForwardNscState: true,
Features: []string{"EXP_USE_CONTAINER_AS_TERMINAL_SOURCE"},
}
resp, err := cluster.CreateContainerInstance(ctx, *machineType, *duration, "", false, opts)
if err != nil {
return err
}
return cluster.PrintCreateContainersResult(ctx, "plain", resp)
})
return run
}