prepare the transition to #Plan.context
This change helps the transition between `dagger input` and `#Plan.context`. In summary, the codebase now relies on a *context* for execution with mapping to *IDs*. In the future, *context* will come from a `#Plan.context`. In the meantime, a bridge converts `dagger input` to a plan context. This allows both *old* and *new* style configurations to co-exist with the same underlying engine. - Implement `plancontext`. Context holds the execution context for a plan. Currently this includes the platform, local directories, secrets and services (e.g. unix/npipe). - Contextual data can be registered at any point. In the future, this will be done by `#Plan.context` - Migrated the `dagger input` codebase to register inputs in a `plancontext` - Migrated low-level types/operations to the *Context ID* pattern. - `dagger.#Stream` now only includes an `id` (instead of `unix` path) - `dagger.#Secret` still includes only an ID, but now it's based off `plancontext` - `op.#Local` now only includes an `id` (instead of `path`, `include`, `exclude`. Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"go.dagger.io/dagger/cmd/dagger/logger"
|
||||
"go.dagger.io/dagger/compiler"
|
||||
"go.dagger.io/dagger/environment"
|
||||
"go.dagger.io/dagger/plancontext"
|
||||
"go.dagger.io/dagger/solver"
|
||||
"go.dagger.io/dagger/state"
|
||||
"go.mozilla.org/sops/v3"
|
||||
@@ -43,6 +44,7 @@ var computeCmd = &cobra.Command{
|
||||
doneCh := common.TrackCommand(ctx, cmd)
|
||||
|
||||
st := &state.State{
|
||||
Context: plancontext.New(),
|
||||
Name: "FIXME",
|
||||
Platform: platforms.Format(specs.Platform{OS: "linux", Architecture: "amd64"}),
|
||||
Path: args[0],
|
||||
@@ -191,7 +193,12 @@ var computeCmd = &cobra.Command{
|
||||
lg.Fatal().Err(err).Msg("failed to compile inputs")
|
||||
}
|
||||
|
||||
err = cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
env, err := environment.New(st)
|
||||
if err != nil {
|
||||
lg.Fatal().Msg("unable to create environment")
|
||||
}
|
||||
|
||||
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
|
||||
// check that all inputs are set
|
||||
checkInputs(ctx, env)
|
||||
|
||||
|
@@ -77,8 +77,13 @@ var editCmd = &cobra.Command{
|
||||
st.Plan = newState.Plan
|
||||
st.Inputs = newState.Inputs
|
||||
|
||||
env, err := environment.New(st)
|
||||
if err != nil {
|
||||
lg.Fatal().Msg("unable to create environment")
|
||||
}
|
||||
|
||||
cl := common.NewClient(ctx)
|
||||
err = cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
|
||||
// check for cue errors by scanning all the inputs
|
||||
_, err := env.ScanInputs(ctx, true)
|
||||
if err != nil {
|
||||
|
@@ -1,33 +0,0 @@
|
||||
package input
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"go.dagger.io/dagger/cmd/dagger/logger"
|
||||
"go.dagger.io/dagger/state"
|
||||
)
|
||||
|
||||
var containerCmd = &cobra.Command{
|
||||
Use: "container TARGET CONTAINER-IMAGE",
|
||||
Short: "Add a container image as input artifact",
|
||||
Args: cobra.ExactArgs(2),
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
// Fix Viper bug for duplicate flags:
|
||||
// https://github.com/spf13/viper/issues/233
|
||||
if err := viper.BindPFlags(cmd.Flags()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
lg := logger.New()
|
||||
ctx := lg.WithContext(cmd.Context())
|
||||
|
||||
updateEnvironmentInput(ctx, cmd, args[0], state.DockerInput(args[1]))
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
if err := viper.BindPFlags(containerCmd.Flags()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
@@ -41,8 +41,13 @@ var listCmd = &cobra.Command{
|
||||
|
||||
doneCh := common.TrackProjectCommand(ctx, cmd, project, st)
|
||||
|
||||
c := common.NewClient(ctx)
|
||||
err := c.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
env, err := environment.New(st)
|
||||
if err != nil {
|
||||
lg.Fatal().Msg("unable to create environment")
|
||||
}
|
||||
|
||||
cl := common.NewClient(ctx)
|
||||
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
|
||||
inputs, err := env.ScanInputs(ctx, false)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@@ -25,7 +25,6 @@ func init() {
|
||||
Cmd.AddCommand(
|
||||
dirCmd,
|
||||
gitCmd,
|
||||
containerCmd,
|
||||
secretCmd,
|
||||
textCmd,
|
||||
jsonCmd,
|
||||
@@ -52,11 +51,15 @@ func updateEnvironmentInput(ctx context.Context, cmd *cobra.Command, target stri
|
||||
Value: target,
|
||||
})
|
||||
|
||||
cl := common.NewClient(ctx)
|
||||
|
||||
st.SetInput(target, input)
|
||||
|
||||
err := cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
env, err := environment.New(st)
|
||||
if err != nil {
|
||||
lg.Fatal().Msg("unable to create environment")
|
||||
}
|
||||
|
||||
cl := common.NewClient(ctx)
|
||||
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
|
||||
// the inputs are set, check for cue errors by scanning all the inputs
|
||||
_, err := env.ScanInputs(ctx, true)
|
||||
if err != nil {
|
||||
|
@@ -40,8 +40,13 @@ var listCmd = &cobra.Command{
|
||||
|
||||
doneCh := common.TrackProjectCommand(ctx, cmd, project, st)
|
||||
|
||||
env, err := environment.New(st)
|
||||
if err != nil {
|
||||
lg.Fatal().Msg("unable to create environment")
|
||||
}
|
||||
|
||||
cl := common.NewClient(ctx)
|
||||
err := cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
|
||||
return ListOutputs(ctx, env, true)
|
||||
})
|
||||
|
||||
|
@@ -61,7 +61,12 @@ var upCmd = &cobra.Command{
|
||||
|
||||
cl := common.NewClient(ctx)
|
||||
|
||||
err = cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
env, err := environment.New(st)
|
||||
if err != nil {
|
||||
lg.Fatal().Msg("unable to create environment")
|
||||
}
|
||||
|
||||
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
|
||||
// check that all inputs are set
|
||||
if err := checkInputs(ctx, env); err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user