Skip to content

Commit

Permalink
Updated stpsignal to use arg, and createdby field
Browse files Browse the repository at this point in the history
  • Loading branch information
Priya Wadhwa committed May 2, 2018
1 parent 829ce12 commit 805244b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
6 changes: 6 additions & 0 deletions pkg/commands/arg.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/google/go-containerregistry/v1"
"github.com/sirupsen/logrus"
"strings"
)

type ArgCommand struct {
Expand All @@ -38,3 +39,8 @@ func (r *ArgCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.Bui
func (r *ArgCommand) FilesToSnapshot() []string {
return []string{}
}

// CreatedBy returns some information about the command for the image config history
func (r *ArgCommand) CreatedBy() string {
return strings.Join([]string{r.cmd.Name(), r.cmd.Key}, " ")
}
2 changes: 2 additions & 0 deletions pkg/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type DockerCommand interface {
// 2. Updating metadata fields in the config
// It should not change the config history.
ExecuteCommand(*v1.Config, *dockerfile.BuildArgs) 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
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/commands/stopsignal.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,26 @@ limitations under the License.
package commands

import (
"strings"

"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/util"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/docker/docker/pkg/signal"
"github.com/google/go-containerregistry/v1"
"github.com/sirupsen/logrus"
"strings"
)

type StopSignalCommand struct {
cmd *instructions.StopSignalCommand
}

// ExecuteCommand handles command processing similar to CMD and RUN,
func (s *StopSignalCommand) ExecuteCommand(config *v1.Config) error {
func (s *StopSignalCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.BuildArgs) error {
logrus.Info("cmd: STOPSIGNAL")

// resolve possible environment variables
resolvedEnvs, err := util.ResolveEnvironmentReplacementList([]string{s.cmd.Signal}, config.Env, false)
b := buildArgs.FilterAllowed(config.Env)
resolvedEnvs, err := util.ResolveEnvironmentReplacementList([]string{s.cmd.Signal}, append(config.Env, b...), false)
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/commands/stopsignal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ limitations under the License.
package commands

import (
"testing"

"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"github.com/GoogleContainerTools/kaniko/testutil"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/google/go-containerregistry/v1"
"testing"
)

var stopsignalTests = []struct {
Expand Down Expand Up @@ -54,7 +54,8 @@ func TestStopsignalExecuteCmd(t *testing.T) {
Signal: test.signal,
},
}
err := cmd.ExecuteCommand(cfg)
b := dockerfile.NewBuildArgs([]string{})
err := cmd.ExecuteCommand(cfg, b)
testutil.CheckErrorAndDeepEqual(t, false, err, test.expectedSignal, cfg.StopSignal)
}
}

0 comments on commit 805244b

Please sign in to comment.