-
-
Notifications
You must be signed in to change notification settings - Fork 580
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
Make ddev ssh
exit more predictable, not outputting useless info, fixes #3738
#4569
Conversation
You can push new commits into this if you think you see a path forward. |
Download the artifacts for this pull request: |
I took the liberty of rebasing this since the updated docker-compose will be in there now. I don't think it changes anything, but you'll want to update your git checkout. |
cmd/ddev/cmd/ssh.go
Outdated
if err != nil && isPiped { | ||
util.Failed("Failed to ddev ssh %s: %v", serviceType, err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The easy part of this PR is to remove the output on failure as it's not useful, and in the case of ddev ssh
was already output if needed, and just exit with the exit code, which can be done something like this:
if err != nil && isPiped { | |
util.Failed("Failed to ddev ssh %s: %v", serviceType, err) | |
} | |
if err != nil { // Didn't experiment with your isPiped here... | |
if exiterr, ok := err.(*exec.ExitError); ok { | |
os.Exit(exiterr.ExitCode()) | |
} else { | |
os.Exit(1) | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. So many moving parts on top of just getting my head around Go, so every little suggestion is appreciated. Will check this out!
Oh, if you don't have GoLand (or vscode) set up to let you debug through things, make sure to make that a priority. I love Goland, I think you will too. Lots of people use vscode successfully, but it's more tweaky, and I am not a master of the tweaks. But make sure you can do step-debugging. Of course, the pipe thing you're trying to do here is one of the hardest things to do with step debugging. |
I'm using VSCode. I'm cash strapped at the moment and I don't see paying for another tool anytime soon. And yeah, I was wondering how you do step debugging with Go. I tried a cursory search but didn't really understand the suggested results. If you have specific suggestions for VSCode, I'm all ears. Will keep looking at these issues as I learn though. Thank you for the opportunity and help! |
Yeah, IMO the first thing to do with any development project in any language is to get step-debugging going, so spend some time with it. There are docs around, and the Gitpod integration is all set up with it, so you could debug with this PR at https://gitpod.io/#https://github.com/drud/ddev/pull/4569, but since you're an established vscode user I'd try to get it set up locally as well. |
So see It turns out that the phony exit codes are a feature of bash. So all we really need to do here is
|
I'm not sure, but I think this is now doing what you expect?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making progress! I think we can get rid of more now :)
I'm going to take the liberty of rebasing this now, because you now have lots of bits and pieces you don't want, so when you start working on it, make sure your git remote is updated.
ddev ssh
exit more predictable, not outputting useless info, fixes #3738
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this is perfect now. Behavior is as expected. The one thing I'd like to ask is to remove
https://github.com/drud/ddev/blob/995cc6beffe375a5ada8ecdecf17ac707b608ad0/cmd/ddev/cmd/ssh.go#L34-L37
The reason is... we don't have to check siteStatus if the container is running. I think this might be better in the case where one container failed.
Yes, I've been meaning all day to say that I think you had it and to thank you for your patience with my tunnel vision as I now totally see what you were getting at the entire time and how what was in the pipe was irrelevant. But I wanted to test it before reporting back on those changes but I seemed to have done something unexplainable that prevents me from running the compiled project. So I haven't been able to test it. I am using an M1 (arm64), and for some reason (probably from a previous bad install), things were compiling amd64. Oddly, now that I think it's "fixed" I get
That's definitely the executable I just compiled with "make" but still I get I've uninstalled and re-installed Go and tools and blew away my local of ddev and re-cloned.
Don't see how it has anything to do with ddev, so trying to figure out what's wrong and will circle back. Your signature on this quickfix should be "If things get any worse, I'm going to have to ask you to stop helping." :-D |
So weird. Compiling for amd64 works:
|
Running amd64, I get the following with the above code, which I believe isn't what you want due to the non-zero exit code on exit:
but I don't really trust my environment right now, maybe it's a Rosetta thing? |
"The reason is... we don't have to check siteStatus if the container is running. I think this might be better in the case where one container failed." Yes, I didn't think that was necessary for same reason but you had suggested it earlier and I just thought I was missing something. Will address that after I figure out my local issues. |
You're doing great, congratulations! The problem with your build is you have some bad-architecture I don't recommend running amd64 anything on arm64. Just confuses everything. If you just run |
When I run
Yes, I've just been copying that (as noted above). But if I do
|
Twilight Zone level stuff. Restarted the whole computer. And now seems to That fixed, I don't think that code is working the way you want it to, because if an error is returned from the previous command per os, it spits that out (code 2) and you want 0 on exit:
This actually worked correctly with the pipe check code in there because if you're not piping anything, it returns nothing: |
The case you show is bash's fault, and it's OK. As explored in I don't think there's a "fix" that makes any sense if that's the behavior of bash. But now we don't whine about it with extra output. |
Use |
Oh. Okay. Was going off of something you said last week in #3738 (comment):
Because if you really want it 0, I was getting that by bypassing that whole return block if we weren't expecting a return value for a piped in command. |
That was before I studied the bash behavior. |
Ah! Understood. And I also misread the block you wanted removed. Thought you were asking to remove the service check (not the SiteRunning check). I'm 2 steps behind but catching up! |
Give it a look now. (symlinking was the answer, btw, copying it = bad) |
Attempt to check if values were piped in before deciding to return additional error ou tput from ssh.go. Issue ddev#3738.
Remove piped input check per rfay suggestion. Co-authored-by: Randy Fay <randy@randyfay.com>
Remove unused iPiped conditional check per rfay suggstion. Co-authored-by: Randy Fay <randy@randyfay.com>
Remove unnecessary siterunning check now that we check for if the service is running.
I hope you'll be ready for another challenge! Maybe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great to me! I'll manually test one more time before pull, but congratulations!
Absolutely! Thank you again for the opportunity and the guidance, even that out of scope of the issue. And I'll even name the branch correctly as requested for the PR! :-) Thank you for the |
I always try to keep PRs rebased to current upstream/master. This can be done
|
I think you're all done here, but general workflow is:
When it gets merged, the PR will be closed. If it says "fixes ..." like the title here does, it will auto-close the related issue, #3738 in this case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks perfect; I did another manual test and things look just right.
It has a great side-effect that I've always wanted. Now when you have a failure to start due to some random container failing, you can still ddev ssh
into the other containers that were successfully started.
Congratulations! |
Attempt to check if values were piped in before deciding to return additional error output from ssh.go. Issue
ddev ssh
should return the exit code that is returned from docker-compose and not add extra output #3738.The Issue
ddev ssh
returns output when not needed. It should only do so when a command was piped in.Lots of confusion on this...
The change reversion happened in
Which was fixing
How This PR Solves The Issue
It doesn't. It's a direction that needs work. Reading the stdin/piped-in values removes them from evaluation later down the chain.
Manual Testing Instructions
Should NOT produce additional output and should exit with code 0:
SHOULD produce error output from the piped in command:
echo "ls /non-existent" | ddev ssh
Automated Testing Overview
No automated tests at this time.
Related Issue Link(s)
#3738
Release/Deployment Notes
In addition to not solving the problem,
ddev ssh
"hangs" because it appears to be waiting for stdin input read.