diff --git a/e2e/e2e.go b/e2e/e2e.go index 1b373d863..9fa225d91 100644 --- a/e2e/e2e.go +++ b/e2e/e2e.go @@ -63,20 +63,3 @@ func CreateOption() (*option.Option, error) { } return o, nil } - -// CreateLimaOption creates an option for shelling into VM in e2e tests. -func CreateLimaOption() (*option.Option, string, error) { - wd, err := os.Getwd() - if err != nil { - return nil, "", fmt.Errorf("failed to get the current working directory: %w", err) - } - - subject := "LIMA_HOME=" + filepath.Join(wd, "../../_output/lima/data") - subject2 := filepath.Join(wd, "../../_output/lima/bin/limactl") - - o, err := option.New([]string{subject2}, option.Env([]string{subject})) - if err != nil { - return nil, "", fmt.Errorf("failed to initialize a testing option: %w", err) - } - return o, subject, nil -} diff --git a/e2e/vm/soci_test.go b/e2e/vm/soci_test.go index 4293f0ce3..16b6163cc 100644 --- a/e2e/vm/soci_test.go +++ b/e2e/vm/soci_test.go @@ -4,6 +4,8 @@ package vm import ( + "os" + "path/filepath" "strings" "github.com/onsi/ginkgo/v2" @@ -13,38 +15,52 @@ import ( "github.com/runfinch/common-tests/option" ) -var testSoci = func(o *option.Option, limactlO *option.Option, limaHomePath string, installed bool) { +const ( + FfmpegSociImage = "public.ecr.aws/soci-workshop-examples/ffmpeg:latest" + sociMountString = "fuse.rawBridge" +) + +var testSoci = func(o *option.Option, installed bool) { + + ginkgo.Describe("SOCI", func() { + var limactlO *option.Option + var limaHomePathEnv string + var wd string + + ginkgo.BeforeEach(func() { + wd, _ = os.Getwd() + limaHomePathEnv = "LIMA_HOME=" + filepath.Join(wd, "../../_output/lima/data") + limactlO, _ = option.New([]string{filepath.Join(wd, "../../_output/lima/bin/limactl")}, + option.Env([]string{limaHomePathEnv})) + }) - ginkgo.Describe("Soci", func() { ginkgo.It("finch pull should have same mounts as nerdctl pull with SOCI", func() { resetVM(o, installed) resetDisks(o, installed) - writeFile(finchConfigFilePath, []byte("cpus: 6\nmemory: 4GiB\nsoci_snapshotter: true\n"+ + writeFile(finchConfigFilePath, []byte("cpus: 6\nmemory: 4GiB\nsnapshotter: soci\n"+ "vmType: qemu\nrosetta: false")) initCmdSession := command.New(o, virtualMachineRootCmd, "init").WithTimeoutInSeconds(600).Run() gomega.Expect(initCmdSession).Should(gexec.Exit(0)) command.New(o, "pull", FfmpegSociImage).WithTimeoutInSeconds(30).Run() finchPullMounts := countMounts(limactlO) command.New(o, "rmi", "-f", FfmpegSociImage).WithTimeoutInSeconds(30).Run() - command.New(limactlO, "shell", "finch", "sudo", "nerdctl", "pull", FfmpegSociImage).WithTimeoutInSeconds(30).Run().Out.Contents() + command.New(limactlO, "shell", "finch", "sudo", "nerdctl", "--snapshotter=soci", "pull", FfmpegSociImage).WithTimeoutInSeconds(30).Run().Out.Contents() nerdctlPullMounts := countMounts(limactlO) command.New(o, "rmi", "-f", FfmpegSociImage).WithTimeoutInSeconds(30).Run() gomega.Expect(finchPullMounts).Should(gomega.Equal(nerdctlPullMounts)) }) - }) - ginkgo.Describe("Soci", func() { ginkgo.It("finch run should have same mounts as nerdctl run with SOCI", func() { resetVM(o, installed) resetDisks(o, installed) - writeFile(finchConfigFilePath, []byte("cpus: 6\nmemory: 4GiB\nsoci_snapshotter: true\n"+ + writeFile(finchConfigFilePath, []byte("cpus: 6\nmemory: 4GiB\nsnapshotter: soci\n"+ "vmType: qemu\nrosetta: false")) initCmdSession := command.New(o, virtualMachineRootCmd, "init").WithTimeoutInSeconds(600).Run() gomega.Expect(initCmdSession).Should(gexec.Exit(0)) command.New(o, "run", FfmpegSociImage).WithTimeoutInSeconds(30).Run() finchPullMounts := countMounts(limactlO) command.New(o, "rmi", "-f", FfmpegSociImage).WithTimeoutInSeconds(30).Run() - command.New(limactlO, "shell", "finch", "sudo", "nerdctl", "run", FfmpegSociImage).WithTimeoutInSeconds(30).Run().Out.Contents() + command.New(limactlO, "shell", "finch", "sudo", "nerdctl", "--snapshotter=soci", "run", FfmpegSociImage).WithTimeoutInSeconds(30).Run().Out.Contents() nerdctlPullMounts := countMounts(limactlO) command.New(o, "rmi", "-f", FfmpegSociImage).WithTimeoutInSeconds(30).Run() gomega.Expect(finchPullMounts).Should(gomega.Equal(nerdctlPullMounts)) diff --git a/e2e/vm/vm_test.go b/e2e/vm/vm_test.go index bac5e19ae..02245e356 100644 --- a/e2e/vm/vm_test.go +++ b/e2e/vm/vm_test.go @@ -23,8 +23,6 @@ import ( const ( virtualMachineRootCmd = "vm" - FfmpegSociImage = "public.ecr.aws/soci-workshop-examples/ffmpeg:latest" - sociMountString = "fuse.rawBridge" ) //nolint:paralleltest // TestVM is like TestMain for the VM-related tests. @@ -36,11 +34,6 @@ func TestVM(t *testing.T) { t.Fatal(err) } - limactlO, limaHomePath, err := e2e.CreateLimaOption() - if err != nil { - t.Fatal(err) - } - ginkgo.SynchronizedBeforeSuite(func() []byte { command.New(o, "vm", "init").WithTimeoutInSeconds(600).Run() return nil @@ -60,7 +53,7 @@ func TestVM(t *testing.T) { testVirtualizationFrameworkAndRosetta(o, *e2e.Installed) testSupportBundle(o) testCredHelper(o, *e2e.Installed, *e2e.Registry) - testSoci(o, limactlO, limaHomePath, *e2e.Installed) + testSoci(o, *e2e.Installed) }) gomega.RegisterFailHandler(ginkgo.Fail) diff --git a/pkg/config/config.go b/pkg/config/config.go index cba1538e6..e83b3692a 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -35,8 +35,8 @@ type AdditionalDirectory struct { type Finch struct { CPUs *int `yaml:"cpus"` Memory *string `yaml:"memory"` - //Soci: boolean value of whether user wants SOCI installed - Soci *bool `yaml:"soci_snapshotter,omitempty"` + // Soci: the snapshotter that will be installed and configured automatically on vm init or on vm start + Snapshotter *string `yaml:"snapshotter,omitempty"` // CredsHelper: the list of credential helpers that will be installed and configured automatically on vm init or on vm start CredsHelpers []string `yaml:"creds_helpers,omitempty"` // AdditionalDirectories are the work directories that are not supported by default. In macOS, only home directory is supported by default. diff --git a/pkg/config/lima_config_applier.go b/pkg/config/lima_config_applier.go index 0a7629932..f8adcd03f 100644 --- a/pkg/config/lima_config_applier.go +++ b/pkg/config/lima_config_applier.go @@ -19,7 +19,7 @@ import ( const ( sociVersion = "0.3.0" sociInstallationProvisioningScriptHeader = "# soci installation and configuring" - fnameFormat = "soci-snapshotter-%s-linux-%s.tar.gz" + sociFileNameFormat = "soci-snapshotter-%s-linux-%s.tar.gz" sociDownloadUrlFormat = "https://github.com/awslabs/soci-snapshotter/releases/download/v%s/%s" sociInstallationScriptFormat = `%s if [ ! -f /usr/local/bin/soci ]; then @@ -32,8 +32,8 @@ fi #changing containerd config export config=etc/containerd/config.toml echo " [proxy_plugins.soci] -type = \"snapshot\" -address = \"/run/soci-snapshotter-grpc/soci-snapshotter-grpc.sock\" " >> $config + type = \"snapshot\" + address = \"/run/soci-snapshotter-grpc/soci-snapshotter-grpc.sock\" " >> $config sudo systemctl restart containerd.service sudo soci-snapshotter-grpc &> ~/soci-snapshotter-logs & @@ -113,13 +113,6 @@ func (lca *limaConfigApplier) Apply(isInit bool) error { limaCfg.Rosetta.BinFmt = pointer.Bool(false) } - var sociEnabled bool - if lca.cfg.Soci == nil { - sociEnabled = false - } else { - sociEnabled = *lca.cfg.Soci - } - if isInit { cfgAfterInit, err := lca.applyInit(&limaCfg) if err != nil { @@ -128,7 +121,7 @@ func (lca *limaConfigApplier) Apply(isInit bool) error { limaCfg = *cfgAfterInit } - toggleSoci(&limaCfg, sociEnabled, sociVersion, system.NewStdLib().Arch()) + toggleSoci(&limaCfg, *lca.cfg.Snapshotter == "soci", sociVersion, system.NewStdLib().Arch()) limaCfgBytes, err := yaml.Marshal(limaCfg) if err != nil { @@ -225,9 +218,9 @@ func hasUserModeEmulationInstallationScript(limaCfg *limayaml.LimaYAML) (int, bo func toggleSoci(limaCfg *limayaml.LimaYAML, enabled bool, sociVersion string, arch string) { idx, hasScript := hasSociInstallationScript(limaCfg) - fname := fmt.Sprintf(fnameFormat, sociVersion, system.NewStdLib().Arch()) - sociDownloadUrl := fmt.Sprintf(sociDownloadUrlFormat, sociVersion, fname) - sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat, sociInstallationProvisioningScriptHeader, sociDownloadUrl, fname) + sociFileName := fmt.Sprintf(sociFileNameFormat, sociVersion, system.NewStdLib().Arch()) + sociDownloadUrl := fmt.Sprintf(sociDownloadUrlFormat, sociVersion, sociFileNameFormat) + sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat, sociInstallationProvisioningScriptHeader, sociDownloadUrl, sociFileName) if !hasScript && enabled { limaCfg.Env = map[string]string{"CONTAINERD_SNAPSHOTTER": "soci"} limaCfg.Provision = append(limaCfg.Provision, limayaml.Provision{