mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-09-25 14:17:18 +00:00
Re-introduce local runner (#57)
* Re-introduce local runner Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Refactor code, remove LocalRunner and allow both "container:" and "run:" types to use local archives Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Treat "docker:" bundler prefix the same as "container:" as per the docs: https://kairos.io/docs/advanced/bundles/#bundle-types Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Add TODO tests Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Remove the not-needed LocalRunner Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Implement tests Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Remove TODO Won't do now to avoid introducing bugs Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> --------- Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> Co-authored-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package bundles_test
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
. "github.com/kairos-io/kairos-sdk/bundles"
|
||||
@@ -11,7 +13,7 @@ import (
|
||||
|
||||
var _ = Describe("Bundle", func() {
|
||||
Context("install", func() {
|
||||
PIt("installs packages from luet repos", func() {
|
||||
It("installs packages from luet repos", func() {
|
||||
dir, err := os.MkdirTemp("", "test")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
defer os.RemoveAll(dir)
|
||||
@@ -29,5 +31,177 @@ var _ = Describe("Bundle", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(filepath.Join(dir, "usr", "bin", "edgevpn")).To(BeARegularFile())
|
||||
})
|
||||
|
||||
When("local is true", func() {
|
||||
var installer BundleInstaller
|
||||
var config *BundleConfig
|
||||
var tmpDir, tmpFile string
|
||||
var err error
|
||||
|
||||
BeforeEach(func() {
|
||||
config = &BundleConfig{
|
||||
LocalFile: true,
|
||||
}
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
})
|
||||
|
||||
JustBeforeEach(func() {
|
||||
installer, err = NewBundleInstaller(*config)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
When("type is container", func() {
|
||||
BeforeEach(func() {
|
||||
tmpDir, err = os.MkdirTemp("", "test")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
tmpFile = path.Join(tmpDir, "grub-config.tar")
|
||||
copyFile("../assets/grub-config.tar", tmpFile)
|
||||
|
||||
config.Target = "container://" + tmpFile
|
||||
config.DBPath = "/usr/local/.kairos/db"
|
||||
config.RootPath = "/"
|
||||
})
|
||||
|
||||
It("installs", func() {
|
||||
expectInstalled(installer, config)
|
||||
})
|
||||
})
|
||||
|
||||
When("type is docker", func() {
|
||||
BeforeEach(func() {
|
||||
tmpDir, err = os.MkdirTemp("", "test")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
tmpFile = path.Join(tmpDir, "grub-config.tar")
|
||||
copyFile("../assets/grub-config.tar", tmpFile)
|
||||
|
||||
config.Target = "docker://" + tmpFile
|
||||
config.DBPath = "/usr/local/.kairos/db"
|
||||
config.RootPath = "/"
|
||||
})
|
||||
|
||||
It("installs", func() {
|
||||
expectInstalled(installer, config)
|
||||
})
|
||||
})
|
||||
|
||||
When("type is run", func() {
|
||||
BeforeEach(func() {
|
||||
// Ensure no leftovers from previous tests
|
||||
// These tests are meant to run in a container (Earthly), so it should
|
||||
// be ok to delete files like this.
|
||||
os.RemoveAll("/var/lib/rancher/k3s/server/manifests/longhorn.yaml")
|
||||
|
||||
tmpDir, err = os.MkdirTemp("", "test")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
tmpFile = path.Join(tmpDir, "longhorn-bundle.tar")
|
||||
copyFile("../assets/longhorn-bundle.tar", tmpFile)
|
||||
config.Target = "run://" + tmpFile
|
||||
})
|
||||
|
||||
It("installs", func() {
|
||||
_, err := os.Stat("/var/lib/rancher/k3s/server/manifests/longhorn.yaml")
|
||||
Expect(err).To(HaveOccurred())
|
||||
|
||||
err = installer.Install(config)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, err = os.Stat("/var/lib/rancher/k3s/server/manifests/longhorn.yaml")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
When("local is false", func() {
|
||||
var installer BundleInstaller
|
||||
var config *BundleConfig
|
||||
var err error
|
||||
|
||||
BeforeEach(func() {
|
||||
config = &BundleConfig{
|
||||
LocalFile: false,
|
||||
}
|
||||
})
|
||||
|
||||
JustBeforeEach(func() {
|
||||
installer, err = NewBundleInstaller(*config)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
When("type is container", func() {
|
||||
BeforeEach(func() {
|
||||
config.Target = "container://quay.io/kairos/packages:grub-config-static-0.9"
|
||||
config.DBPath = "/usr/local/.kairos/db"
|
||||
config.RootPath = "/"
|
||||
})
|
||||
|
||||
It("installs", func() {
|
||||
expectInstalled(installer, config)
|
||||
})
|
||||
})
|
||||
|
||||
When("type is docker", func() {
|
||||
BeforeEach(func() {
|
||||
config.Target = "docker://quay.io/kairos/packages:grub-config-static-0.9"
|
||||
config.DBPath = "/usr/local/.kairos/db"
|
||||
config.RootPath = "/"
|
||||
})
|
||||
|
||||
It("installs", func() {
|
||||
expectInstalled(installer, config)
|
||||
})
|
||||
})
|
||||
|
||||
When("type is run", func() {
|
||||
BeforeEach(func() {
|
||||
os.RemoveAll("/var/lib/rancher/k3s/server/manifests/longhorn.yaml")
|
||||
config.Target = "run://quay.io/kairos/community-bundles:longhorn_latest"
|
||||
})
|
||||
|
||||
It("installs", func() {
|
||||
_, err := os.Stat("/var/lib/rancher/k3s/server/manifests/longhorn.yaml")
|
||||
Expect(err).To(HaveOccurred())
|
||||
|
||||
err = installer.Install(config)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, err = os.Stat("/var/lib/rancher/k3s/server/manifests/longhorn.yaml")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
// Copied from: https://opensource.com/article/18/6/copying-files-go
|
||||
func copyFile(src, dst string) {
|
||||
sourceFileStat, err := os.Stat(src)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(sourceFileStat.Mode().IsRegular()).To(BeTrue())
|
||||
|
||||
source, err := os.Open(src)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
defer source.Close()
|
||||
|
||||
destination, err := os.Create(dst)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
defer destination.Close()
|
||||
|
||||
_, err = io.Copy(destination, source)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
func expectInstalled(installer BundleInstaller, config *BundleConfig) {
|
||||
// Ensure no leftovers from previous tests
|
||||
// These tests are meant to run in a container (Earthly), so it should
|
||||
// be ok to delete files like this.
|
||||
err := os.RemoveAll("/etc/cos/grub.cfg")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, err = os.Stat("/etc/cos/grub.cfg")
|
||||
Expect(err).To(HaveOccurred())
|
||||
|
||||
err = installer.Install(config)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, err = os.Stat("/etc/cos/grub.cfg")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
Reference in New Issue
Block a user