diff --git a/integration_tests/dockerfiles/Dockerfile_onbuild_base b/integration_tests/dockerfiles/Dockerfile_onbuild_base new file mode 100644 index 000000000..85532c1a0 --- /dev/null +++ b/integration_tests/dockerfiles/Dockerfile_onbuild_base @@ -0,0 +1,6 @@ +FROM gcr.io/google-appengine/debian9:latest +ENV dir /tmp/dir/ +ONBUILD RUN echo "onbuild" > /tmp/onbuild +ONBUILD RUN mkdir $dir +ONBUILD RUN echo "onbuild 2" > ${dir}/onbuild2 +ONBUILD WORKDIR /new/workdir diff --git a/integration_tests/dockerfiles/Dockerfile_test_onbuild b/integration_tests/dockerfiles/Dockerfile_test_onbuild new file mode 100644 index 000000000..2968c0c62 --- /dev/null +++ b/integration_tests/dockerfiles/Dockerfile_test_onbuild @@ -0,0 +1,6 @@ +FROM gcr.io/kaniko-test/onbuild-base:latest +COPY context/foo foo +ENV dir /new/workdir/ +ONBUILD RUN echo "onbuild" > /tmp/onbuild +ONBUILD RUN echo "onbuild 2" > ${dir} +ONBUILD WORKDIR /new/workdir diff --git a/integration_tests/dockerfiles/config_test_onbuild.json b/integration_tests/dockerfiles/config_test_onbuild.json new file mode 100644 index 000000000..e7fa9a1e4 --- /dev/null +++ b/integration_tests/dockerfiles/config_test_onbuild.json @@ -0,0 +1,12 @@ +[ + { + "Image1": "gcr.io/kaniko-test/docker-test-onbuild:latest", + "Image2": "gcr.io/kaniko-test/kaniko-test-onbuild:latest", + "DiffType": "File", + "Diff": { + "Adds": null, + "Dels": null, + "Mods": null + } + } +] \ No newline at end of file diff --git a/integration_tests/integration_test_yaml.go b/integration_tests/integration_test_yaml.go index 3adb712d0..169594ffe 100644 --- a/integration_tests/integration_test_yaml.go +++ b/integration_tests/integration_test_yaml.go @@ -34,6 +34,7 @@ const ( kanikoTestBucket = "kaniko-test-bucket" buildcontextPath = "/workspace/integration_tests" dockerfilesPath = "/workspace/integration_tests/dockerfiles" + onbuildBaseImage = testRepo + "onbuild-base:latest" ) var fileTests = []struct { @@ -102,6 +103,14 @@ var fileTests = []struct { kanikoContext: buildcontextPath, repo: "test-add", }, + { + description: "test onbuild", + dockerfilePath: "/workspace/integration_tests/dockerfiles/Dockerfile_test_onbuild", + configPath: "/workspace/integration_tests/dockerfiles/config_test_onbuild.json", + dockerContext: buildcontextPath, + kanikoContext: buildcontextPath, + repo: "test-onbuild", + }, } var structureTests = []struct { @@ -182,8 +191,19 @@ func main() { Name: dockerImage, Args: []string{"build", "-t", executorImage, "-f", "deploy/Dockerfile", "."}, } + + // Build and push onbuild base images + buildOnbuildImage := step{ + Name: dockerImage, + Args: []string{"build", "-t", onbuildBaseImage, "-f", "/workspace/integration_tests/dockerfiles/Dockerfile_onbuild_base", "."}, + } + pushOnbuildBase := step{ + Name: dockerImage, + Args: []string{"push", onbuildBaseImage}, + } y := testyaml{ - Steps: []step{containerDiffStep, containerDiffPermissions, structureTestsStep, structureTestPermissions, GCSBucketTarBuildContext, uploadTarBuildContext, buildExecutorImage}, + Steps: []step{containerDiffStep, containerDiffPermissions, structureTestsStep, structureTestPermissions, GCSBucketTarBuildContext, uploadTarBuildContext, buildExecutorImage, + buildOnbuildImage, pushOnbuildBase}, } for _, test := range fileTests { // First, build the image with docker diff --git a/pkg/commands/onbuild.go b/pkg/commands/onbuild.go index 8823e5061..db4711604 100644 --- a/pkg/commands/onbuild.go +++ b/pkg/commands/onbuild.go @@ -27,8 +27,10 @@ type OnBuildCommand struct { cmd *instructions.OnbuildCommand } +//ExecuteCommand adds the specified expression in Onbuild to the config func (o *OnBuildCommand) ExecuteCommand(config *manifest.Schema2Config) error { logrus.Info("cmd: ONBUILD") + logrus.Infof("args: %s", o.cmd.Expression) resolvedExpression, err := util.ResolveEnvironmentReplacement(o.cmd.Expression, config.Env, false) if err != nil { return err @@ -41,7 +43,7 @@ func (o *OnBuildCommand) ExecuteCommand(config *manifest.Schema2Config) error { return nil } -// No files have changed, this command only touches metadata. +// FilesToSnapshot returns that no files have changed, this command only touches metadata. func (o *OnBuildCommand) FilesToSnapshot() []string { return []string{} }