Bug 1311426

Summary: [devexp_public_844]Cannot implement post-build command when adding Command with arguments to bc and build
Product: OKD Reporter: wewang <wewang>
Component: BuildAssignee: Rodolfo Carvalho <rcarvalh>
Status: CLOSED CURRENTRELEASE QA Contact: Wenjing Zheng <wzheng>
Severity: medium Docs Contact:
Priority: medium    
Version: 3.xCC: aos-bugs
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1311435 (view as bug list) Environment:
Last Closed: 2016-05-12 17:12:59 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1311435    

Description wewang 2016-02-24 08:50:45 UTC
Version-Release number of selected component (if applicable):
openshift v1.1.3-228-ge8dd2a2
kubernetes v1.2.0-alpha.7-703-gbc4550d
etcd 2.2.5

Description of problem:
Cannot implement post-build command when adding Command with arguments to bc and build

Steps to Reproduce:
1. Login to openshift and create project 
2. Create app
   $oc new-app -f https://raw.githubusercontent.com/openshift/origin/master/examples/sample-app/application-template-dockerbuild.json
3.  Add Command with arguments to bc and build
                "postCommit": {
                    "command": [
                        "/bin/sh",
                        "-ic"
                    ],
                    "args": [
                        "rake",
                        "test"
                    ]
                }
            },

   $oc start-build <bc>
4. Check the log 
   

Actual results:
4. I0224 08:02:36.952679       1 environment.go:31] DEPRECATED: Use .s2i/environment instead of .sti/environment
I0224 08:02:36.952721       1 environment.go:60] Setting 1 environment variables provided by environment file in sources
I0224 08:02:42.369979       1 common.go:134] Running post commit hook with image wewang/ruby-sample-build-7:70c11ead ...
sh: cannot set terminal process group (-1): Inappropriate ioctl for device
sh: no job control in this shell
rake aborted!
LoadError: cannot load such file -- sinatra/activerecord
/opt/app-root/src/config/database.rb:1:in `<top (required)>'
/opt/app-root/src/Rakefile:3:in `require_relative'
/opt/app-root/src/Rakefile:3:in `<top (required)>'
(See full trace by running task with --trace)
F0224 08:02:43.409992       1 builder.go:204] Error: build error: container "openshift_s2i-build_ruby-sample-build-7_wewang_post-commit" returned non-zero exit code: 1

Expected results:

Can implement Command with arguments  and image push to registry

Comment 1 wewang 2016-02-24 08:53:17 UTC
when I use :
                "postCommit": {
                    "command": [
                        "/bin/sh",
                        "-ic"
                    ],
                    "args": [
                        "bundle",
                        "exec",
                        "rake",
                        "test"
                    ]

build is complete ,but logs have error:
sh: cannot set terminal process group (-1): Inappropriate ioctl for device
sh: no job control in this shell


http://pastebin.test.redhat.com/351307

Comment 2 wewang 2016-02-24 08:56:34 UTC
@rhcarvalho ,can you updated docs:https://github.com/PI-Victor/openshift-docs/blob/pi-victor/post_build_actions/dev_guide/builds.adoc#build-hooks? then merge

because I saw  post commit are not include "bundle exec";
        and command: ["/bin/sh", "-c"] should be command: ["/bin/sh", "-ic"] ,right?

Comment 3 wewang 2016-02-24 09:35:36 UTC
when I updated bc below
 Add Command  to bc and build
                 "postCommit": {
                    "command": [
                        "bundle",
                        "exec",
                        "rake",
                        "test",
                        "--verbose"
                    ]
                }


   $oc start-build <bc>
 Check the log 
   
Actual results:
 I0224 09:06:43.877799       1 common.go:134] Running post commit hook with image wewang/ruby-sample-build-10:59791539 ...
F0224 09:06:44.568459       1 builder.go:204] Error: build error: start container "openshift_s2i-build_ruby-sample-build-10_wewang_post-commit": API error (404): Cannot start container 62f8bad2d5b107a80b81396de4d4005b3e3e9ed515f71eb1071b8c7b4b9b7c96: [8] System error: exec: "bundle": executable file not found in $PATH

Comment 4 Rodolfo Carvalho 2016-02-24 11:42:56 UTC
@wewang thanks for the report.

1. Docs

You are right, the docs need to be updated. I've asked Victor who is leading the PR, I would like to get it cleaned up today.


2. Syntax

There are multiple ways to run the tests if you are using the command/args syntax.

For example, you can use Bash (then no need for -i):
"command": ["/bin/bash", "-c", "bundle exec rake test"]

Or, alternatively (with the Ruby image, since this relies on the image entrypoint):
"args": ["bundle exec rake test"]

(I'm updating the sample-app to use this as example, see https://github.com/openshift/origin/pull/7567)


I will comment on the values you tried to use and why they didn't work:


a.
                "postCommit": {
                    "command": ["/bin/sh", "-ic"],
                    "args": ["rake", "test"]
                }

This doesn't work because "rake" and "test" are passed as separate arguments, so only "rake" is executed and it fails ("rake aborted!"), the "test" part is ignored.

Example:

$ /bin/sh -ic "echo 123" this will be ignored
123

The example above, written with the command/args syntax is:
"command": ["/bin/sh", "-ic", "echo 123", "this", "will", "be", "ignored"]

Notice that command + args is the same as having only command with empty value for args, IOW:

{"command": ["/bin/bash"], "args": ["/my/script"]} == {"command": ["/bin/bash", "/my/script"]}


b. 
                "postCommit": {
                    "command": ["/bin/sh", "-ic"],
                    "args": ["bundle", "exec", "rake", "test"]


Same problem with args, should be a single string:

{"command": ["/bin/sh", "-ic"], "args": ["bundle exec rake test"]}


c. 
                 "postCommit": {
                    "command": ["bundle", "exec", "rake", "test", "--verbose"]
                 }

In this case, the Ruby image doesn't have "bundle" in the PATH by default ('"bundle": executable file not found in $PATH').
That's a known limitation of our SCL images, that need the appropriate SCLs to be enabled before you can use them.
We try to make it better by automatically enabling collections when:
   i.  `/bin/bash` is used
   ii. `/bin/sh -ic` is used

In all other cases, `scl enable ruby200` (depends on exact version) is needed.

That's why the script syntax uses `/bin/sh -ic`.

I didn't try, but something like this should work as well:

{"command": ["scl", "enable", "ruby200", "bundle", "exec", "rake", "test", "--verbose"]}

(might be missing something or have wrong collection name)

Comment 5 wewang 2016-02-25 07:02:28 UTC
@ Rodolfo Carvalho thanks for your detail comments
I already see docs has been updated 

and verified below sceniaros , it all works 
verified version:
openshift v1.1.3-271-g28e5bbf-dirty
kubernetes v1.2.0-alpha.7-703-gbc4550d
etcd 2.2.5

a.b.  updated postCommit with command and args 
       command: ["bundle", "exec", "rake", "test"]
       args: ["--verbose"]

c.  updated postCommit with command, "bundle exec rake test --verbose" is a single args :
      command: ["/bin/bash", "-c", "bundle exec rake test --verbose"]
 
the bug already verified now, you can set the bug to assigned,   if docs pr is merged ,will accept related card ,thanks for your quick response.

Comment 6 wewang 2016-02-26 01:34:48 UTC
as comment5 , and  verified in ose32 :openshift v3.1.1.906 too.