~james/core

core/spindle/engines/microvm/models.go -rw-r--r-- 1.7 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//go:build linux

package microvm

import (
	"fmt"
	"slices"

	"tangled.org/core/spindle/models"
)

type manifestWorkflow struct {
	Image          string              `yaml:"image"`
	Services       map[string]any      `yaml:"services"`
	Virtualisation map[string]any      `yaml:"virtualisation"`
	Dependencies   []string            `yaml:"dependencies"`
	Registry       map[string]any      `yaml:"registry"`
	Environment    map[string]string   `yaml:"environment"`
	Substituters   map[string]string   `yaml:"substituters"`
	Cache          []models.CacheEntry `yaml:"cache"`
	Steps          []struct {
		Name        string            `yaml:"name"`
		Command     string            `yaml:"command"`
		Environment map[string]string `yaml:"environment"`
	} `yaml:"steps"`
}

// sorted so the guest env is deterministic
func workflowSubstituters(substituters map[string]string) (urls []string, keys []string, err error) {
	for cacheURL, key := range substituters {
		urls = append(urls, cacheURL)
		if key != "" {
			keys = append(keys, key)
		}
	}
	if _, err := parseSubstituterUpstreams(urls); err != nil {
		return nil, nil, fmt.Errorf("substituters: %w", err)
	}
	slices.Sort(urls)
	slices.Sort(keys)
	return urls, keys, nil
}

type manifestConfig struct {
	Services       map[string]any `yaml:"services"     json:"services,omitempty"`
	Virtualisation map[string]any `yaml:"virtualisation" json:"virtualisation,omitempty"`
	Dependencies   []string       `yaml:"dependencies" json:"dependencies,omitempty"`
	Registry       map[string]any `yaml:"registry"     json:"registry,omitempty"`
}

func (c manifestConfig) Enabled() bool {
	return len(c.Services) > 0 || len(c.Virtualisation) > 0 || len(c.Dependencies) > 0 || len(c.Registry) > 0
}