Add Separate tree for build dependency

Reuse the Recipe and extend it to read a separate tree for build
dependencies.

Also add accessors to compilespec to produce dockerfile image format.
This commit is contained in:
Ettore Di Giacinto
2019-11-05 17:36:22 +01:00
parent f570f74a9e
commit ff88ff67c2
7 changed files with 254 additions and 12 deletions

View File

@@ -16,23 +16,86 @@
package compiler
import (
pkg "github.com/mudler/luet/pkg/package"
yaml "gopkg.in/yaml.v2"
"io/ioutil"
)
type LuetCompilationSpec struct {
Steps []string `json:"steps"`
Image string `json:"image"`
Steps []string `json:"steps"` // Are run inside a container and the result layer diff is saved
Image string `json:"image"`
Seed string `json:"seed"`
Package pkg.Package `json:"-"`
}
func NewLuetCompilationSpec(b []byte) (CompilationSpec, error) {
func NewLuetCompilationSpec(b []byte, p pkg.Package) (CompilationSpec, error) {
var spec LuetCompilationSpec
err := yaml.Unmarshal(b, &spec)
if err != nil {
return &spec, err
}
spec.Package = p
return &spec, nil
}
func (cs *LuetCompilationSpec) ToDocker() (string, error) {
return "", nil
func (cs *LuetCompilationSpec) GetPackage() pkg.Package {
return cs.Package
}
func (cs *LuetCompilationSpec) BuildSteps() []string {
return cs.Steps
}
func (cs *LuetCompilationSpec) GetSeedImage() string {
return cs.Seed
}
func (cs *LuetCompilationSpec) GetImage() string {
return cs.Image
}
func (cs *LuetCompilationSpec) SetImage(s string) {
cs.Image = s
}
func (cs *LuetCompilationSpec) SetSeedImage(s string) {
cs.Seed = s
}
// 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) {
spec := `
FROM ` + cs.GetSeedImage() + `
COPY . /luetbuild
WORKDIR /luetbuild
`
return spec, nil
}
// 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) RenderStepImage(image string) (string, error) {
spec := `
FROM ` + image
for _, s := range cs.BuildSteps() {
spec = spec + `
RUN ` + s
}
return spec, nil
}
func (cs *LuetCompilationSpec) WriteBuildImageDefinition(path string) error {
data, err := cs.RenderBuildImage()
if err != nil {
return err
}
return ioutil.WriteFile(path, []byte(data), 0644)
}
func (cs *LuetCompilationSpec) WriteStepImageDefinition(fromimage, path string) error {
data, err := cs.RenderStepImage(fromimage)
if err != nil {
return err
}
return ioutil.WriteFile(path, []byte(data), 0644)
}