mirror of
https://github.com/mudler/luet.git
synced 2025-09-03 00:06:36 +00:00
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:
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user