2019-11-04 16:16:13 +00:00
|
|
|
// Copyright © 2019 Ettore Di Giacinto <mudler@gentoo.org>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package compiler
|
|
|
|
|
2019-11-09 12:58:15 +00:00
|
|
|
import (
|
2020-01-05 13:32:26 +00:00
|
|
|
"runtime"
|
|
|
|
|
2020-02-12 10:21:55 +00:00
|
|
|
"github.com/mudler/luet/pkg/config"
|
2019-11-09 12:58:15 +00:00
|
|
|
pkg "github.com/mudler/luet/pkg/package"
|
2019-11-15 17:11:26 +00:00
|
|
|
"github.com/mudler/luet/pkg/solver"
|
2019-11-09 12:58:15 +00:00
|
|
|
)
|
2019-11-04 16:16:13 +00:00
|
|
|
|
|
|
|
type Compiler interface {
|
2019-12-30 13:46:45 +00:00
|
|
|
Compile(bool, CompilationSpec) (Artifact, error)
|
|
|
|
CompileParallel(keepPermissions bool, ps CompilationSpecs) ([]Artifact, []error)
|
|
|
|
CompileWithReverseDeps(keepPermissions bool, ps CompilationSpecs) ([]Artifact, []error)
|
2019-11-15 23:38:07 +00:00
|
|
|
ComputeDepTree(p CompilationSpec) (solver.PackagesAssertions, error)
|
2020-06-06 06:58:18 +00:00
|
|
|
ComputeMinimumCompilableSet(p ...CompilationSpec) ([]CompilationSpec, error)
|
2019-12-30 11:53:32 +00:00
|
|
|
SetConcurrency(i int)
|
2019-11-04 16:16:13 +00:00
|
|
|
FromPackage(pkg.Package) (CompilationSpec, error)
|
2020-06-06 06:58:18 +00:00
|
|
|
FromDatabase(db pkg.PackageDatabase, minimum bool, dst string) ([]CompilationSpec, error)
|
2019-11-04 16:20:00 +00:00
|
|
|
SetBackend(CompilerBackend)
|
|
|
|
GetBackend() CompilerBackend
|
2019-12-30 13:52:34 +00:00
|
|
|
SetCompressionType(t CompressionImplementation)
|
2019-11-04 16:16:13 +00:00
|
|
|
}
|
|
|
|
|
2019-11-08 17:29:51 +00:00
|
|
|
type CompilerBackendOptions struct {
|
|
|
|
ImageName string
|
|
|
|
SourcePath string
|
|
|
|
DockerFileName string
|
|
|
|
Destination string
|
|
|
|
}
|
|
|
|
|
2020-01-05 13:32:26 +00:00
|
|
|
type CompilerOptions struct {
|
2020-02-15 13:45:05 +00:00
|
|
|
ImageRepository string
|
|
|
|
PullFirst, KeepImg, Push bool
|
|
|
|
Concurrency int
|
|
|
|
CompressionType CompressionImplementation
|
|
|
|
Clean bool
|
2020-02-21 21:00:35 +00:00
|
|
|
KeepImageExport bool
|
2020-02-12 10:21:55 +00:00
|
|
|
|
2020-07-17 20:42:03 +00:00
|
|
|
OnlyDeps bool
|
|
|
|
NoDeps bool
|
|
|
|
SolverOptions config.LuetSolverOptions
|
|
|
|
SkipIfMetadataExists bool
|
2020-11-27 21:22:20 +00:00
|
|
|
BuildValuesFile string
|
2020-10-06 15:57:57 +00:00
|
|
|
|
|
|
|
PackageTargetOnly bool
|
2020-01-05 13:32:26 +00:00
|
|
|
}
|
|
|
|
|
2020-01-05 15:26:42 +00:00
|
|
|
func NewDefaultCompilerOptions() *CompilerOptions {
|
|
|
|
return &CompilerOptions{
|
2020-01-05 13:32:26 +00:00
|
|
|
ImageRepository: "luet/cache",
|
2020-02-15 13:45:05 +00:00
|
|
|
PullFirst: false,
|
|
|
|
Push: false,
|
2020-01-05 13:32:26 +00:00
|
|
|
CompressionType: None,
|
|
|
|
KeepImg: true,
|
|
|
|
Concurrency: runtime.NumCPU(),
|
2020-01-05 14:52:05 +00:00
|
|
|
Clean: true,
|
2020-02-18 17:22:18 +00:00
|
|
|
OnlyDeps: false,
|
|
|
|
NoDeps: false,
|
2020-01-05 13:32:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-04 16:16:13 +00:00
|
|
|
type CompilerBackend interface {
|
2019-11-08 17:29:51 +00:00
|
|
|
BuildImage(CompilerBackendOptions) error
|
|
|
|
ExportImage(CompilerBackendOptions) error
|
|
|
|
RemoveImage(CompilerBackendOptions) error
|
2019-11-09 12:58:15 +00:00
|
|
|
Changes(fromImage, toImage string) ([]ArtifactLayer, error)
|
2019-11-08 17:29:51 +00:00
|
|
|
ImageDefinitionToTar(CompilerBackendOptions) error
|
2019-11-10 09:47:28 +00:00
|
|
|
ExtractRootfs(opts CompilerBackendOptions, keepPerms bool) error
|
2019-11-13 08:42:52 +00:00
|
|
|
|
|
|
|
CopyImage(string, string) error
|
|
|
|
DownloadImage(opts CompilerBackendOptions) error
|
2020-02-15 13:45:05 +00:00
|
|
|
|
|
|
|
Push(opts CompilerBackendOptions) error
|
2020-06-03 19:00:30 +00:00
|
|
|
|
|
|
|
ImageExists(string) bool
|
2019-11-04 16:16:13 +00:00
|
|
|
}
|
|
|
|
|
2019-11-09 12:58:15 +00:00
|
|
|
type Artifact interface {
|
|
|
|
GetPath() string
|
|
|
|
SetPath(string)
|
2019-11-15 17:11:26 +00:00
|
|
|
GetDependencies() []Artifact
|
|
|
|
SetDependencies(d []Artifact)
|
|
|
|
GetSourceAssertion() solver.PackagesAssertions
|
|
|
|
SetSourceAssertion(as solver.PackagesAssertions)
|
|
|
|
|
|
|
|
SetCompileSpec(as CompilationSpec)
|
|
|
|
GetCompileSpec() CompilationSpec
|
2019-11-22 20:01:29 +00:00
|
|
|
WriteYaml(dst string) error
|
2019-12-28 15:32:32 +00:00
|
|
|
Unpack(dst string, keepPerms bool) error
|
2019-12-30 11:53:32 +00:00
|
|
|
Compress(src string, concurrency int) error
|
|
|
|
SetCompressionType(t CompressionImplementation)
|
2019-12-28 15:32:32 +00:00
|
|
|
FileList() ([]string, error)
|
2019-12-29 12:56:52 +00:00
|
|
|
Hash() error
|
|
|
|
Verify() error
|
2020-01-28 16:46:32 +00:00
|
|
|
|
2020-04-13 08:52:41 +00:00
|
|
|
SetFiles(f []string)
|
|
|
|
GetFiles() []string
|
|
|
|
|
2020-01-28 16:46:32 +00:00
|
|
|
GetChecksums() Checksums
|
|
|
|
SetChecksums(c Checksums)
|
2019-11-09 12:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ArtifactNode struct {
|
|
|
|
Name string `json:"Name"`
|
|
|
|
Size int `json:"Size"`
|
|
|
|
}
|
|
|
|
type ArtifactDiffs struct {
|
|
|
|
Additions []ArtifactNode `json:"Adds"`
|
|
|
|
Deletions []ArtifactNode `json:"Dels"`
|
|
|
|
Changes []ArtifactNode `json:"Mods"`
|
|
|
|
}
|
|
|
|
type ArtifactLayer struct {
|
|
|
|
FromImage string `json:"Image1"`
|
|
|
|
ToImage string `json:"Image2"`
|
|
|
|
Diffs ArtifactDiffs `json:"Diff"`
|
|
|
|
}
|
2020-01-05 17:05:48 +00:00
|
|
|
type ArtifactLayerSummary struct {
|
|
|
|
FromImage string `json:"image1"`
|
|
|
|
ToImage string `json:"image2"`
|
|
|
|
AddFiles int `json:"add_files"`
|
|
|
|
AddSizes int64 `json:"add_sizes"`
|
|
|
|
DelFiles int `json:"del_files"`
|
|
|
|
DelSizes int64 `json:"del_sizes"`
|
|
|
|
ChangeFiles int `json:"change_files"`
|
|
|
|
ChangeSizes int64 `json:"change_sizes"`
|
|
|
|
}
|
|
|
|
type ArtifactLayersSummary struct {
|
|
|
|
Layers []ArtifactLayerSummary `json:"summary"`
|
|
|
|
}
|
2019-11-09 12:58:15 +00:00
|
|
|
|
2019-11-04 16:16:13 +00:00
|
|
|
// CompilationSpec represent a compilation specification derived from a package
|
|
|
|
type CompilationSpec interface {
|
2019-11-13 08:42:52 +00:00
|
|
|
ImageUnpack() bool // tells if the definition is just an image
|
2019-11-14 16:43:47 +00:00
|
|
|
GetIncludes() []string
|
2020-11-08 14:35:24 +00:00
|
|
|
GetExcludes() []string
|
2019-11-13 08:42:52 +00:00
|
|
|
|
2019-11-05 16:36:22 +00:00
|
|
|
RenderBuildImage() (string, error)
|
|
|
|
WriteBuildImageDefinition(string) error
|
|
|
|
|
|
|
|
RenderStepImage(image string) (string, error)
|
|
|
|
WriteStepImageDefinition(fromimage, path string) error
|
|
|
|
|
|
|
|
GetPackage() pkg.Package
|
|
|
|
BuildSteps() []string
|
|
|
|
|
|
|
|
GetSeedImage() string
|
|
|
|
SetSeedImage(string)
|
|
|
|
|
|
|
|
GetImage() string
|
|
|
|
SetImage(string)
|
2019-11-08 17:28:01 +00:00
|
|
|
|
|
|
|
SetOutputPath(string)
|
|
|
|
GetOutputPath() string
|
|
|
|
Rel(string) string
|
|
|
|
|
|
|
|
GetPreBuildSteps() []string
|
2019-11-15 23:38:07 +00:00
|
|
|
|
|
|
|
GetSourceAssertion() solver.PackagesAssertions
|
|
|
|
SetSourceAssertion(as solver.PackagesAssertions)
|
2020-02-13 13:15:43 +00:00
|
|
|
|
|
|
|
GetRetrieve() []string
|
|
|
|
CopyRetrieves(dest string) error
|
2020-05-16 19:34:27 +00:00
|
|
|
|
|
|
|
SetPackageDir(string)
|
|
|
|
GetPackageDir() string
|
2019-11-04 16:16:13 +00:00
|
|
|
}
|
2019-11-15 17:11:26 +00:00
|
|
|
|
|
|
|
type CompilationSpecs interface {
|
|
|
|
Unique() CompilationSpecs
|
|
|
|
Len() int
|
|
|
|
All() []CompilationSpec
|
|
|
|
Add(CompilationSpec)
|
|
|
|
Remove(s CompilationSpecs) CompilationSpecs
|
|
|
|
}
|