Skip to content

Commit 78a0c5b

Browse files
committed
Run post build hook with /bin/bash
We need either `/bin/bash -c` or `/bin/sh -ic` to make our supported images to work properly. That's due to a hack to auto-enable SCLs. https://github.com/openshift/sti-base/blob/8d95148/Dockerfile#L23-L29 When `/bin/sh` is a symlink to `/bin/bash`, the ENV environment variable is only evaluated when the shell is started in interactive mode. Making the shell interactive with `-i` seems to make less sense than requiring Bash. For images that do not include Bash, the full Command+Args syntax is the way to go.
1 parent cf9e5e9 commit 78a0c5b

8 files changed

+47
-36
lines changed

examples/sample-app/application-template-dockerbuild.json

+3
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@
144144
"name": "origin-ruby-sample:latest"
145145
}
146146
},
147+
"postCommit": {
148+
"script": "bundle exec rake test"
149+
},
147150
"resources": {}
148151
},
149152
"status": {

examples/sample-app/application-template-pullspecbuild.json

+3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@
136136
"name": "origin-ruby-sample:latest"
137137
}
138138
},
139+
"postCommit": {
140+
"script": "bundle exec rake test"
141+
},
139142
"resources": {}
140143
},
141144
"status": {

examples/sample-app/application-template-stibuild.json

+3
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@
146146
"name": "origin-ruby-sample:latest"
147147
}
148148
},
149+
"postCommit": {
150+
"script": "bundle exec rake test"
151+
},
149152
"resources": {}
150153
},
151154
"status": {

pkg/build/api/types.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ type SourceBuildStrategy struct {
432432
// There are five different ways to configure the hook. As an example, all forms
433433
// below are equivalent and will execute `rake test --verbose`.
434434
//
435-
// 1. Shell script:
435+
// 1. Bash script:
436436
//
437437
// BuildPostCommitSpec{
438438
// Script: "rake test --verbose",
@@ -441,7 +441,7 @@ type SourceBuildStrategy struct {
441441
// The above is a convenient form which is equivalent to:
442442
//
443443
// BuildPostCommitSpec{
444-
// Command: []string{"/bin/sh", "-c"},
444+
// Command: []string{"/bin/bash", "-c"},
445445
// Args: []string{"rake test --verbose"},
446446
// }
447447
//
@@ -470,8 +470,8 @@ type SourceBuildStrategy struct {
470470
// }
471471
//
472472
// This form is useful if you need to pass arguments that would otherwise be
473-
// hard to quote properly in the shell script. In the script, $0 will be
474-
// "/bin/sh" and $1, $2, etc, are the positional arguments from Args.
473+
// hard to quote properly in the Bash script. In the script, $0 will be
474+
// "/bin/bash" and $1, $2, etc, are the positional arguments from Args.
475475
//
476476
// 5. Command with arguments:
477477
//
@@ -486,19 +486,19 @@ type SourceBuildStrategy struct {
486486
// the fields are specified, the hook is not executed.
487487
type BuildPostCommitSpec struct {
488488
// Command is the command to run. It may not be specified with Script.
489-
// This might be needed if the image doesn't have "/bin/sh", or if you
489+
// This might be needed if the image doesn't have `/bin/bash`, or if you
490490
// do not want to use a shell. In all other cases, using Script might be
491491
// more convenient.
492492
Command []string
493493
// Args is a list of arguments that are provided to either Command,
494494
// Script or the Docker image's default entrypoint. The arguments are
495495
// placed immediately after the command to be run.
496496
Args []string
497-
// Script is a shell script to be run with `/bin/sh -c`. It may not be
497+
// Script is a Bash script to be run with `/bin/bash -c`. It may not be
498498
// specified with Command. Use Script when a shell script is appropriate
499499
// to execute the post build hook, for example for running unit tests
500-
// with "rake test". If you need control over the image entrypoint, or
501-
// if the image does not have "/bin/sh", use Command and/or Args.
500+
// with `rake test`. If you need control over the image entrypoint, or
501+
// if the image does not have `/bin/bash`, use Command and/or Args.
502502
Script string
503503
}
504504

pkg/build/api/v1/types.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ type SourceBuildStrategy struct {
415415
// There are five different ways to configure the hook. As an example, all forms
416416
// below are equivalent and will execute `rake test --verbose`.
417417
//
418-
// 1. Shell script:
418+
// 1. Bash script:
419419
//
420420
// BuildPostCommitSpec{
421421
// Script: "rake test --verbose",
@@ -424,7 +424,7 @@ type SourceBuildStrategy struct {
424424
// The above is a convenient form which is equivalent to:
425425
//
426426
// BuildPostCommitSpec{
427-
// Command: []string{"/bin/sh", "-c"},
427+
// Command: []string{"/bin/bash", "-c"},
428428
// Args: []string{"rake test --verbose"},
429429
// }
430430
//
@@ -453,8 +453,8 @@ type SourceBuildStrategy struct {
453453
// }
454454
//
455455
// This form is useful if you need to pass arguments that would otherwise be
456-
// hard to quote properly in the shell script. In the script, $0 will be
457-
// "/bin/sh" and $1, $2, etc, are the positional arguments from Args.
456+
// hard to quote properly in the Bash script. In the script, $0 will be
457+
// "/bin/bash" and $1, $2, etc, are the positional arguments from Args.
458458
//
459459
// 5. Command with arguments:
460460
//
@@ -469,19 +469,19 @@ type SourceBuildStrategy struct {
469469
// the fields are specified, the hook is not executed.
470470
type BuildPostCommitSpec struct {
471471
// Command is the command to run. It may not be specified with Script.
472-
// This might be needed if the image doesn't have "/bin/sh", or if you
472+
// This might be needed if the image doesn't have `/bin/bash`, or if you
473473
// do not want to use a shell. In all other cases, using Script might be
474474
// more convenient.
475475
Command []string `json:"command,omitempty" description:"command to be executed in a container running the build output image replacing the image's entrypoint"`
476476
// Args is a list of arguments that are provided to either Command,
477477
// Script or the Docker image's default entrypoint. The arguments are
478478
// placed immediately after the command to be run.
479479
Args []string `json:"args,omitempty" description:"arguments to command, script or the default image entrypoint"`
480-
// Script is a shell script to be run with `/bin/sh -c`. It may not be
480+
// Script is a Bash script to be run with `/bin/bash -c`. It may not be
481481
// specified with Command. Use Script when a shell script is appropriate
482482
// to execute the post build hook, for example for running unit tests
483-
// with "rake test". If you need control over the image entrypoint, or
484-
// if the image does not have "/bin/sh", use Command and/or Args.
483+
// with `rake test`. If you need control over the image entrypoint, or
484+
// if the image does not have `/bin/bash`, use Command and/or Args.
485485
Script string `json:"script,omitempty" description:"shell script to be executed in a container running the build output image"`
486486
}
487487

pkg/build/api/v1beta3/types.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ type SourceBuildStrategy struct {
402402
// There are five different ways to configure the hook. As an example, all forms
403403
// below are equivalent and will execute `rake test --verbose`.
404404
//
405-
// 1. Shell script:
405+
// 1. Bash script:
406406
//
407407
// BuildPostCommitSpec{
408408
// Script: "rake test --verbose",
@@ -411,7 +411,7 @@ type SourceBuildStrategy struct {
411411
// The above is a convenient form which is equivalent to:
412412
//
413413
// BuildPostCommitSpec{
414-
// Command: []string{"/bin/sh", "-c"},
414+
// Command: []string{"/bin/bash", "-c"},
415415
// Args: []string{"rake test --verbose"},
416416
// }
417417
//
@@ -440,8 +440,8 @@ type SourceBuildStrategy struct {
440440
// }
441441
//
442442
// This form is useful if you need to pass arguments that would otherwise be
443-
// hard to quote properly in the shell script. In the script, $0 will be
444-
// "/bin/sh" and $1, $2, etc, are the positional arguments from Args.
443+
// hard to quote properly in the Bash script. In the script, $0 will be
444+
// "/bin/bash" and $1, $2, etc, are the positional arguments from Args.
445445
//
446446
// 5. Command with arguments:
447447
//
@@ -456,19 +456,19 @@ type SourceBuildStrategy struct {
456456
// the fields are specified, the hook is not executed.
457457
type BuildPostCommitSpec struct {
458458
// Command is the command to run. It may not be specified with Script.
459-
// This might be needed if the image doesn't have "/bin/sh", or if you
459+
// This might be needed if the image doesn't have `/bin/bash`, or if you
460460
// do not want to use a shell. In all other cases, using Script might be
461461
// more convenient.
462462
Command []string `json:"command,omitempty" description:"command to be executed in a container running the build output image replacing the image's entrypoint"`
463463
// Args is a list of arguments that are provided to either Command,
464464
// Script or the Docker image's default entrypoint. The arguments are
465465
// placed immediately after the command to be run.
466466
Args []string `json:"args,omitempty" description:"arguments to command, script or the default image entrypoint"`
467-
// Script is a shell script to be run with `/bin/sh -c`. It may not be
467+
// Script is a Bash script to be run with `/bin/bash -c`. It may not be
468468
// specified with Command. Use Script when a shell script is appropriate
469469
// to execute the post build hook, for example for running unit tests
470-
// with "rake test". If you need control over the image entrypoint, or
471-
// if the image does not have "/bin/sh", use Command and/or Args.
470+
// with `rake test`. If you need control over the image entrypoint, or
471+
// if the image does not have `/bin/bash`, use Command and/or Args.
472472
Script string `json:"script,omitempty" description:"shell script to be executed in a container running the build output image"`
473473
}
474474

pkg/build/builder/common.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func execPostCommitHook(client DockerClient, postCommitSpec api.BuildPostCommitS
135135
glog.V(4).Infof("Post commit hook spec: %+v", postCommitSpec)
136136

137137
if script != "" {
138-
command = []string{"/bin/sh", "-c"}
138+
command = []string{"/bin/bash", "-c"}
139139
args = append([]string{script, command[0]}, args...)
140140
}
141141

test/cmd/builds.sh

+13-11
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,23 @@ os::cmd::expect_success 'oc delete all --all'
7272
os::cmd::expect_success "oc new-build -D \$'FROM centos:7' --no-output"
7373
os::cmd::expect_success_and_text 'oc get bc/centos -o=jsonpath="{.spec.output.to}"' '^<nil>$'
7474

75+
os::cmd::expect_success 'oc delete all --all'
76+
7577
# Ensure output is valid JSON
7678
os::cmd::expect_success 'oc new-build -D "FROM centos:7" -o json | python -m json.tool'
7779

7880
# Ensure post commit hook is executed
79-
os::cmd::expect_success 'oc new-build -D "FROM busybox:1"'
80-
os::cmd::try_until_text 'oc get istag busybox:1' 'busybox@sha256:'
81-
os::cmd::expect_success 'oc patch bc/busybox -p '\''{"spec":{"postCommit":{"script":"echo hello $1","args":["world"],"command":null}}}'\'
82-
os::cmd::expect_success_and_text 'oc get bc/busybox -o=jsonpath="{.spec.postCommit['\''script'\'','\''args'\'','\''command'\'']}"' '^echo hello \$1 \[world\] \[\]$'
83-
# os::cmd::expect_success_and_text 'oc start-build --wait --follow busybox' 'hello world'
84-
os::cmd::expect_success 'oc patch bc/busybox -p '\''{"spec":{"postCommit":{"command":["sh","-c"],"args":["echo explicit command"],"script":""}}}'\'
85-
os::cmd::expect_success_and_text 'oc get bc/busybox -o=jsonpath="{.spec.postCommit['\''script'\'','\''args'\'','\''command'\'']}"' ' \[echo explicit command\] \[sh -c\]'
86-
# os::cmd::expect_success_and_text 'oc start-build --wait --follow busybox' 'explicit command'
87-
os::cmd::expect_success 'oc patch bc/busybox -p '\''{"spec":{"postCommit":{"args":["echo","default entrypoint"],"command":null,"script":""}}}'\'
88-
os::cmd::expect_success_and_text 'oc get bc/busybox -o=jsonpath="{.spec.postCommit['\''script'\'','\''args'\'','\''command'\'']}"' ' \[echo default entrypoint\] \[\]'
89-
# os::cmd::expect_success_and_text 'oc start-build --wait --follow busybox' 'default entrypoint'
81+
os::cmd::expect_success 'oc new-build -D "FROM centos:7"'
82+
os::cmd::try_until_text 'oc get istag centos:7' 'centos@sha256:'
83+
os::cmd::expect_success 'oc patch bc/centos -p '\''{"spec":{"postCommit":{"script":"echo hello $1","args":["world"],"command":null}}}'\'
84+
os::cmd::expect_success_and_text 'oc get bc/centos -o=jsonpath="{.spec.postCommit['\''script'\'','\''args'\'','\''command'\'']}"' '^echo hello \$1 \[world\] \[\]$'
85+
# os::cmd::expect_success_and_text 'oc start-build --wait --follow centos' 'hello world'
86+
os::cmd::expect_success 'oc patch bc/centos -p '\''{"spec":{"postCommit":{"command":["sh","-c"],"args":["echo explicit command"],"script":""}}}'\'
87+
os::cmd::expect_success_and_text 'oc get bc/centos -o=jsonpath="{.spec.postCommit['\''script'\'','\''args'\'','\''command'\'']}"' ' \[echo explicit command\] \[sh -c\]'
88+
# os::cmd::expect_success_and_text 'oc start-build --wait --follow centos' 'explicit command'
89+
os::cmd::expect_success 'oc patch bc/centos -p '\''{"spec":{"postCommit":{"args":["echo","default entrypoint"],"command":null,"script":""}}}'\'
90+
os::cmd::expect_success_and_text 'oc get bc/centos -o=jsonpath="{.spec.postCommit['\''script'\'','\''args'\'','\''command'\'']}"' ' \[echo default entrypoint\] \[\]'
91+
# os::cmd::expect_success_and_text 'oc start-build --wait --follow centos' 'default entrypoint'
9092
echo "postCommitHook: ok"
9193

9294
os::cmd::expect_success 'oc delete all --all'

0 commit comments

Comments
 (0)