Add config as point to ExecuteCommand, fix snapshots

This commit is contained in:
Priya Wadhwa
2018-03-09 11:30:35 -08:00
parent 55314cef9c
commit 27b09f28be
6 changed files with 61 additions and 57 deletions
+12 -8
View File
@@ -17,23 +17,27 @@ limitations under the License.
package commands
import (
"github.com/containers/image/manifest"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/sirupsen/logrus"
"github.com/pkg/errors"
)
type DockerCommand interface {
ExecuteCommand() error
// The config file has an "author" field, should return information about the command
Author() string
// ExecuteCommand is responsible for:
// 1. Making required changes to the filesystem (ex. copying files for ADD/COPY or setting ENV variables)
// 2. Updating metadata fields in the config
// It should not change the config history.
ExecuteCommand(*manifest.Schema2Config) error
// The config history has a "created by" field, should return information about the command
CreatedBy() string
// A list of files to snapshot, empty for metadata commands or nil if we don't know
FilesToSnapshot() []string
}
func GetCommand(cmd instructions.Command) DockerCommand {
func GetCommand(cmd instructions.Command) (DockerCommand, error) {
switch c := cmd.(type) {
case *instructions.RunCommand:
return &RunCommand{cmd: c}
return &RunCommand{cmd: c}, nil
}
logrus.Errorf("%s is not a supported command.", cmd.Name())
return nil
return nil, errors.Errorf("%s is not a supported command", cmd.Name())
}
+7 -8
View File
@@ -17,7 +17,7 @@ limitations under the License.
package commands
import (
"github.com/GoogleCloudPlatform/k8s-container-builder/pkg/constants"
"github.com/containers/image/manifest"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/sirupsen/logrus"
"os"
@@ -29,10 +29,11 @@ type RunCommand struct {
cmd *instructions.RunCommand
}
func (r *RunCommand) ExecuteCommand() error {
func (r *RunCommand) ExecuteCommand(config *manifest.Schema2Config) error {
var newCommand []string
if r.cmd.PrependShell {
// This is the default shell on Linux
// TODO: Support shell command here
shell := []string{"/bin/sh", "-c"}
newCommand = append(shell, strings.Join(r.cmd.CmdLine, " "))
} else {
@@ -54,14 +55,12 @@ func (r *RunCommand) FilesToSnapshot() []string {
}
// Author returns some information about the command for the image config
func (r *RunCommand) Author() string {
author := []string{constants.Author}
func (r *RunCommand) CreatedBy() string {
cmdLine := strings.Join(r.cmd.CmdLine, " ")
if r.cmd.PrependShell {
// TODO: Support shell command here
shell := []string{"/bin/sh", "-c"}
author = append(author, shell...)
return strings.Join(author, " ") + " " + cmdLine
return strings.Join(append(shell, cmdLine), " ")
}
author = append(author, cmdLine)
return strings.Join(author, " ")
return cmdLine
}