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 (
|
|
|
|
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)
|
2019-12-30 11:53:32 +00:00
|
|
|
SetConcurrency(i int)
|
2019-11-04 16:16:13 +00:00
|
|
|
FromPackage(pkg.Package) (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
|
|
|
|
}
|
|
|
|
|
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
|
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
|
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"`
|
|
|
|
}
|
|
|
|
|
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
|
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)
|
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
|
|
|
|
}
|