Skip to content

Commit

Permalink
Merge pull request GoogleContainerTools#159 from chrisz100/feature/cm…
Browse files Browse the repository at this point in the history
…d_stopsignal

Feature/cmd stopsignal
  • Loading branch information
priyawadhwa authored May 2, 2018
2 parents 1fca51e + e23003a commit 60cbc54
Show file tree
Hide file tree
Showing 13 changed files with 509 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ After each command, we append a layer of changed files to the base image (if the
The majority of Dockerfile commands can be executed with kaniko, but we're still working on supporting the following commands:

* HEALTHCHECK
* STOPSIGNAL
* ARG

Multi-Stage Dockerfiles are also unsupported currently, but will be ready soon.
Expand Down
2 changes: 2 additions & 0 deletions pkg/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func GetCommand(cmd instructions.Command, buildcontext string) (DockerCommand, e
return &OnBuildCommand{cmd: c}, nil
case *instructions.VolumeCommand:
return &VolumeCommand{cmd: c}, nil
case *instructions.StopSignalCommand:
return &StopSignalCommand{cmd: c}, nil
case *instructions.MaintainerCommand:
logrus.Warnf("%s is deprecated, skipping", cmd.Name())
return nil, nil
Expand Down
65 changes: 65 additions & 0 deletions pkg/commands/stopsignal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package commands

import (
"strings"

"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"
)

type StopSignalCommand struct {
cmd *instructions.StopSignalCommand
}

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

// resolve possible environment variables
resolvedEnvs, err := util.ResolveEnvironmentReplacementList([]string{s.cmd.Signal}, config.Env, false)
if err != nil {
return err
}
stopsignal := resolvedEnvs[0]

// validate stopsignal
_, err = signal.ParseSignal(stopsignal)
if err != nil {
return err
}

logrus.Infof("Replacing StopSignal in config with %v", stopsignal)
config.StopSignal = stopsignal
return nil
}

// FilesToSnapshot returns an empty array since this is a metadata command
func (s *StopSignalCommand) FilesToSnapshot() []string {
return []string{}
}

// CreatedBy returns some information about the command for the image config history
func (s *StopSignalCommand) CreatedBy() string {
entrypoint := []string{"STOPSIGNAL"}

return strings.Join(append(entrypoint, s.cmd.Signal), " ")
}
60 changes: 60 additions & 0 deletions pkg/commands/stopsignal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package commands

import (
"testing"

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

var stopsignalTests = []struct {
signal string
expectedSignal string
}{
{
signal: "SIGKILL",
expectedSignal: "SIGKILL",
},
{
signal: "${STOPSIG}",
expectedSignal: "SIGKILL",
},
{
signal: "1",
expectedSignal: "1",
},
}

func TestStopsignalExecuteCmd(t *testing.T) {

cfg := &v1.Config{
StopSignal: "",
Env: []string{"STOPSIG=SIGKILL"},
}

for _, test := range stopsignalTests {
cmd := StopSignalCommand{
&instructions.StopSignalCommand{
Signal: test.signal,
},
}
err := cmd.ExecuteCommand(cfg)
testutil.CheckErrorAndDeepEqual(t, false, err, test.expectedSignal, cfg.StopSignal)
}
}
54 changes: 54 additions & 0 deletions vendor/github.com/docker/docker/pkg/signal/signal.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions vendor/github.com/docker/docker/pkg/signal/signal_darwin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions vendor/github.com/docker/docker/pkg/signal/signal_freebsd.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions vendor/github.com/docker/docker/pkg/signal/signal_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 60cbc54

Please sign in to comment.