Skip to content

Commit

Permalink
Add author and created_by data (ko-build#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjohnsonjr authored and mattmoor committed Jun 24, 2019
1 parent d32f069 commit f46a2b6
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions pkg/build/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ type GetBase func(string) (v1.Image, error)
type builder func(string, bool) (string, error)

type gobuild struct {
getBase GetBase
creationTime v1.Time
build builder
getBase GetBase
creationTime v1.Time
build builder
disableOptimizations bool
}

// Option is a functional option for NewGo.
type Option func(*gobuildOpener) error

type gobuildOpener struct {
getBase GetBase
creationTime v1.Time
build builder
getBase GetBase
creationTime v1.Time
build builder
disableOptimizations bool
}

Expand All @@ -62,9 +62,9 @@ func (gbo *gobuildOpener) Open() (Interface, error) {
return nil, errors.New("a way of providing base images must be specified, see build.WithBaseImages")
}
return &gobuild{
getBase: gbo.getBase,
creationTime: gbo.creationTime,
build: gbo.build,
getBase: gbo.getBase,
creationTime: gbo.creationTime,
build: gbo.build,
disableOptimizations: gbo.disableOptimizations,
}, nil
}
Expand Down Expand Up @@ -290,7 +290,7 @@ func (gb *gobuild) Build(s string) (v1.Image, error) {
}
defer os.RemoveAll(filepath.Dir(file))

var layers []v1.Layer
var layers []mutate.Addendum
// Create a layer from the kodata directory under this import path.
dataLayerBuf, err := tarKoData(s)
if err != nil {
Expand All @@ -303,7 +303,14 @@ func (gb *gobuild) Build(s string) (v1.Image, error) {
if err != nil {
return nil, err
}
layers = append(layers, dataLayer)
layers = append(layers, mutate.Addendum{
Layer: dataLayer,
History: v1.History{
Author: "ko",
CreatedBy: "ko publish " + s,
Comment: "kodata contents, at $KO_DATA_PATH",
},
})

appPath := filepath.Join(appDir, appFilename(s))

Expand All @@ -319,7 +326,14 @@ func (gb *gobuild) Build(s string) (v1.Image, error) {
if err != nil {
return nil, err
}
layers = append(layers, binaryLayer)
layers = append(layers, mutate.Addendum{
Layer: binaryLayer,
History: v1.History{
Author: "ko",
CreatedBy: "ko publish " + s,
Comment: "go build output, at " + appPath,
},
})

// Determine the appropriate base image for this import path.
base, err := gb.getBase(s)
Expand All @@ -328,7 +342,7 @@ func (gb *gobuild) Build(s string) (v1.Image, error) {
}

// Augment the base image with our application layer.
withApp, err := mutate.AppendLayers(base, layers...)
withApp, err := mutate.Append(base, layers...)
if err != nil {
return nil, err
}
Expand All @@ -343,8 +357,10 @@ func (gb *gobuild) Build(s string) (v1.Image, error) {
cfg = cfg.DeepCopy()
cfg.Config.Entrypoint = []string{appPath}
cfg.Config.Env = append(cfg.Config.Env, "KO_DATA_PATH="+kodataRoot)
cfg.ContainerConfig = cfg.Config
cfg.Author = "github.com/google/ko"

image, err := mutate.Config(withApp, cfg.Config)
image, err := mutate.ConfigFile(withApp, cfg)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit f46a2b6

Please sign in to comment.