Skip to content

Commit eb4eb0f

Browse files
committed
add "extraArchive" config option
1 parent 1a56960 commit eb4eb0f

File tree

6 files changed

+62
-2
lines changed

6 files changed

+62
-2
lines changed

cmd/limactl/hostagent.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func newHostagentCommand() *cobra.Command {
2828
hostagentCommand.Flags().StringP("pidfile", "p", "", "write pid to file")
2929
hostagentCommand.Flags().String("socket", "", "hostagent socket")
3030
hostagentCommand.Flags().String("nerdctl-archive", "", "local file path (not URL) of nerdctl-full-VERSION-linux-GOARCH.tar.gz")
31+
hostagentCommand.Flags().String("extra-archive", "", "local file path (not URL) of an arbitrary archive")
3132
return hostagentCommand
3233
}
3334

@@ -70,6 +71,13 @@ func hostagentAction(cmd *cobra.Command, args []string) error {
7071
if nerdctlArchive != "" {
7172
opts = append(opts, hostagent.WithNerdctlArchive(nerdctlArchive))
7273
}
74+
extraArchive, err := cmd.Flags().GetString("extra-archive")
75+
if err != nil {
76+
return err
77+
}
78+
if extraArchive != "" {
79+
opts = append(opts, hostagent.WithExtraArchive(extraArchive))
80+
}
7381
ha, err := hostagent.New(instName, stdout, sigintCh, opts...)
7482
if err != nil {
7583
return err

examples/default.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ containerd:
196196
# vim was not installed in the guest. Make sure the package system is working correctly.
197197
# Also see "/var/log/cloud-init-output.log" in the guest.
198198

199+
# Adds an additional archive to the CIDATA image which is mounted on boot
200+
# Useful for provisioning scripts that run before mounts
201+
# extraArchive:
202+
# location: "~/extra.tar.gz"
203+
# arch: "x86_64"
204+
# digest: "sha256:..."
205+
199206
# ===================================================================== #
200207
# FURTHER ADVANCED CONFIGURATION
201208
# ===================================================================== #

pkg/cidata/cidata.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func setupEnv(y *limayaml.LimaYAML) (map[string]string, error) {
104104
return env, nil
105105
}
106106

107-
func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort int, nerdctlArchive string) error {
107+
func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort int, nerdctlArchive, extraArchive string) error {
108108
if err := limayaml.Validate(*y, false); err != nil {
109109
return err
110110
}
@@ -287,6 +287,19 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
287287
})
288288
}
289289

290+
if extraArchive != "" {
291+
extratgzR, err := os.Open(extraArchive)
292+
if err != nil {
293+
return err
294+
}
295+
defer extratgzR.Close()
296+
layout = append(layout, iso9660util.Entry{
297+
// ISO9660 requires len(Path) <= 30
298+
Path: "extra.tgz",
299+
Reader: extratgzR,
300+
})
301+
}
302+
290303
return iso9660util.Write(filepath.Join(instDir, filenames.CIDataISO), "cidata", layout)
291304
}
292305

pkg/hostagent/hostagent.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type HostAgent struct {
5858

5959
type options struct {
6060
nerdctlArchive string // local path, not URL
61+
extraArchive string // local path, not URL
6162
}
6263

6364
type Opt func(*options) error
@@ -69,6 +70,13 @@ func WithNerdctlArchive(s string) Opt {
6970
}
7071
}
7172

73+
func WithExtraArchive(s string) Opt {
74+
return func(o *options) error {
75+
o.extraArchive = s
76+
return nil
77+
}
78+
}
79+
7280
// New creates the HostAgent.
7381
//
7482
// stdout is for emitting JSON lines of Events.
@@ -107,7 +115,7 @@ func New(instName string, stdout io.Writer, sigintCh chan os.Signal, opts ...Opt
107115
}
108116
}
109117

110-
if err := cidata.GenerateISO9660(inst.Dir, instName, y, udpDNSLocalPort, tcpDNSLocalPort, o.nerdctlArchive); err != nil {
118+
if err := cidata.GenerateISO9660(inst.Dir, instName, y, udpDNSLocalPort, tcpDNSLocalPort, o.nerdctlArchive, o.extraArchive); err != nil {
111119
return nil, err
112120
}
113121

pkg/limayaml/limayaml.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type LimaYAML struct {
3131
UseHostResolver *bool `yaml:"useHostResolver,omitempty" json:"useHostResolver,omitempty"` // DEPRECATED, use `HostResolver.Enabled` instead
3232
PropagateProxyEnv *bool `yaml:"propagateProxyEnv,omitempty" json:"propagateProxyEnv,omitempty"`
3333
CACertificates CACertificates `yaml:"caCerts,omitempty" json:"caCerts,omitempty"`
34+
ExtraArchive *File `yaml:"extraArchive,omitempty" json:"extraArchive,omitempty"`
3435
}
3536

3637
type Arch = string

pkg/start/start.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,29 @@ func Start(ctx context.Context, inst *store.Instance) error {
132132
if nerdctlArchiveCache != "" {
133133
args = append(args, "--nerdctl-archive", nerdctlArchiveCache)
134134
}
135+
if y.ExtraArchive != nil {
136+
if y.ExtraArchive.Digest.String() != "" {
137+
if !y.ExtraArchive.Digest.Algorithm().Available() {
138+
return fmt.Errorf("expected digest algorithm %q is not available", y.ExtraArchive.Digest.Algorithm())
139+
}
140+
if err := y.ExtraArchive.Digest.Validate(); err != nil {
141+
return err
142+
}
143+
eaBuf, err := os.ReadFile(y.ExtraArchive.Location)
144+
if err != nil {
145+
return err
146+
}
147+
verifier := y.ExtraArchive.Digest.Verifier()
148+
if _, err := verifier.Write(eaBuf); err != nil {
149+
return err
150+
}
151+
if !verifier.Verified() {
152+
return errors.New("digest mismatch between supplied digest and calculated digest for extra archive")
153+
}
154+
}
155+
156+
args = append(args, "--extra-archive", y.ExtraArchive.Location)
157+
}
135158
args = append(args, inst.Name)
136159
haCmd := exec.CommandContext(ctx, self, args...)
137160

0 commit comments

Comments
 (0)