Care deeply, but do not take yourself too seriously.
I have worked for some deeply ethical companies, and some rather shady ones. I felt better about myself and what I did when I worked for the ethical ones, even if their choices differed from the ones I would have made.
There are degrees. A not-so-stellar company can still be a reasonable choice to work for, as long as they have not gone so far down the path of evil that you are compelled to quit. To give an example: I have many friends at Apple. I do not agree with some of the recent App Store decisions Apple has made, but I do not think they have made the company unethical, merely foolish on occasion. I thus do not think my friends should switch jobs.
A different company I worked for did things that I felt were attempts to mislead the government while applying for grants. While the company was "minority and women owned", the minority/woman owner was not involved in any way with the company beyond the articles of incorporation. Legal, yes, but ethical, no. I finished my contract, but was happy that they did not get the contract they were trying for.
Had they gotten closer to winning the contract, I would have had a much harder choice.
Another friend of mine works in the porn industry, and is not at all happy about some of the things he has done. I am glad I do not have his choices.
There is a temptation to equate the importance of our work with the importance it had for us. It is of some importance to me that my "life's work" be a net good for our species and our world, but not every day, or every job, is going to count for much on the positive side. I wrote a front end for a product that was cancelled, and while I would rather have had the product shine, I am content that I learned a lot, have taught the lessons the cancelled project taught me, and have been able to make a living that let me bring up my daughter well.
Failed projects had best not be a pattern. I will view it differently if several such products tank. Some failure is a proxy for having taken a risk. Other failures mean you are shooting at the wrong targets. So far, it feels like this one project was in the first category.
So, were I to take myself too seriously, I would probably lose sleep thinking about whether I had spent those irreplaceable hours well. Instead, I try to make sure that I am always either content with what I am doing and learning, or I am working actively to change that which offends me.
I do find that working for a company with a clear code of ethics really makes it easier to sleep at night. I have done so several times, and it makes a difference.
Scott