Files
podman/pkg/machine/os/machine_os.go
Ashley Cui 9abe8c7853 Introduce podman machine os apply
Podman machine os apply takes a takes a OCI image with container native ostree functionality and rebases the machine os on that image.
Currently, this requires the guest os inside the vm to use rpm-ostree.

When specifying an image, any container transport may be specified. If a
container transport is not specified, OS apply will attempt to search
the local containers-storage for the image, and if it is not found, it
will then attempt to use the Docker transport to pull from a remote
registry.

The architecture of OS apply is as follows:
podman machine os apply ssh's into the machine and calls podman machine os
apply. on the secondary call to podman machine os apply, apply
recognizes that it is inside the machine and does image operations, and
finally calls rpm-ostree rebase.

Tests are written but commented out, due to the chicken-and-egg problem.

Signed-off-by: Ashley Cui <acui@redhat.com>
2023-02-15 14:48:12 -05:00

41 lines
892 B
Go

//go:build amd64 || arm64
// +build amd64 arm64
package os
import (
"fmt"
"github.com/containers/podman/v4/pkg/machine"
)
// MachineOS manages machine OS's from outside the machine.
type MachineOS struct {
Args []string
VM machine.VM
VMName string
Restart bool
}
// Apply applies the image by sshing into the machine and running apply from inside the VM.
func (m *MachineOS) Apply(image string, opts ApplyOptions) error {
sshOpts := machine.SSHOptions{
Args: []string{"podman", "machine", "os", "apply", image},
}
if err := m.VM.SSH(m.VMName, sshOpts); err != nil {
return err
}
if m.Restart {
if err := m.VM.Stop(m.VMName, machine.StopOptions{}); err != nil {
return err
}
if err := m.VM.Start(m.VMName, machine.StartOptions{NoInfo: true}); err != nil {
return err
}
fmt.Printf("Machine %q restarted successfully\n", m.VMName)
}
return nil
}