Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run post build hook with /bin/sh -ic #7379

Merged
merged 1 commit into from
Feb 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/sample-app/application-template-dockerbuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
"name": "origin-ruby-sample:latest"
}
},
"postCommit": {
"script": "bundle exec rake test"
},
"resources": {}
},
"status": {
Expand Down
3 changes: 3 additions & 0 deletions examples/sample-app/application-template-pullspecbuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@
"name": "origin-ruby-sample:latest"
}
},
"postCommit": {
"script": "bundle exec rake test"
},
"resources": {}
},
"status": {
Expand Down
3 changes: 3 additions & 0 deletions examples/sample-app/application-template-stibuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@
"name": "origin-ruby-sample:latest"
}
},
"postCommit": {
"script": "bundle exec rake test"
},
"resources": {}
},
"status": {
Expand Down
15 changes: 10 additions & 5 deletions pkg/build/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ type SourceBuildStrategy struct {
// The above is a convenient form which is equivalent to:
//
// BuildPostCommitSpec{
// Command: []string{"/bin/sh", "-c"},
// Command: []string{"/bin/sh", "-ic"},
// Args: []string{"rake test --verbose"},
// }
//
Expand Down Expand Up @@ -486,19 +486,24 @@ type SourceBuildStrategy struct {
// the fields are specified, the hook is not executed.
type BuildPostCommitSpec struct {
// Command is the command to run. It may not be specified with Script.
// This might be needed if the image doesn't have "/bin/sh", or if you
// This might be needed if the image doesn't have `/bin/sh`, or if you
// do not want to use a shell. In all other cases, using Script might be
// more convenient.
Command []string
// Args is a list of arguments that are provided to either Command,
// Script or the Docker image's default entrypoint. The arguments are
// placed immediately after the command to be run.
Args []string
// Script is a shell script to be run with `/bin/sh -c`. It may not be
// Script is a shell script to be run with `/bin/sh -ic`. It may not be
// specified with Command. Use Script when a shell script is appropriate
// to execute the post build hook, for example for running unit tests
// with "rake test". If you need control over the image entrypoint, or
// if the image does not have "/bin/sh", use Command and/or Args.
// with `rake test`. If you need control over the image entrypoint, or
// if the image does not have `/bin/sh`, use Command and/or Args.
// The `-i` flag is needed to support CentOS and RHEL images that use
// Software Collections (SCL), in order to have the appropriate
// collections enabled in the shell. E.g., in the Ruby image, this is
// necessary to make `ruby`, `bundle` and other binaries available in
// the PATH.
Script string
}

Expand Down
15 changes: 10 additions & 5 deletions pkg/build/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ type SourceBuildStrategy struct {
// The above is a convenient form which is equivalent to:
//
// BuildPostCommitSpec{
// Command: []string{"/bin/sh", "-c"},
// Command: []string{"/bin/sh", "-ic"},
// Args: []string{"rake test --verbose"},
// }
//
Expand Down Expand Up @@ -469,19 +469,24 @@ type SourceBuildStrategy struct {
// the fields are specified, the hook is not executed.
type BuildPostCommitSpec struct {
// Command is the command to run. It may not be specified with Script.
// This might be needed if the image doesn't have "/bin/sh", or if you
// This might be needed if the image doesn't have `/bin/sh`, or if you
// do not want to use a shell. In all other cases, using Script might be
// more convenient.
Command []string `json:"command,omitempty" description:"command to be executed in a container running the build output image replacing the image's entrypoint"`
// Args is a list of arguments that are provided to either Command,
// Script or the Docker image's default entrypoint. The arguments are
// placed immediately after the command to be run.
Args []string `json:"args,omitempty" description:"arguments to command, script or the default image entrypoint"`
// Script is a shell script to be run with `/bin/sh -c`. It may not be
// Script is a shell script to be run with `/bin/sh -ic`. It may not be
// specified with Command. Use Script when a shell script is appropriate
// to execute the post build hook, for example for running unit tests
// with "rake test". If you need control over the image entrypoint, or
// if the image does not have "/bin/sh", use Command and/or Args.
// with `rake test`. If you need control over the image entrypoint, or
// if the image does not have `/bin/sh`, use Command and/or Args.
// The `-i` flag is needed to support CentOS and RHEL images that use
// Software Collections (SCL), in order to have the appropriate
// collections enabled in the shell. E.g., in the Ruby image, this is
// necessary to make `ruby`, `bundle` and other binaries available in
// the PATH.
Script string `json:"script,omitempty" description:"shell script to be executed in a container running the build output image"`
}

Expand Down
15 changes: 10 additions & 5 deletions pkg/build/api/v1beta3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ type SourceBuildStrategy struct {
// The above is a convenient form which is equivalent to:
//
// BuildPostCommitSpec{
// Command: []string{"/bin/sh", "-c"},
// Command: []string{"/bin/sh", "-ic"},
// Args: []string{"rake test --verbose"},
// }
//
Expand Down Expand Up @@ -456,19 +456,24 @@ type SourceBuildStrategy struct {
// the fields are specified, the hook is not executed.
type BuildPostCommitSpec struct {
// Command is the command to run. It may not be specified with Script.
// This might be needed if the image doesn't have "/bin/sh", or if you
// This might be needed if the image doesn't have `/bin/sh`, or if you
// do not want to use a shell. In all other cases, using Script might be
// more convenient.
Command []string `json:"command,omitempty" description:"command to be executed in a container running the build output image replacing the image's entrypoint"`
// Args is a list of arguments that are provided to either Command,
// Script or the Docker image's default entrypoint. The arguments are
// placed immediately after the command to be run.
Args []string `json:"args,omitempty" description:"arguments to command, script or the default image entrypoint"`
// Script is a shell script to be run with `/bin/sh -c`. It may not be
// Script is a shell script to be run with `/bin/sh -ic`. It may not be
// specified with Command. Use Script when a shell script is appropriate
// to execute the post build hook, for example for running unit tests
// with "rake test". If you need control over the image entrypoint, or
// if the image does not have "/bin/sh", use Command and/or Args.
// with `rake test`. If you need control over the image entrypoint, or
// if the image does not have `/bin/sh`, use Command and/or Args.
// The `-i` flag is needed to support CentOS and RHEL images that use
// Software Collections (SCL), in order to have the appropriate
// collections enabled in the shell. E.g., in the Ruby image, this is
// necessary to make `ruby`, `bundle` and other binaries available in
// the PATH.
Script string `json:"script,omitempty" description:"shell script to be executed in a container running the build output image"`
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/build/builder/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ func execPostCommitHook(client DockerClient, postCommitSpec api.BuildPostCommitS
glog.V(4).Infof("Post commit hook spec: %+v", postCommitSpec)

if script != "" {
command = []string{"/bin/sh", "-c"}
// The `-i` flag is needed to support CentOS and RHEL images
// that use Software Collections (SCL), in order to have the
// appropriate collections enabled in the shell. E.g., in the
// Ruby image, this is necessary to make `ruby`, `bundle` and
// other binaries available in the PATH.
command = []string{"/bin/sh", "-ic"}
args = append([]string{script, command[0]}, args...)
}

Expand Down