fixed inputs when input target is overriden
Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
parent
a24dbef0b7
commit
d3fc31ab57
@ -41,7 +41,7 @@ var computeCmd = &cobra.Command{
|
|||||||
for _, input := range viper.GetStringSlice("input-string") {
|
for _, input := range viper.GetStringSlice("input-string") {
|
||||||
parts := strings.SplitN(input, "=", 2)
|
parts := strings.SplitN(input, "=", 2)
|
||||||
k, v := parts[0], parts[1]
|
k, v := parts[0], parts[1]
|
||||||
err := st.AddInput(k, dagger.TextInput(v))
|
err := st.SetInput(k, dagger.TextInput(v))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lg.
|
lg.
|
||||||
Fatal().
|
Fatal().
|
||||||
@ -54,7 +54,7 @@ var computeCmd = &cobra.Command{
|
|||||||
for _, input := range viper.GetStringSlice("input-dir") {
|
for _, input := range viper.GetStringSlice("input-dir") {
|
||||||
parts := strings.SplitN(input, "=", 2)
|
parts := strings.SplitN(input, "=", 2)
|
||||||
k, v := parts[0], parts[1]
|
k, v := parts[0], parts[1]
|
||||||
err := st.AddInput(k, dagger.DirInput(v, []string{}))
|
err := st.SetInput(k, dagger.DirInput(v, []string{}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lg.
|
lg.
|
||||||
Fatal().
|
Fatal().
|
||||||
@ -67,7 +67,7 @@ var computeCmd = &cobra.Command{
|
|||||||
for _, input := range viper.GetStringSlice("input-git") {
|
for _, input := range viper.GetStringSlice("input-git") {
|
||||||
parts := strings.SplitN(input, "=", 2)
|
parts := strings.SplitN(input, "=", 2)
|
||||||
k, v := parts[0], parts[1]
|
k, v := parts[0], parts[1]
|
||||||
err := st.AddInput(k, dagger.GitInput(v, "", ""))
|
err := st.SetInput(k, dagger.GitInput(v, "", ""))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lg.
|
lg.
|
||||||
Fatal().
|
Fatal().
|
||||||
@ -98,7 +98,7 @@ var computeCmd = &cobra.Command{
|
|||||||
lg.Fatal().Msg("invalid json")
|
lg.Fatal().Msg("invalid json")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = st.AddInput("", dagger.JSONInput(string(content)))
|
err = st.SetInput("", dagger.JSONInput(string(content)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lg.Fatal().Err(err).Msg("failed to add input")
|
lg.Fatal().Err(err).Msg("failed to add input")
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ var computeCmd = &cobra.Command{
|
|||||||
content = plaintext
|
content = plaintext
|
||||||
}
|
}
|
||||||
|
|
||||||
err = st.AddInput("", dagger.YAMLInput(string(content)))
|
err = st.SetInput("", dagger.YAMLInput(string(content)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lg.Fatal().Err(err).Msg("failed to add input")
|
lg.Fatal().Err(err).Msg("failed to add input")
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ func updateDeploymentInput(ctx context.Context, target string, input dagger.Inpu
|
|||||||
}
|
}
|
||||||
|
|
||||||
st := common.GetCurrentDeploymentState(ctx, store)
|
st := common.GetCurrentDeploymentState(ctx, store)
|
||||||
st.AddInput(target, input)
|
st.SetInput(target, input)
|
||||||
|
|
||||||
if err := store.UpdateDeployment(ctx, st, nil); err != nil {
|
if err := store.UpdateDeployment(ctx, st, nil); err != nil {
|
||||||
lg.Fatal().Err(err).Str("deploymentId", st.ID).Str("deploymentName", st.Name).Msg("cannot update deployment")
|
lg.Fatal().Err(err).Str("deploymentId", st.ID).Str("deploymentName", st.Name).Msg("cannot update deployment")
|
||||||
|
@ -40,7 +40,15 @@ type inputKV struct {
|
|||||||
Value Input `json:"value,omitempty"`
|
Value Input `json:"value,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DeploymentState) AddInput(key string, value Input) error {
|
func (s *DeploymentState) SetInput(key string, value Input) error {
|
||||||
|
for i, inp := range s.Inputs {
|
||||||
|
if inp.Key != key {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Remove existing inputs with the same key
|
||||||
|
s.Inputs = append(s.Inputs[:i], s.Inputs[i+1:]...)
|
||||||
|
}
|
||||||
|
|
||||||
s.Inputs = append(s.Inputs, inputKV{Key: key, Value: value})
|
s.Inputs = append(s.Inputs, inputKV{Key: key, Value: value})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ func TestInputDir(t *testing.T) {
|
|||||||
st := &DeploymentState{
|
st := &DeploymentState{
|
||||||
PlanSource: DirInput("/tmp/source", []string{}),
|
PlanSource: DirInput("/tmp/source", []string{}),
|
||||||
}
|
}
|
||||||
require.NoError(t, st.AddInput("www.source", DirInput(".", []string{})))
|
require.NoError(t, st.SetInput("www.source", DirInput(".", []string{})))
|
||||||
|
|
||||||
deployment, err := NewDeployment(st)
|
deployment, err := NewDeployment(st)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -62,7 +62,7 @@ func TestStoreLookupByPath(t *testing.T) {
|
|||||||
st := &DeploymentState{
|
st := &DeploymentState{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
}
|
}
|
||||||
require.NoError(t, st.AddInput("foo", DirInput("/test/path", []string{})))
|
require.NoError(t, st.SetInput("foo", DirInput("/test/path", []string{})))
|
||||||
require.NoError(t, store.CreateDeployment(ctx, st))
|
require.NoError(t, store.CreateDeployment(ctx, st))
|
||||||
|
|
||||||
// Lookup by path
|
// Lookup by path
|
||||||
@ -72,7 +72,7 @@ func TestStoreLookupByPath(t *testing.T) {
|
|||||||
require.Equal(t, st.ID, r.ID)
|
require.Equal(t, st.ID, r.ID)
|
||||||
|
|
||||||
// Add a new path
|
// Add a new path
|
||||||
require.NoError(t, st.AddInput("bar", DirInput("/test/anotherpath", []string{})))
|
require.NoError(t, st.SetInput("bar", DirInput("/test/anotherpath", []string{})))
|
||||||
require.NoError(t, store.UpdateDeployment(ctx, st, nil))
|
require.NoError(t, store.UpdateDeployment(ctx, st, nil))
|
||||||
|
|
||||||
// Lookup by the previous path
|
// Lookup by the previous path
|
||||||
|
Reference in New Issue
Block a user