diff --git a/cmd/dagger/cmd/new.go b/cmd/dagger/cmd/new.go index 3ab0b6b3..a658418a 100644 --- a/cmd/dagger/cmd/new.go +++ b/cmd/dagger/cmd/new.go @@ -34,7 +34,7 @@ var newCmd = &cobra.Command{ st, err := project.Create(ctx, name, state.Plan{ Package: viper.GetString("package"), - }) + }, viper.GetString("architecture")) if err != nil { lg.Fatal().Err(err).Msg("failed to create environment") @@ -46,6 +46,7 @@ var newCmd = &cobra.Command{ func init() { newCmd.Flags().StringP("package", "p", "", "references the name of the Cue package within the module to use as a plan. Default: defer to cue loader") + newCmd.Flags().StringP("architecture", "a", "", "architecture of the running pipeline. Default: host architecture") if err := viper.BindPFlags(newCmd.Flags()); err != nil { panic(err) } diff --git a/state/project.go b/state/project.go index fc8d0ebc..902a2909 100644 --- a/state/project.go +++ b/state/project.go @@ -240,7 +240,7 @@ func (w *Project) Save(ctx context.Context, st *State) error { return nil } -func (w *Project) Create(ctx context.Context, name string, plan Plan) (*State, error) { +func (w *Project) Create(ctx context.Context, name string, plan Plan, arch string) (*State, error) { if _, err := w.Get(ctx, name); err == nil { return nil, ErrExist } @@ -262,6 +262,10 @@ func (w *Project) Create(ctx context.Context, name string, plan Plan) (*State, e manifestPath := path.Join(envPath, manifestFile) + if arch == "" { + arch = platforms.Format(platforms.DefaultSpec()) + } + st := &State{ Path: envPath, Project: w.Path, @@ -269,7 +273,7 @@ func (w *Project) Create(ctx context.Context, name string, plan Plan) (*State, e Package: pkg, }, Name: name, - Architecture: platforms.DefaultString(), + Architecture: arch, } data, err := yaml.Marshal(st) diff --git a/state/project_test.go b/state/project_test.go index 137a3333..7eeb7b93 100644 --- a/state/project_test.go +++ b/state/project_test.go @@ -32,9 +32,10 @@ func TestProject(t *testing.T) { // Create st, err := project.Create(ctx, "test", Plan{ Module: ".", - }) + }, "linux/amd64") require.NoError(t, err) require.Equal(t, "test", st.Name) + require.Equal(t, "linux/amd64", st.Architecture) // Open project, err = Open(ctx, root) @@ -51,6 +52,7 @@ func TestProject(t *testing.T) { env, err := project.Get(ctx, "test") require.NoError(t, err) require.Equal(t, "test", env.Name) + require.Equal(t, "linux/amd64", env.Architecture) // Save require.NoError(t, env.SetInput("foo", TextInput("bar"))) @@ -82,7 +84,7 @@ func TestEncryption(t *testing.T) { _, err = project.Create(ctx, "test", Plan{ Module: ".", - }) + }, "linux/amd64") require.NoError(t, err) // Set a plaintext input, make sure it is not encrypted