Support for onbuild and unit test

This commit is contained in:
Priya Wadhwa
2018-04-04 17:06:01 -07:00
parent c63a03d123
commit 27f964957b
5 changed files with 162 additions and 0 deletions
+20
View File
@@ -23,6 +23,8 @@ import (
"github.com/GoogleCloudPlatform/k8s-container-builder/pkg/image"
"github.com/GoogleCloudPlatform/k8s-container-builder/pkg/snapshot"
"github.com/GoogleCloudPlatform/k8s-container-builder/pkg/util"
"github.com/containers/image/manifest"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@@ -141,6 +143,9 @@ func execute() error {
imageConfig := sourceImage.Config()
// Currently only supports single stage builds
for _, stage := range stages {
if err := resolveOnBuild(&stage, imageConfig); err != nil {
return err
}
for _, cmd := range stage.Commands {
dockerCommand, err := commands.GetCommand(cmd, srcContext)
if err != nil {
@@ -173,6 +178,21 @@ func execute() error {
return image.PushImage(sourceImage, destination)
}
func resolveOnBuild(stage *instructions.Stage, config *manifest.Schema2Config) error {
if config.OnBuild == nil {
return nil
}
// Otherwise, parse into commands
cmds, err := dockerfile.ParseCommands(config.OnBuild)
if err != nil {
return err
}
// Append to the beginning of the commands in the stage
stage.Commands = append(cmds, stage.Commands...)
logrus.Infof("Executing %v build triggers", len(cmds))
return nil
}
// setDefaultEnv sets default values for HOME and PATH so that
// config.json and docker-credential-gcr can be accessed
func setDefaultEnv() error {