Skip to content

Commit

Permalink
Suport version parameter in manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
discordianfish committed Mar 11, 2024
1 parent 9973714 commit f78582a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/diambra/client/submission.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (

type Manifest struct {
Image string `yaml:"image" json:"image"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
Mode Mode `yaml:"mode" json:"mode"`
Difficulty string `yaml:"difficulty,omitempty" json:"difficulty,omitempty"`
Command []string `yaml:"command,omitempty" json:"command,omitempty"`
Expand Down Expand Up @@ -89,12 +90,16 @@ func (c *Client) Submission(id int) (*Submission, error) {
func ManifestFromPath(path string) (*Manifest, error) {
manifest := &Manifest{}
if path == "-" {
return manifest, yaml.NewDecoder(os.Stdin).Decode(manifest)
d := yaml.NewDecoder(os.Stdin)
d.SetStrict(true)
return manifest, d.Decode(manifest)
}
f, err := os.Open(path)
if err != nil {
return nil, fmt.Errorf("failed to open manifest: %w", err)
}
defer f.Close()
return manifest, yaml.NewDecoder(f).Decode(manifest)
d := yaml.NewDecoder(f)
d.SetStrict(true)
return manifest, d.Decode(manifest)
}
8 changes: 8 additions & 0 deletions pkg/diambra/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type AppArgs struct {
Render bool
LockFPS bool
Sound bool
ExtraArgs []string
}

type Args []string
Expand All @@ -68,6 +69,7 @@ func (a AppArgs) Args() []string {
args.Bool("--lockFps", a.LockFPS)
args.Bool("--sound", a.Sound)
args.Int("--randomSeed", a.RandomSeed)
args = append(args, a.ExtraArgs...)
return args
}

Expand Down Expand Up @@ -166,6 +168,7 @@ func (c *EnvConfig) AddFlags(flags *pflag.FlagSet) {
flags.BoolVarP(&c.AppArgs.Render, "engine.render", "g", false, "Render graphics server side")
flags.BoolVarP(&c.AppArgs.LockFPS, "engine.lockfps", "l", false, "Lock FPS")
flags.BoolVar(&c.AppArgs.Sound, "engine.sound", false, "Enable sound")
flags.StringSliceVar(&c.AppArgs.ExtraArgs, "engine.args", []string{}, "Additional engine arguments")

// Agent flags
flags.StringVarP(&c.AgentImage, "agent.image", "a", "", "Run given agent command in container")
Expand Down Expand Up @@ -237,6 +240,7 @@ var ErrInvalidArgs = errors.New("either image, manifest path or submission id mu
type SubmissionConfig struct {
Mode string
Difficulty string
Version string
EnvVars map[string]string
Sources map[string]string
Secrets map[string]string
Expand All @@ -262,6 +266,7 @@ func (c *SubmissionConfig) RegisterCredentialsProviders() {
func (c *SubmissionConfig) AddFlags(flags *pflag.FlagSet) {
flags.StringVar(&c.Mode, "submission.mode", string(client.ModeAIvsCOM), "Mode to use for evaluation")
flags.StringVar(&c.Difficulty, "submission.difficulty", string(DifficultyEasy), "Difficulty to use for evaluation")
flags.StringVar(&c.Version, "submission.version", "", "Version to use for evaluation")
flags.StringToStringVarP(&c.EnvVars, "submission.env", "e", nil, "Environment variables to pass to the agent")
flags.StringToStringVarP(&c.Sources, "submission.source", "u", nil, "Source urls to pass to the agent")
flags.StringToStringVar(&c.Secrets, "submission.secret", nil, "Secrets to pass to the agent")
Expand Down Expand Up @@ -316,6 +321,9 @@ func (c *SubmissionConfig) Submission(config *EnvConfig, args []string) (*client
if c.Difficulty != "" {
manifest.Difficulty = c.Difficulty
}
if c.Version != "" {
manifest.Version = c.Version
}
if manifest.Image == "" {
return nil, fmt.Errorf("image is required")
}
Expand Down

0 comments on commit f78582a

Please sign in to comment.