Skip to content

Commit 2eff704

Browse files
committed
use context services
1 parent e67abcb commit 2eff704

File tree

6 files changed

+47
-9
lines changed

6 files changed

+47
-9
lines changed

tools/dctl/cmd/infra.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
var (
10-
defaultServices = []string{"blueprint", "catalyst", "fuse", "envoy"}
10+
defaultServices = []string{}
1111
)
1212

1313
var infraCmd = &cobra.Command{
@@ -59,6 +59,7 @@ func init() {
5959
rootCmd.AddCommand(infraCmd)
6060
// add children
6161
infraCmd.AddCommand(infraCleanCmd)
62+
infraCleanCmd.Flags().BoolVarP(&infra.Full, "full", "f", false, "whether or not to delete data volumes associated with services (true/FALSE)")
6263
infraCleanCmd.Flags().StringSliceVarP(&infra.Services, "services", "s", defaultServices, "infra services to act on")
6364
infraCmd.AddCommand(infraInitCmd)
6465
infraInitCmd.Flags().StringSliceVarP(&infra.Services, "services", "s", defaultServices, "infra services to act on")

tools/dctl/cmd/infra/configs.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/docker/docker/api/types/mount"
1010
"github.com/docker/go-connections/nat"
1111
"github.com/docker/go-units"
12+
"github.com/steady-bytes/draft/tools/dctl/config"
1213
)
1314

1415
type (
@@ -28,7 +29,8 @@ type (
2829
)
2930

3031
var (
31-
infraConfigs = map[string]infraConfig{
32+
defaultServices = []string{"blueprint", "catalyst", "fuse", "envoy"}
33+
infraConfigs = map[string]infraConfig{
3234
"blueprint": {
3335
containerConfig: &container.Config{
3436
Image: "ghcr.io/steady-bytes/draft-core-blueprint:latest",
@@ -448,11 +450,20 @@ func containerName(infra string) string {
448450
}
449451

450452
func getInfraConfig(name string) (infraConfig, error) {
453+
dctx := config.GetContext()
451454
config, ok := infraConfigs[name]
452455
if !ok {
453456
return config, fmt.Errorf("invalid infra service name: %s", name)
454457
}
455458

459+
// apply context config overrides
460+
ctxConfig, ok := dctx.Infra[name]
461+
if ok {
462+
if ctxConfig.ImageName != "" {
463+
config.containerConfig.Image = ctxConfig.ImageName
464+
}
465+
}
466+
456467
if config.configFile != nil {
457468
path, err := configPath()
458469
if err != nil {
@@ -470,7 +481,7 @@ func getInfraConfig(name string) (infraConfig, error) {
470481
}
471482
config.hostConfig.Mounts = []mount.Mount{
472483
{
473-
Type: mount.TypeBind,
484+
Type: mount.TypeBind,
474485
Source: filepath.Join(path, name),
475486
Target: config.mountPoint.mountPath,
476487
},

tools/dctl/cmd/infra/init.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import (
66
"path/filepath"
77
"strings"
88

9+
"github.com/steady-bytes/draft/tools/dctl/config"
910
"github.com/steady-bytes/draft/tools/dctl/docker"
1011
"github.com/steady-bytes/draft/tools/dctl/output"
1112

1213
"github.com/spf13/cobra"
1314
)
1415

1516
func Init(cmd *cobra.Command, args []string) error {
17+
defineServices()
1618
ctx := cmd.Context()
1719
dockerCtl, err := docker.NewDockerController()
1820
if err != nil {
@@ -42,21 +44,21 @@ func Init(cmd *cobra.Command, args []string) error {
4244
home, err := os.UserHomeDir()
4345
if err != nil {
4446
output.Error(err)
45-
os.Exit(1)
47+
continue
4648
}
4749

4850
dirName := filepath.Join(home, ".config", "dctl", "infra")
4951
err = os.Mkdir(dirName, 0666)
5052
if err != nil && !os.IsExist(err) {
5153
output.Error(err)
52-
os.Exit(1)
54+
continue
5355
}
5456

5557
fileName := filepath.Join(dirName, fmt.Sprintf("%s.yaml", name))
5658
err = os.WriteFile(fileName, []byte(config.configFile.contents), 0666)
5759
if err != nil {
5860
output.Error(err)
59-
os.Exit(1)
61+
continue
6062
}
6163
}
6264

@@ -65,17 +67,38 @@ func Init(cmd *cobra.Command, args []string) error {
6567
home, err := os.UserHomeDir()
6668
if err != nil {
6769
output.Error(err)
68-
os.Exit(1)
70+
continue
6971
}
7072

7173
dirName := filepath.Join(home, ".config", "dctl", "infra", name)
7274
err = os.MkdirAll(dirName, 0666)
7375
if err != nil && !os.IsExist(err) {
7476
output.Error(err)
75-
os.Exit(1)
77+
continue
7678
}
7779
}
7880
}
7981

8082
return nil
8183
}
84+
85+
// defineServices sets the Services variable based off of the user
86+
// input and current context.
87+
func defineServices() {
88+
dctx := config.GetContext()
89+
90+
// if user didn't define services, use the ones defined in the context
91+
if len(Services) == 0 {
92+
Services = make([]string, len(dctx.Infra))
93+
i := 0
94+
for key := range dctx.Infra {
95+
Services[i] = key
96+
i++
97+
}
98+
}
99+
100+
// if neither user nor context defined services, use default
101+
if len(Services) == 0 {
102+
Services = defaultServices
103+
}
104+
}

tools/dctl/cmd/infra/start.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import (
1313
var (
1414
Follow bool
1515
Services []string
16+
Full bool
1617
)
1718

1819
func Start(cmd *cobra.Command, args []string) (err error) {
20+
defineServices()
1921
ctx := cmd.Context()
20-
2122
dockerCtl, err := docker.NewDockerController()
2223
if err != nil {
2324
return nil

tools/dctl/cmd/infra/status.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
func Status(cmd *cobra.Command, args []string) (err error) {
14+
defineServices()
1415
ctx := cmd.Context()
1516
dockerCtl, err := docker.NewDockerController()
1617
if err != nil {

tools/dctl/cmd/infra/stop.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
)
99

1010
func Stop(cmd *cobra.Command, args []string) (err error) {
11+
defineServices()
1112
ctx := cmd.Context()
1213
dockerCtl, err := docker.NewDockerController()
1314
if err != nil {

0 commit comments

Comments
 (0)