cloud_controller_ng icon indicating copy to clipboard operation
cloud_controller_ng copied to clipboard

cf run-task failing for docker-based apps

Open rahearn opened this issue 5 years ago • 3 comments

Issue

A simple app built with Ruby on Rails and deployed to cloud.gov via docker image runs fine, but cf run-tasks and cf ssh do not work without workarounds.

Context

It appears that the PATH gets messed up for cf run-tasks and cf ssh while the actual running app is fine. On an example app:

cf run-tasks cf-test "bundle exec rake db:migrate" fails, but

cf run-task cf-test "export PATH=/usr/local/bundle/bin:/usr/local/bundle/gems/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin && cd /usr/src/app && bundle check --path vendor/bundle/ && bundle exec rake db:migrate"

works. The same PATH exporting and bundle check dance is required to run commands after using cf ssh APP_NAME

On further testing today, run-task might only require prepending the cd /usr/src/app (that path being the WORKDIR of the docker image) part to correctly run, though cf ssh requires the full setup before commands start being found.

Steps to Reproduce

A reproducing example app is at https://github.com/rahearn/cf-docker-test

The full docker build command used was:

docker build -t rcahearn/cf-test --build-arg RAILS_MASTER_KEY=809a1129e14e8e36f126c76dfce87e25 --build-arg BUILD_ENV=production --build-arg BUNDLE_WITHOUT="development test" .

Expected result

Tasks such as bundle exec rake db:migrate:status complete successfully.

Current result

Tasks such as bundle exec rake db:migrate:status fail with logs:

2019-06-14T09:09:24.14-0400 [APP/TASK/f180fd00/0] ERR Could not locate Gemfile or .bundle/ directory
2019-06-14T09:09:24.17-0400 [APP/TASK/f180fd00/0] OUT Exit status 10

Commands such as bundle exec rake db:migrate:status when run after sshing to app fail with:

root@f153f6fd-97a9-47ab-4a36-e9c8:/usr/src/app# bundle exec rake db:migrate:status
bash: bundle: command not found

rahearn avatar Jun 14 '19 13:06 rahearn

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/166700434

The labels on this github issue will be updated when the story is started.

cf-gitbot avatar Jun 14 '19 13:06 cf-gitbot

There is some context in #1333 around why the cf ssh environment is different than the app running environment: https://github.com/cloudfoundry/cloud_controller_ng/issues/1333#issuecomment-486478224

Gerg avatar Aug 07 '20 16:08 Gerg

workarounds:

  • get envs from /proc/<PID>/environ
  • start a "sidecar" server in the entrypoint as port ":9999" which responds with the environment it has and then when executing the task or ssh eval $(curl localhost:999)

matti avatar Jun 08 '21 09:06 matti