GoogleContainerTools / skaffold

Easy and Repeatable Kubernetes Development
https://skaffold.dev/
Apache License 2.0
15k stars 1.62k forks source link

`debug` should rewrite command-lines to remove 'exec' #7168

Open briandealwis opened 2 years ago

briandealwis commented 2 years ago

Motivated by [a problem on stackoverflow](), where the user's Dockerfile had CMD exec gunicorn .... The Python debug launcher does not strip out the exec and so the launch fails.

Normally this is somewhat self-evident from the logs:

Waiting for deployments to stabilize...
 - pods: waiting for init container install-python-debug-support to start
    - pod/python3: waiting for init container install-python-debug-support to start
 - pods: container python3-web terminated with exit code 1
    - pod/python3: container python3-web terminated with exit code 1
      > [python3 python3-web] time="2022-03-08T15:24:02Z" level=warning msg="unable to determine launcher: could not find launcher \"exec\": exec: \"exec\": executable file not found in $PATH"
      > [python3 python3-web] time="2022-03-08T15:24:02Z" level=fatal msg="error launching python debugging: exec: \"exec\": executable file not found in $PATH"
 - pods failed. Error: container python3-web terminated with exit code 1.

But the logs are more hit-and-miss with the Cloud Run emulator in Cloud Code, where I usually see logs like:

Waiting for deployments to stabilize...
Deploy completed in 2.538 seconds
 - deployment/t: waiting for init container install-python-debug-support to start
    - pod/t-7677684866-kbrlx: waiting for init container install-python-debug-support to start
 - deployment/t: container t-container terminated with exit code 1
    - pod/t-7677684866-kbrlx: container t-container terminated with exit code 1
      > Error retrieving logs for pod t-7677684866-kbrlx: exit status 1.
Try `kubectl logs t-7677684866-kbrlx -n default -c t-container`
 - deployment/t failed. Error: container t-container terminated with exit code 1.

Strategy

We have some command-line rewriting for the Buildpacks case. This could be generalized into a set of transformations, one of which would strip off exec, and another of which might handle env A=B ... too? Or maybe recognize and error on patterns that won't work, like sh -c '...' or ... && ...

amocsub commented 2 years ago

This is probably associated because people like me uses the quickstart documentation Dockerfile with that exec. thanks @briandealwis for creating the issue