mirror of
https://github.com/mudler/luet.git
synced 2025-09-05 01:00:44 +00:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
68a5604d8c | ||
|
fcec6c5699 | ||
|
d527eaed60 | ||
|
c7253ac8ad | ||
|
fffed79767 | ||
|
f329e1d5e0 | ||
|
20bc250470 |
18
cmd/build.go
18
cmd/build.go
@@ -46,6 +46,11 @@ var buildCmd = &cobra.Command{
|
|||||||
viper.BindPFlag("all", cmd.Flags().Lookup("all"))
|
viper.BindPFlag("all", cmd.Flags().Lookup("all"))
|
||||||
viper.BindPFlag("compression", cmd.Flags().Lookup("compression"))
|
viper.BindPFlag("compression", cmd.Flags().Lookup("compression"))
|
||||||
|
|
||||||
|
viper.BindPFlag("image-repository", cmd.Flags().Lookup("image-repository"))
|
||||||
|
viper.BindPFlag("push", cmd.Flags().Lookup("push"))
|
||||||
|
viper.BindPFlag("pull", cmd.Flags().Lookup("pull"))
|
||||||
|
viper.BindPFlag("keep-images", cmd.Flags().Lookup("keep-images"))
|
||||||
|
|
||||||
LuetCfg.Viper.BindPFlag("solver.type", cmd.Flags().Lookup("solver-type"))
|
LuetCfg.Viper.BindPFlag("solver.type", cmd.Flags().Lookup("solver-type"))
|
||||||
LuetCfg.Viper.BindPFlag("solver.discount", cmd.Flags().Lookup("solver-discount"))
|
LuetCfg.Viper.BindPFlag("solver.discount", cmd.Flags().Lookup("solver-discount"))
|
||||||
LuetCfg.Viper.BindPFlag("solver.rate", cmd.Flags().Lookup("solver-rate"))
|
LuetCfg.Viper.BindPFlag("solver.rate", cmd.Flags().Lookup("solver-rate"))
|
||||||
@@ -63,6 +68,10 @@ var buildCmd = &cobra.Command{
|
|||||||
all := viper.GetBool("all")
|
all := viper.GetBool("all")
|
||||||
databaseType := viper.GetString("database")
|
databaseType := viper.GetString("database")
|
||||||
compressionType := viper.GetString("compression")
|
compressionType := viper.GetString("compression")
|
||||||
|
imageRepository := viper.GetString("image-repository")
|
||||||
|
push := viper.GetBool("push")
|
||||||
|
pull := viper.GetBool("pull")
|
||||||
|
keepImages := viper.GetBool("keep-images")
|
||||||
|
|
||||||
compilerSpecs := compiler.NewLuetCompilationspecs()
|
compilerSpecs := compiler.NewLuetCompilationspecs()
|
||||||
var compilerBackend compiler.CompilerBackend
|
var compilerBackend compiler.CompilerBackend
|
||||||
@@ -112,8 +121,11 @@ var buildCmd = &cobra.Command{
|
|||||||
|
|
||||||
opts := compiler.NewDefaultCompilerOptions()
|
opts := compiler.NewDefaultCompilerOptions()
|
||||||
opts.SolverOptions = *LuetCfg.GetSolverOptions()
|
opts.SolverOptions = *LuetCfg.GetSolverOptions()
|
||||||
|
opts.ImageRepository = imageRepository
|
||||||
opts.Clean = clean
|
opts.Clean = clean
|
||||||
|
opts.PullFirst = pull
|
||||||
|
opts.KeepImg = keepImages
|
||||||
|
opts.Push = push
|
||||||
luetCompiler := compiler.NewLuetCompiler(compilerBackend, generalRecipe.GetDatabase(), opts)
|
luetCompiler := compiler.NewLuetCompiler(compilerBackend, generalRecipe.GetDatabase(), opts)
|
||||||
luetCompiler.SetConcurrency(concurrency)
|
luetCompiler.SetConcurrency(concurrency)
|
||||||
luetCompiler.SetCompressionType(compiler.CompressionImplementation(compressionType))
|
luetCompiler.SetCompressionType(compiler.CompressionImplementation(compressionType))
|
||||||
@@ -196,6 +208,10 @@ func init() {
|
|||||||
buildCmd.Flags().Bool("all", false, "Build all packages in the tree")
|
buildCmd.Flags().Bool("all", false, "Build all packages in the tree")
|
||||||
buildCmd.Flags().String("destination", path, "Destination folder")
|
buildCmd.Flags().String("destination", path, "Destination folder")
|
||||||
buildCmd.Flags().String("compression", "none", "Compression alg: none, gzip")
|
buildCmd.Flags().String("compression", "none", "Compression alg: none, gzip")
|
||||||
|
buildCmd.Flags().String("image-repository", "luet/cache", "Default base image string for generated image")
|
||||||
|
buildCmd.Flags().Bool("push", false, "Push images to a hub")
|
||||||
|
buildCmd.Flags().Bool("pull", false, "Pull images from a hub")
|
||||||
|
buildCmd.Flags().Bool("keep-images", true, "Keep built docker images in the host")
|
||||||
|
|
||||||
buildCmd.Flags().String("solver-type", "", "Solver strategy")
|
buildCmd.Flags().String("solver-type", "", "Solver strategy")
|
||||||
buildCmd.Flags().Float32("solver-rate", 0.7, "Solver learning rate")
|
buildCmd.Flags().Float32("solver-rate", 0.7, "Solver learning rate")
|
||||||
|
@@ -35,7 +35,7 @@ var cfgFile string
|
|||||||
var Verbose bool
|
var Verbose bool
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LuetCLIVersion = "0.5.1"
|
LuetCLIVersion = "0.6"
|
||||||
LuetEnvPrefix = "LUET"
|
LuetEnvPrefix = "LUET"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -101,6 +101,18 @@ func (*SimpleDocker) RemoveImage(opts compiler.CompilerBackendOptions) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*SimpleDocker) Push(opts compiler.CompilerBackendOptions) error {
|
||||||
|
name := opts.ImageName
|
||||||
|
pusharg := []string{"push", name}
|
||||||
|
out, err := exec.Command("docker", pusharg...).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "Failed pushing image: "+string(out))
|
||||||
|
}
|
||||||
|
Info(":whale: Pushed image:", name)
|
||||||
|
//Info(string(out))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SimpleDocker) ImageDefinitionToTar(opts compiler.CompilerBackendOptions) error {
|
func (s *SimpleDocker) ImageDefinitionToTar(opts compiler.CompilerBackendOptions) error {
|
||||||
if err := s.BuildImage(opts); err != nil {
|
if err := s.BuildImage(opts); err != nil {
|
||||||
return errors.Wrap(err, "Failed building image")
|
return errors.Wrap(err, "Failed building image")
|
||||||
|
@@ -145,3 +145,15 @@ func (*SimpleImg) ExtractRootfs(opts compiler.CompilerBackendOptions, keepPerms
|
|||||||
func (*SimpleImg) Changes(fromImage, toImage string) ([]compiler.ArtifactLayer, error) {
|
func (*SimpleImg) Changes(fromImage, toImage string) ([]compiler.ArtifactLayer, error) {
|
||||||
return NewSimpleDockerBackend().Changes(fromImage, toImage)
|
return NewSimpleDockerBackend().Changes(fromImage, toImage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*SimpleImg) Push(opts compiler.CompilerBackendOptions) error {
|
||||||
|
name := opts.ImageName
|
||||||
|
pusharg := []string{"push", name}
|
||||||
|
out, err := exec.Command("img", pusharg...).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "Failed pushing image: "+string(out))
|
||||||
|
}
|
||||||
|
Info(":tea: Pushed image:", name)
|
||||||
|
//Info(string(out))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@@ -256,6 +256,15 @@ func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage
|
|||||||
return nil, errors.Wrap(err, "Could not copy package sources")
|
return nil, errors.Wrap(err, "Could not copy package sources")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy file into the build context, the compilespec might have requested to do so.
|
||||||
|
if len(p.GetRetrieve()) > 0 {
|
||||||
|
err := p.CopyRetrieves(buildDir)
|
||||||
|
if err != nil {
|
||||||
|
Warning("Failed copying retrieves", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if buildertaggedImage == "" {
|
if buildertaggedImage == "" {
|
||||||
buildertaggedImage = cs.ImageRepository + "-" + p.GetPackage().GetFingerPrint() + "-builder"
|
buildertaggedImage = cs.ImageRepository + "-" + p.GetPackage().GetFingerPrint() + "-builder"
|
||||||
}
|
}
|
||||||
@@ -263,7 +272,7 @@ func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage
|
|||||||
packageImage = cs.ImageRepository + "-" + p.GetPackage().GetFingerPrint()
|
packageImage = cs.ImageRepository + "-" + p.GetPackage().GetFingerPrint()
|
||||||
}
|
}
|
||||||
|
|
||||||
if cs.PullFirst {
|
if cs.Options.PullFirst {
|
||||||
//Best effort pull
|
//Best effort pull
|
||||||
cs.Backend.DownloadImage(CompilerBackendOptions{ImageName: buildertaggedImage})
|
cs.Backend.DownloadImage(CompilerBackendOptions{ImageName: buildertaggedImage})
|
||||||
cs.Backend.DownloadImage(CompilerBackendOptions{ImageName: packageImage})
|
cs.Backend.DownloadImage(CompilerBackendOptions{ImageName: packageImage})
|
||||||
@@ -290,6 +299,12 @@ func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage
|
|||||||
return nil, errors.Wrap(err, "Could not export image")
|
return nil, errors.Wrap(err, "Could not export image")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cs.Options.Push {
|
||||||
|
err = cs.Backend.Push(builderOpts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "Could not push image: "+image+" "+builderOpts.DockerFileName)
|
||||||
|
}
|
||||||
|
}
|
||||||
// Then we write the step image, which uses the builder one
|
// Then we write the step image, which uses the builder one
|
||||||
p.WriteStepImageDefinition(buildertaggedImage, filepath.Join(buildDir, p.GetPackage().GetFingerPrint()+".dockerfile"))
|
p.WriteStepImageDefinition(buildertaggedImage, filepath.Join(buildDir, p.GetPackage().GetFingerPrint()+".dockerfile"))
|
||||||
runnerOpts := CompilerBackendOptions{
|
runnerOpts := CompilerBackendOptions{
|
||||||
@@ -311,6 +326,13 @@ func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage
|
|||||||
if err := cs.Backend.ExportImage(runnerOpts); err != nil {
|
if err := cs.Backend.ExportImage(runnerOpts); err != nil {
|
||||||
return nil, errors.Wrap(err, "Failed exporting image")
|
return nil, errors.Wrap(err, "Failed exporting image")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cs.Options.Push {
|
||||||
|
err = cs.Backend.Push(runnerOpts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "Could not push image: "+image+" "+builderOpts.DockerFileName)
|
||||||
|
}
|
||||||
|
}
|
||||||
// }
|
// }
|
||||||
|
|
||||||
var diffs []ArtifactLayer
|
var diffs []ArtifactLayer
|
||||||
|
@@ -44,11 +44,11 @@ type CompilerBackendOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CompilerOptions struct {
|
type CompilerOptions struct {
|
||||||
ImageRepository string
|
ImageRepository string
|
||||||
PullFirst, KeepImg bool
|
PullFirst, KeepImg, Push bool
|
||||||
Concurrency int
|
Concurrency int
|
||||||
CompressionType CompressionImplementation
|
CompressionType CompressionImplementation
|
||||||
Clean bool
|
Clean bool
|
||||||
|
|
||||||
SolverOptions config.LuetSolverOptions
|
SolverOptions config.LuetSolverOptions
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,8 @@ type CompilerOptions struct {
|
|||||||
func NewDefaultCompilerOptions() *CompilerOptions {
|
func NewDefaultCompilerOptions() *CompilerOptions {
|
||||||
return &CompilerOptions{
|
return &CompilerOptions{
|
||||||
ImageRepository: "luet/cache",
|
ImageRepository: "luet/cache",
|
||||||
PullFirst: true,
|
PullFirst: false,
|
||||||
|
Push: false,
|
||||||
CompressionType: None,
|
CompressionType: None,
|
||||||
KeepImg: true,
|
KeepImg: true,
|
||||||
Concurrency: runtime.NumCPU(),
|
Concurrency: runtime.NumCPU(),
|
||||||
@@ -74,6 +75,8 @@ type CompilerBackend interface {
|
|||||||
|
|
||||||
CopyImage(string, string) error
|
CopyImage(string, string) error
|
||||||
DownloadImage(opts CompilerBackendOptions) error
|
DownloadImage(opts CompilerBackendOptions) error
|
||||||
|
|
||||||
|
Push(opts CompilerBackendOptions) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Artifact interface {
|
type Artifact interface {
|
||||||
@@ -154,6 +157,9 @@ type CompilationSpec interface {
|
|||||||
|
|
||||||
GetSourceAssertion() solver.PackagesAssertions
|
GetSourceAssertion() solver.PackagesAssertions
|
||||||
SetSourceAssertion(as solver.PackagesAssertions)
|
SetSourceAssertion(as solver.PackagesAssertions)
|
||||||
|
|
||||||
|
GetRetrieve() []string
|
||||||
|
CopyRetrieves(dest string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type CompilationSpecs interface {
|
type CompilationSpecs interface {
|
||||||
|
@@ -21,6 +21,7 @@ import (
|
|||||||
|
|
||||||
pkg "github.com/mudler/luet/pkg/package"
|
pkg "github.com/mudler/luet/pkg/package"
|
||||||
"github.com/mudler/luet/pkg/solver"
|
"github.com/mudler/luet/pkg/solver"
|
||||||
|
"github.com/otiai10/copy"
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -95,6 +96,8 @@ type LuetCompilationSpec struct {
|
|||||||
Package *pkg.DefaultPackage `json:"package"`
|
Package *pkg.DefaultPackage `json:"package"`
|
||||||
SourceAssertion solver.PackagesAssertions `json:"-"`
|
SourceAssertion solver.PackagesAssertions `json:"-"`
|
||||||
|
|
||||||
|
Retrieve []string `json:"retrieve"`
|
||||||
|
|
||||||
OutputPath string `json:"-"` // Where the build processfiles go
|
OutputPath string `json:"-"` // Where the build processfiles go
|
||||||
Unpack bool `json:"unpack"`
|
Unpack bool `json:"unpack"`
|
||||||
Includes []string `json:"includes"`
|
Includes []string `json:"includes"`
|
||||||
@@ -136,6 +139,10 @@ func (cs *LuetCompilationSpec) GetIncludes() []string {
|
|||||||
return cs.Includes
|
return cs.Includes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cs *LuetCompilationSpec) GetRetrieve() []string {
|
||||||
|
return cs.Retrieve
|
||||||
|
}
|
||||||
|
|
||||||
func (cs *LuetCompilationSpec) GetSeedImage() string {
|
func (cs *LuetCompilationSpec) GetSeedImage() string {
|
||||||
return cs.Seed
|
return cs.Seed
|
||||||
}
|
}
|
||||||
@@ -164,6 +171,24 @@ func (cs *LuetCompilationSpec) SetSeedImage(s string) {
|
|||||||
cs.Seed = s
|
cs.Seed = s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cs *LuetCompilationSpec) CopyRetrieves(dest string) error {
|
||||||
|
var err error
|
||||||
|
if len(cs.Retrieve) > 0 {
|
||||||
|
for _, s := range cs.Retrieve {
|
||||||
|
matches, err := filepath.Glob(cs.Rel(s))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, m := range matches {
|
||||||
|
err = copy.Copy(m, filepath.Join(dest, filepath.Base(m)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: docker build image first. Then a backend can be used to actually spin up a container with it and run the steps within
|
// TODO: docker build image first. Then a backend can be used to actually spin up a container with it and run the steps within
|
||||||
func (cs *LuetCompilationSpec) RenderBuildImage() (string, error) {
|
func (cs *LuetCompilationSpec) RenderBuildImage() (string, error) {
|
||||||
spec := `
|
spec := `
|
||||||
@@ -174,6 +199,19 @@ ENV PACKAGE_NAME=` + cs.Package.GetName() + `
|
|||||||
ENV PACKAGE_VERSION=` + cs.Package.GetVersion() + `
|
ENV PACKAGE_VERSION=` + cs.Package.GetVersion() + `
|
||||||
ENV PACKAGE_CATEGORY=` + cs.Package.GetCategory()
|
ENV PACKAGE_CATEGORY=` + cs.Package.GetCategory()
|
||||||
|
|
||||||
|
if len(cs.Retrieve) > 0 {
|
||||||
|
for _, s := range cs.Retrieve {
|
||||||
|
//var file string
|
||||||
|
// if helpers.IsValidUrl(s) {
|
||||||
|
// file = s
|
||||||
|
// } else {
|
||||||
|
// file = cs.Rel(s)
|
||||||
|
// }
|
||||||
|
spec = spec + `
|
||||||
|
ADD ` + s + ` /luetbuild/`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, s := range cs.Env {
|
for _, s := range cs.Env {
|
||||||
spec = spec + `
|
spec = spec + `
|
||||||
ENV ` + s
|
ENV ` + s
|
||||||
|
@@ -105,4 +105,74 @@ RUN echo bar > /test2`))
|
|||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("Renders retrieve and env fields", func() {
|
||||||
|
generalRecipe := tree.NewGeneralRecipe(pkg.NewInMemoryDatabase(false))
|
||||||
|
|
||||||
|
err := generalRecipe.Load("../../tests/fixtures/retrieve")
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
Expect(len(generalRecipe.GetDatabase().GetPackages())).To(Equal(1))
|
||||||
|
|
||||||
|
compiler := NewLuetCompiler(nil, generalRecipe.GetDatabase(), NewDefaultCompilerOptions())
|
||||||
|
spec, err := compiler.FromPackage(&pkg.DefaultPackage{Name: "a", Category: "test", Version: "1.0"})
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
lspec, ok := spec.(*LuetCompilationSpec)
|
||||||
|
Expect(ok).To(BeTrue())
|
||||||
|
|
||||||
|
Expect(lspec.Steps).To(Equal([]string{"echo foo > /test", "echo bar > /test2"}))
|
||||||
|
Expect(lspec.Image).To(Equal("luet/base"))
|
||||||
|
Expect(lspec.Seed).To(Equal("alpine"))
|
||||||
|
tmpdir, err := ioutil.TempDir("", "tree")
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
defer os.RemoveAll(tmpdir) // clean up
|
||||||
|
|
||||||
|
err = lspec.WriteBuildImageDefinition(filepath.Join(tmpdir, "Dockerfile"))
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
dockerfile, err := helpers.Read(filepath.Join(tmpdir, "Dockerfile"))
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(dockerfile).To(Equal(`
|
||||||
|
FROM alpine
|
||||||
|
COPY . /luetbuild
|
||||||
|
WORKDIR /luetbuild
|
||||||
|
ENV PACKAGE_NAME=a
|
||||||
|
ENV PACKAGE_VERSION=1.0
|
||||||
|
ENV PACKAGE_CATEGORY=test
|
||||||
|
ADD test /luetbuild/
|
||||||
|
ADD http://www.google.com /luetbuild/
|
||||||
|
ENV test=1`))
|
||||||
|
|
||||||
|
lspec.SetOutputPath("/foo/bar")
|
||||||
|
|
||||||
|
err = lspec.WriteBuildImageDefinition(filepath.Join(tmpdir, "Dockerfile"))
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
dockerfile, err = helpers.Read(filepath.Join(tmpdir, "Dockerfile"))
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(dockerfile).To(Equal(`
|
||||||
|
FROM alpine
|
||||||
|
COPY . /luetbuild
|
||||||
|
WORKDIR /luetbuild
|
||||||
|
ENV PACKAGE_NAME=a
|
||||||
|
ENV PACKAGE_VERSION=1.0
|
||||||
|
ENV PACKAGE_CATEGORY=test
|
||||||
|
ADD test /luetbuild/
|
||||||
|
ADD http://www.google.com /luetbuild/
|
||||||
|
ENV test=1`))
|
||||||
|
|
||||||
|
err = lspec.WriteStepImageDefinition(lspec.Image, filepath.Join(tmpdir, "Dockerfile"))
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
dockerfile, err = helpers.Read(filepath.Join(tmpdir, "Dockerfile"))
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
Expect(dockerfile).To(Equal(`
|
||||||
|
FROM luet/base
|
||||||
|
ENV PACKAGE_NAME=a
|
||||||
|
ENV PACKAGE_VERSION=1.0
|
||||||
|
ENV PACKAGE_CATEGORY=test
|
||||||
|
ENV test=1
|
||||||
|
RUN echo foo > /test
|
||||||
|
RUN echo bar > /test2`))
|
||||||
|
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
3
tests/fixtures/retrieve-integration/a/build.yaml
vendored
Normal file
3
tests/fixtures/retrieve-integration/a/build.yaml
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
image: "alpine"
|
||||||
|
steps:
|
||||||
|
- echo a > /a
|
3
tests/fixtures/retrieve-integration/a/definition.yaml
vendored
Normal file
3
tests/fixtures/retrieve-integration/a/definition.yaml
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
name: "a"
|
||||||
|
version: "1.0"
|
||||||
|
category: "test"
|
10
tests/fixtures/retrieve-integration/b/build.yaml
vendored
Normal file
10
tests/fixtures/retrieve-integration/b/build.yaml
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
steps:
|
||||||
|
- tar xvf a-test-1.0.package.* -C ./
|
||||||
|
- mv a /b
|
||||||
|
requires:
|
||||||
|
- name: "a"
|
||||||
|
version: "1.0"
|
||||||
|
category: "test"
|
||||||
|
retrieve:
|
||||||
|
- a-test-1.0.package.*
|
7
tests/fixtures/retrieve-integration/b/definition.yaml
vendored
Normal file
7
tests/fixtures/retrieve-integration/b/definition.yaml
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
name: "b"
|
||||||
|
version: "1.0"
|
||||||
|
category: "test"
|
||||||
|
requires:
|
||||||
|
- name: "a"
|
||||||
|
version: "1.0"
|
||||||
|
category: "test"
|
10
tests/fixtures/retrieve/a/build.yaml
vendored
Normal file
10
tests/fixtures/retrieve/a/build.yaml
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
image: "luet/base"
|
||||||
|
seed: "alpine"
|
||||||
|
steps:
|
||||||
|
- echo foo > /test
|
||||||
|
- echo bar > /test2
|
||||||
|
retrieve:
|
||||||
|
- test
|
||||||
|
- http://www.google.com
|
||||||
|
env:
|
||||||
|
- test=1
|
3
tests/fixtures/retrieve/a/definition.yaml
vendored
Normal file
3
tests/fixtures/retrieve/a/definition.yaml
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
name: "a"
|
||||||
|
version: "1.0"
|
||||||
|
category: "test"
|
@@ -71,7 +71,7 @@ testReInstall() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testUnInstall() {
|
testUnInstall() {
|
||||||
luet uninstall --config $tmpdir/luet.yaml test/c-1.0
|
luet uninstall --config $tmpdir/luet.yaml test/c
|
||||||
installst=$?
|
installst=$?
|
||||||
assertEquals 'uninstall test successfully' "$installst" "0"
|
assertEquals 'uninstall test successfully' "$installst" "0"
|
||||||
assertTrue 'package uninstalled' "[ ! -e '$tmpdir/testrootfs/c' ]"
|
assertTrue 'package uninstalled' "[ ! -e '$tmpdir/testrootfs/c' ]"
|
||||||
|
90
tests/integration/04_retrieve.sh
Executable file
90
tests/integration/04_retrieve.sh
Executable file
@@ -0,0 +1,90 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export LUET_NOLOCK=true
|
||||||
|
|
||||||
|
oneTimeSetUp() {
|
||||||
|
export tmpdir="$(mktemp -d)"
|
||||||
|
}
|
||||||
|
|
||||||
|
oneTimeTearDown() {
|
||||||
|
rm -rf "$tmpdir"
|
||||||
|
}
|
||||||
|
|
||||||
|
testBuild() {
|
||||||
|
mkdir $tmpdir/testbuild
|
||||||
|
luet build --tree "$ROOT_DIR/tests/fixtures/retrieve-integration" --destination $tmpdir/testbuild --compression gzip test/b
|
||||||
|
buildst=$?
|
||||||
|
assertEquals 'builds successfully' "$buildst" "0"
|
||||||
|
assertTrue 'create package dep B' "[ -e '$tmpdir/testbuild/b-test-1.0.package.tar.gz' ]"
|
||||||
|
assertTrue 'create package' "[ -e '$tmpdir/testbuild/a-test-1.0.package.tar.gz' ]"
|
||||||
|
}
|
||||||
|
|
||||||
|
testRepo() {
|
||||||
|
assertTrue 'no repository' "[ ! -e '$tmpdir/testbuild/repository.yaml' ]"
|
||||||
|
luet create-repo --tree "$ROOT_DIR/tests/fixtures/retrieve-integration" \
|
||||||
|
--output $tmpdir/testbuild \
|
||||||
|
--packages $tmpdir/testbuild \
|
||||||
|
--name "test" \
|
||||||
|
--descr "Test Repo" \
|
||||||
|
--urls $tmpdir/testrootfs \
|
||||||
|
--type disk > /dev/null
|
||||||
|
|
||||||
|
createst=$?
|
||||||
|
assertEquals 'create repo successfully' "$createst" "0"
|
||||||
|
assertTrue 'create repository' "[ -e '$tmpdir/testbuild/repository.yaml' ]"
|
||||||
|
}
|
||||||
|
|
||||||
|
testConfig() {
|
||||||
|
mkdir $tmpdir/testrootfs
|
||||||
|
cat <<EOF > $tmpdir/luet.yaml
|
||||||
|
general:
|
||||||
|
debug: true
|
||||||
|
system:
|
||||||
|
rootfs: $tmpdir/testrootfs
|
||||||
|
database_path: "/"
|
||||||
|
database_engine: "boltdb"
|
||||||
|
repositories:
|
||||||
|
- name: "main"
|
||||||
|
type: "disk"
|
||||||
|
enable: true
|
||||||
|
urls:
|
||||||
|
- "$tmpdir/testbuild"
|
||||||
|
EOF
|
||||||
|
luet config --config $tmpdir/luet.yaml
|
||||||
|
res=$?
|
||||||
|
assertEquals 'config test successfully' "$res" "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
testInstall() {
|
||||||
|
luet install --config $tmpdir/luet.yaml test/b
|
||||||
|
#luet install --config $tmpdir/luet.yaml test/c-1.0 > /dev/null
|
||||||
|
installst=$?
|
||||||
|
assertEquals 'install test successfully' "$installst" "0"
|
||||||
|
assertTrue 'package B installed' "[ -e '$tmpdir/testrootfs/b' ]"
|
||||||
|
val=$(cat "$tmpdir/testrootfs/b")
|
||||||
|
assertEquals 'package B content comes from a' "$val" "a"
|
||||||
|
assertTrue 'package A installed' "[ -e '$tmpdir/testrootfs/a' ]"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
testUnInstall() {
|
||||||
|
luet uninstall --config $tmpdir/luet.yaml test/b
|
||||||
|
installst=$?
|
||||||
|
assertEquals 'uninstall test successfully' "$installst" "0"
|
||||||
|
assertTrue 'package uninstalled' "[ ! -e '$tmpdir/testrootfs/b' ]"
|
||||||
|
assertTrue 'package uninstalled' "[ ! -e '$tmpdir/testrootfs/a' ]"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
testCleanup() {
|
||||||
|
luet cleanup --config $tmpdir/luet.yaml
|
||||||
|
installst=$?
|
||||||
|
assertEquals 'install test successfully' "$installst" "0"
|
||||||
|
assertTrue 'package installed' "[ ! -e '$tmpdir/testrootfs/packages/b-test-1.0.package.tar.gz' ]"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Load shUnit2.
|
||||||
|
. "$ROOT_DIR/tests/integration/shunit2"/shunit2
|
||||||
|
|
Reference in New Issue
Block a user