forked from GoogleContainerTools/kaniko
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request GoogleContainerTools#159 from chrisz100/feature/cm…
…d_stopsignal Feature/cmd stopsignal
- Loading branch information
Showing
13 changed files
with
509 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), " ") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
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.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
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.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
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.
Oops, something went wrong.
Oops, something went wrong.