Skip to content

Commit

Permalink
feat: support push with SOCI
Browse files Browse the repository at this point in the history
Signed-off-by: Ziwen Ning <[email protected]>
  • Loading branch information
ningziwen committed Sep 25, 2023
1 parent f70314e commit 176909e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 28 deletions.
7 changes: 5 additions & 2 deletions docs/soci.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Lazy-pulling using SOCI Snapshotter

| :bird: Requirement | finch >= 0.8.0 |
|--------------------|----------------|
| :bird: Requirement for pull and run | finch >= 0.8.0 |
|-----------------------------------|----------------|

| :bird: Requirement for push with SOCI | finch >= 0.9.0 |
|---------------------------------------|----------------|

## Using SOCI

Expand Down
78 changes: 53 additions & 25 deletions e2e/vm/soci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package vm

import (
"fmt"
"os"
"os/exec"
"path/filepath"
Expand All @@ -12,11 +13,15 @@ import (
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/runfinch/common-tests/command"
"github.com/runfinch/common-tests/ffs"
"github.com/runfinch/common-tests/fnet"
"github.com/runfinch/common-tests/option"
)

const (
ffmpegSociImage = "public.ecr.aws/soci-workshop-examples/ffmpeg:latest"
registryImage = "public.ecr.aws/docker/library/registry:latest"
ubuntuImage = "public.ecr.aws/docker/library/ubuntu:23.10"
sociMountString = "fuse.rawBridge"
)

Expand All @@ -25,6 +30,7 @@ var testSoci = func(o *option.Option, installed bool) {
var limactlO *option.Option
var fpath, realFinchPath, limactlPath, limaHomePathEnv, wd string
var err error
var port int

ginkgo.BeforeEach(func() {
// Find lima paths. limactl is used to shell into the Finch VM and verify
Expand All @@ -48,36 +54,58 @@ var testSoci = func(o *option.Option, installed bool) {
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})

ginkgo.It("finch pull should have same mounts as nerdctl pull with 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\nsnapshotters:\n "+
// "- soci\nvmType: qemu\nrosetta: false"))
// command.New(o, virtualMachineRootCmd, "init").WithTimeoutInSeconds(600).Run()
// command.New(o, "pull", "--snapshotter=soci", ffmpegSociImage).WithTimeoutInSeconds(30).Run()
// finchPullMounts := countMounts(limactlO)
// command.Run(o, "rmi", "-f", ffmpegSociImage)
// command.New(limactlO, "shell", "finch",
// "sudo", "nerdctl", "--snapshotter=soci", "pull", ffmpegSociImage).WithTimeoutInSeconds(30).Run()
// nerdctlPullMounts := countMounts(limactlO)
// command.Run(o, "rmi", "-f", ffmpegSociImage)
// gomega.Expect(finchPullMounts).Should(gomega.Equal(nerdctlPullMounts))
//})
//
//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\nsnapshotters:\n "+
// "- soci\nvmType: qemu\nrosetta: false"))
// command.New(o, virtualMachineRootCmd, "init").WithTimeoutInSeconds(600).Run()
// command.New(o, "run", "--snapshotter=soci", ffmpegSociImage).WithTimeoutInSeconds(30).Run()
// finchPullMounts := countMounts(limactlO)
// command.Run(o, "rmi", "-f", ffmpegSociImage)
// command.New(limactlO, "shell", "finch",
// "sudo", "nerdctl", "--snapshotter=soci", "run", ffmpegSociImage).WithTimeoutInSeconds(30).Run()
// nerdctlPullMounts := countMounts(limactlO)
// command.Run(o, "rmi", "-f", ffmpegSociImage)
// gomega.Expect(finchPullMounts).Should(gomega.Equal(nerdctlPullMounts))
//})
ginkgo.It("finch push should work", func() {
resetVM(o, installed)
resetDisks(o, installed)
writeFile(finchConfigFilePath, []byte("cpus: 6\nmemory: 4GiB\nsnapshotters:\n "+
"- soci\nvmType: qemu\nrosetta: false"))
command.New(o, virtualMachineRootCmd, "init").WithTimeoutInSeconds(600).Run()
command.New(o, "pull", ffmpegSociImage).WithTimeoutInSeconds(30).Run()
finchPullMounts := countMounts(limactlO)
command.Run(o, "rmi", "-f", ffmpegSociImage)
command.New(limactlO, "shell", "finch",
"sudo", "nerdctl", "--snapshotter=soci", "pull", ffmpegSociImage).WithTimeoutInSeconds(30).Run()
nerdctlPullMounts := countMounts(limactlO)
command.Run(o, "rmi", "-f", ffmpegSociImage)
gomega.Expect(finchPullMounts).Should(gomega.Equal(nerdctlPullMounts))
})

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\nsnapshotters:\n "+
"- soci\nvmType: qemu\nrosetta: false"))
command.New(o, virtualMachineRootCmd, "init").WithTimeoutInSeconds(600).Run()
command.New(o, "run", ffmpegSociImage).WithTimeoutInSeconds(30).Run()
finchPullMounts := countMounts(limactlO)
command.Run(o, "rmi", "-f", ffmpegSociImage)
command.New(limactlO, "shell", "finch",
"sudo", "nerdctl", "--snapshotter=soci", "run", ffmpegSociImage).WithTimeoutInSeconds(30).Run()
nerdctlPullMounts := countMounts(limactlO)
command.Run(o, "rmi", "-f", ffmpegSociImage)
gomega.Expect(finchPullMounts).Should(gomega.Equal(nerdctlPullMounts))
port = fnet.GetFreePort()
command.New(o, "run", "-dp", fmt.Sprintf("%d:5000", port), "--name", "registry", registryImage).
WithTimeoutInSeconds(30).Run()
buildContext := ffs.CreateBuildContext(fmt.Sprintf(`FROM %s
CMD ["echo", "bar"]
`, ubuntuImage))
ginkgo.DeferCleanup(os.RemoveAll, buildContext)
targetTag := fmt.Sprintf(`localhost:%d/test-push-soci:tag`, port)
command.New(o, "build", "-t", targetTag, buildContext).WithTimeoutInSeconds(30).Run()
testSociSpanSize := 2097152 // 2MiB
testSociMinLayerSize := 20971520 // 20MiB
command.New(o, "push", "--insecure-registry", "--snapshotter=soci", fmt.Sprintf("--soci-span-size=%d", testSociSpanSize),
fmt.Sprintf("--soci-min-layer-size=%d", testSociMinLayerSize), targetTag).WithTimeoutInSeconds(30).Run()
mountOutput := command.StdoutStr(limactlO, "shell", "finch", "sudo", "soci", "index", "list")
gomega.Expect(mountOutput).Should(gomega.ContainSubstring(targetTag))
})
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/lima_config_applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

const (
sociVersion = "0.3.0"
sociVersion = "0.4.0"
sociInstallationProvisioningScriptHeader = "# soci installation and configuring"
sociFileNameFormat = "soci-snapshotter-%s-linux-%s.tar.gz"
sociDownloadURLFormat = "https://github.com/awslabs/soci-snapshotter/releases/download/v%s/%s"
Expand Down

0 comments on commit 176909e

Please sign in to comment.