Skip to content

Commit f006945

Browse files
committed
feat: add is_dependency function
1 parent 2836094 commit f006945

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

pkg/devspace/context/values/values.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const (
1010
nameKey key = iota
1111
tempFolderKey
1212
commandKey
13+
dependencyKey
1314
)
1415

1516
// WithValue returns a copy of parent in which the value associated with key is val.
@@ -49,3 +50,12 @@ func CommandFrom(ctx context.Context) (string, bool) {
4950
user, ok := ctx.Value(commandKey).(string)
5051
return user, ok
5152
}
53+
54+
func WithDependency(parent context.Context, dependency bool) context.Context {
55+
return WithValue(parent, dependencyKey, dependency)
56+
}
57+
58+
func IsDependencyFrom(ctx context.Context) (bool, bool) {
59+
isDependency, ok := ctx.Value(dependencyKey).(bool)
60+
return isDependency, ok
61+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package commands
2+
3+
import (
4+
"context"
5+
"github.com/loft-sh/devspace/pkg/devspace/context/values"
6+
"mvdan.cc/sh/v3/interp"
7+
)
8+
9+
func IsDependency(ctx context.Context, args []string) error {
10+
if len(args) > 0 {
11+
return interp.NewExitStatus(1)
12+
}
13+
14+
isDependency, ok := values.IsDependencyFrom(ctx)
15+
if isDependency && ok {
16+
return interp.NewExitStatus(0)
17+
}
18+
return interp.NewExitStatus(1)
19+
}

pkg/devspace/pipeline/engine/pipelinehandler/handler.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ var PipelineCommands = map[string]func(devCtx *devspacecontext.Context, pipeline
5050
"ensure_pull_secrets": func(devCtx *devspacecontext.Context, pipeline types.Pipeline, args []string) error {
5151
return commands.EnsurePullSecrets(devCtx, args)
5252
},
53+
"is_dependency": func(devCtx *devspacecontext.Context, pipeline types.Pipeline, args []string) error {
54+
return commands.IsDependency(devCtx.Context, args)
55+
},
5356
}
5457

5558
func init() {

pkg/devspace/pipeline/pipeline.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pipeline
22

33
import (
44
"fmt"
5+
"github.com/loft-sh/devspace/pkg/devspace/context/values"
56
"strings"
67
"sync"
78

@@ -114,6 +115,8 @@ func (p *pipeline) Run(ctx *devspacecontext.Context) error {
114115
}
115116

116117
func (p *pipeline) StartNewDependencies(ctx *devspacecontext.Context, dependencies []types2.Dependency, options types.DependencyOptions) error {
118+
// mark all commands from here that they are running within a dependency
119+
ctx = ctx.WithContext(values.WithDependency(ctx.Context, true))
117120
dependencyNames := []string{}
118121
for _, dependency := range dependencies {
119122
dependencyNames = append(dependencyNames, dependency.Name())

0 commit comments

Comments
 (0)