Skip to content

Commit

Permalink
Merge pull request #1 from GoogleContainerTools/master
Browse files Browse the repository at this point in the history
pull master
  • Loading branch information
chrisz100 authored May 2, 2018
2 parents 6ff3c58 + 60cbc54 commit c75ebba
Show file tree
Hide file tree
Showing 15 changed files with 519 additions and 24 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
29 changes: 8 additions & 21 deletions integration_tests/integration_test_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
executorImage = "executor-image"
dockerImage = "gcr.io/cloud-builders/docker"
ubuntuImage = "ubuntu"
structureTestImage = "gcr.io/gcp-runtimes/container-structure-test"
testRepo = "gcr.io/kaniko-test/"
dockerPrefix = "docker-"
kanikoPrefix = "kaniko-"
Expand Down Expand Up @@ -205,15 +206,6 @@ func main() {
Name: ubuntuImage,
Args: []string{"chmod", "+x", "container-diff-linux-amd64"},
}
structureTestsStep := step{
Name: "gcr.io/cloud-builders/gsutil",
Args: []string{"cp", "gs://container-structure-test/latest/container-structure-test", "."},
}
structureTestPermissions := step{
Name: ubuntuImage,
Args: []string{"chmod", "+x", "container-structure-test"},
}

GCSBucketTarBuildContext := step{
Name: ubuntuImage,
Args: []string{"tar", "-C", "/workspace/integration_tests/", "-zcvf", "/workspace/context.tar.gz", "."},
Expand All @@ -239,7 +231,7 @@ func main() {
Args: []string{"push", onbuildBaseImage},
}
y := testyaml{
Steps: []step{containerDiffStep, containerDiffPermissions, structureTestsStep, structureTestPermissions, GCSBucketTarBuildContext, uploadTarBuildContext, buildExecutorImage,
Steps: []step{containerDiffStep, containerDiffPermissions, GCSBucketTarBuildContext, uploadTarBuildContext, buildExecutorImage,
buildOnbuildImage, pushOnbuildBase},
Timeout: "1200s",
}
Expand Down Expand Up @@ -315,20 +307,15 @@ func main() {
Args: []string{"pull", kanikoImage},
}
// Run structure tests on the kaniko and docker image
args := "container-structure-test -image " + kanikoImage + " " + test.structureTestYamlPath
structureTest := step{
Name: ubuntuImage,
Args: []string{"sh", "-c", args},
Env: []string{"PATH=/workspace:/bin"},
kanikoStructureTest := step{
Name: structureTestImage,
Args: []string{"test", "--image", kanikoImage, "--config", test.structureTestYamlPath},
}
args = "container-structure-test -image " + dockerImageTag + " " + test.structureTestYamlPath
dockerStructureTest := step{
Name: ubuntuImage,
Args: []string{"sh", "-c", args},
Env: []string{"PATH=/workspace:/bin"},
Name: structureTestImage,
Args: []string{"test", "--image", dockerImageTag, "--config", test.structureTestYamlPath},
}

y.Steps = append(y.Steps, dockerBuild, kaniko, pullKanikoImage, structureTest, dockerStructureTest)
y.Steps = append(y.Steps, dockerBuild, kaniko, pullKanikoImage, kanikoStructureTest, dockerStructureTest)
}

d, _ := yaml.Marshal(&y)
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)
}
}
3 changes: 2 additions & 1 deletion pkg/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ func DoBuild(dockerfilePath, srcContext, destination, snapshotMode string, docke
mutate.Addendum{
Layer: layer,
History: v1.History{
Author: constants.Author,
Author: constants.Author,
CreatedBy: dockerCommand.CreatedBy(),
},
},
)
Expand Down
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.

Loading

0 comments on commit c75ebba

Please sign in to comment.