-
-
Notifications
You must be signed in to change notification settings - Fork 606
Expand file tree
/
Copy pathconfig.go
More file actions
168 lines (138 loc) · 4.92 KB
/
Copy pathconfig.go
File metadata and controls
168 lines (138 loc) · 4.92 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package config
import (
"fmt"
"net"
"github.com/abiosoft/colima/util"
"github.com/abiosoft/colima/util/osutil"
)
const (
AppName = "colima"
envProfile = "COLIMA_PROFILE" // environment variable for profile name
)
// VersionInfo is the application version info.
type VersionInfo struct {
Version string
Revision string
}
func AppVersion() VersionInfo { return VersionInfo{Version: appVersion, Revision: revision} }
func EnvProfile() string { return osutil.EnvVar(envProfile).Val() }
var (
appVersion = "development"
revision = "unknown"
)
// Config is the application config.
type Config struct {
CPU int `yaml:"cpu,omitempty"`
Disk int `yaml:"disk,omitempty"`
RootDisk int `yaml:"rootDisk,omitempty"`
Memory float32 `yaml:"memory,omitempty"`
Arch string `yaml:"arch,omitempty"`
CPUType string `yaml:"cpuType,omitempty"`
Network Network `yaml:"network,omitempty"`
Env map[string]string `yaml:"env,omitempty"` // environment variables
Hostname string `yaml:"hostname"`
// SSH
SSHPort int `yaml:"sshPort,omitempty"`
ForwardAgent bool `yaml:"forwardAgent,omitempty"`
SSHConfig bool `yaml:"sshConfig,omitempty"` // config generation
// VM
VMType string `yaml:"vmType,omitempty"`
VZRosetta bool `yaml:"rosetta,omitempty"`
Binfmt *bool `yaml:"binfmt,omitempty"`
NestedVirtualization bool `yaml:"nestedVirtualization,omitempty"`
DiskImage string `yaml:"diskImage,omitempty"`
PortForwarder string `yaml:"portForwarder,omitempty"` // "ssh", "grpc"
// volume mounts
Mounts []Mount `yaml:"mounts,omitempty"`
MountType string `yaml:"mountType,omitempty"`
MountINotify bool `yaml:"mountInotify,omitempty"`
// Runtime is one of docker, containerd.
Runtime string `yaml:"runtime,omitempty"`
ActivateRuntime *bool `yaml:"autoActivate,omitempty"`
// ModelRunner is the AI model runner (docker, ramalama).
ModelRunner string `yaml:"modelRunner,omitempty"`
// Kubernetes configuration
Kubernetes Kubernetes `yaml:"kubernetes,omitempty"`
// Docker configuration
Docker map[string]any `yaml:"docker,omitempty"`
// provision scripts
Provision []Provision `yaml:"provision,omitempty"`
}
// Kubernetes is kubernetes configuration
type Kubernetes struct {
Enabled bool `yaml:"enabled"`
Version string `yaml:"version"`
K3sArgs []string `yaml:"k3sArgs"`
Port int `yaml:"port,omitempty"`
}
// Network is VM network configuration
type Network struct {
Address bool `yaml:"address"`
DNSResolvers []net.IP `yaml:"dns"`
DNSHosts map[string]string `yaml:"dnsHosts"`
HostAddresses bool `yaml:"hostAddresses"`
Mode string `yaml:"mode"` // shared, bridged
BridgeInterface string `yaml:"interface"`
PreferredRoute bool `yaml:"preferredRoute"`
GatewayAddress net.IP `yaml:"gatewayAddress"`
}
// Mount is volume mount
type Mount struct {
Location string `yaml:"location"`
MountPoint string `yaml:"mountPoint,omitempty"`
Writable bool `yaml:"writable"`
}
// Provision modes managed by Colima (not passed to Lima).
const (
ProvisionModeAfterBoot = "after-boot"
ProvisionModeReady = "ready"
)
type Provision struct {
Mode string `yaml:"mode"`
Script string `yaml:"script"`
}
// IsColimaMode returns true if the provision script is managed by Colima
// rather than being passed to Lima.
func (p Provision) IsColimaMode() bool {
return p.Mode == ProvisionModeAfterBoot || p.Mode == ProvisionModeReady
}
func (c Config) MountsOrDefault() []Mount {
// explicit empty list means mount home directory (matches yaml.go)
if c.Mounts != nil && len(c.Mounts) == 0 {
return []Mount{
{Location: util.HomeDir(), Writable: true},
}
}
// nil means no mounts, non-empty means user-specified mounts
return c.Mounts
}
// AutoActivate returns if auto-activation of host client config is enabled.
func (c Config) AutoActivate() bool {
if c.ActivateRuntime == nil {
return true
}
return *c.ActivateRuntime
}
// Empty checks if the configuration is empty.
func (c Config) Empty() bool { return c.Runtime == "" } // this may be better but not really needed.
func (c Config) DriverLabel() string {
if c.VMType == "native" {
return "Native"
}
if util.MacOS13OrNewer() && c.VMType == "vz" {
return "macOS Virtualization.Framework"
} else if util.MacOS13OrNewerOnArm() && c.VMType == "krunkit" {
return "Krunkit"
}
return "QEMU"
}
// Disk is an instance disk size
type Disk int
// GiB returns the string represent of the disk in GiB.
func (d Disk) GiB() string { return fmt.Sprintf("%dGiB", d) }
// Int returns the disk size in bytes.
func (d Disk) Int() int64 { return 1024 * 1024 * 1024 * int64(d) }
// CtxKey returns the context key for config.
func CtxKey() any {
return struct{ name string }{name: "colima_config"}
}