Update dagger new
cmd to specify architecture when creating an environment
Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
parent
caa03a37cc
commit
e9de597654
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user