cmd/plan: implemented git and dir
Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
parent
6cbea26f7f
commit
c3846100b3
@ -1,6 +1,8 @@
|
|||||||
package plan
|
package plan
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"dagger.io/go/cmd/dagger/logger"
|
||||||
|
"dagger.io/go/dagger"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
@ -17,10 +19,10 @@ var dirCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
// lg := logger.New()
|
lg := logger.New()
|
||||||
// ctx := lg.WithContext(cmd.Context())
|
ctx := lg.WithContext(cmd.Context())
|
||||||
|
|
||||||
panic("not implemented")
|
updateDeploymentPlan(ctx, dagger.DirInput(args[0], []string{"*.cue", "cue.mod"}))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
package plan
|
package plan
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"dagger.io/go/cmd/dagger/logger"
|
||||||
|
"dagger.io/go/dagger"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var gitCmd = &cobra.Command{
|
var gitCmd = &cobra.Command{
|
||||||
Use: "git REMOTE REF [SUBDIR]",
|
Use: "git REMOTE [REF] [SUBDIR]",
|
||||||
Short: "Load plan from a git package",
|
Short: "Load plan from a git package",
|
||||||
Args: cobra.MinimumNArgs(2),
|
Args: cobra.RangeArgs(1, 3),
|
||||||
PreRun: func(cmd *cobra.Command, args []string) {
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
// Fix Viper bug for duplicate flags:
|
// Fix Viper bug for duplicate flags:
|
||||||
// https://github.com/spf13/viper/issues/233
|
// https://github.com/spf13/viper/issues/233
|
||||||
@ -17,10 +19,20 @@ var gitCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
// lg := logger.New()
|
lg := logger.New()
|
||||||
// ctx := lg.WithContext(cmd.Context())
|
ctx := lg.WithContext(cmd.Context())
|
||||||
|
|
||||||
panic("not implemented")
|
ref := "HEAD"
|
||||||
|
if len(args) > 1 {
|
||||||
|
ref = args[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
subDir := ""
|
||||||
|
if len(args) > 2 {
|
||||||
|
subDir = args[2]
|
||||||
|
}
|
||||||
|
|
||||||
|
updateDeploymentPlan(ctx, dagger.GitInput(args[0], ref, subDir))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
package plan
|
package plan
|
||||||
|
|
||||||
import "github.com/spf13/cobra"
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"dagger.io/go/cmd/dagger/cmd/common"
|
||||||
|
"dagger.io/go/dagger"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
// Cmd exposes the top-level command
|
// Cmd exposes the top-level command
|
||||||
var Cmd = &cobra.Command{
|
var Cmd = &cobra.Command{
|
||||||
@ -16,3 +23,20 @@ func init() {
|
|||||||
fileCmd,
|
fileCmd,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateDeploymentPlan(ctx context.Context, planSource dagger.Input) {
|
||||||
|
lg := log.Ctx(ctx)
|
||||||
|
|
||||||
|
store, err := dagger.DefaultStore()
|
||||||
|
if err != nil {
|
||||||
|
lg.Fatal().Err(err).Msg("failed to load store")
|
||||||
|
}
|
||||||
|
|
||||||
|
st := common.GetCurrentDeploymentState(ctx, store)
|
||||||
|
st.PlanSource = planSource
|
||||||
|
|
||||||
|
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.Info().Str("deploymentId", st.ID).Str("deploymentName", st.Name).Msg("updated deployment")
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user