I think the design your future actions is a big part of this.
I've had some success with framing two modes, Architect Mode and Implementation Mode.
Architect Mode is when you sit down and make a plan to achieve a long term challenging goal (losing a lot of weight, getting in shape, learning something new, etc.). It's where you set up a routine and plan for what you're specifically going to do each day in order to do this. Being able to separate this plan from when you're actually enacting it is important because it removes the choice and doesn't allow comparisons of an immediate reward with an abstract distant reward.
Implementation Mode has to follow what was set up by the architect and is not allowed to make decisions - this is because you're compromised and unreliable when comparing an immediate reward (do I eat that slice of cheesecake?) to a long term abstract reward and it's very easy to rationalize why what you want to do is actually okay (it's only an extra 400 calories anyway - today can be a cheat day etc.).
A big part of succeeding with implementation is stacking success (doing the thing every day without missing any day) and picking a small enough starting point. Another is not putting yourself in positions where you're easily tempted to fail (don't buy oreos and have them in the house). Once you get more in the rhythm of things you are safer in more difficult environments.
When Implementation mode fails it means the architect needs to reevaluate why and make changes - it doesn't help to ruminate or beat yourself up about the failure.
Even with this mindset things are difficult, but I've found it to be the most successful for long term goals when they're clearly defined - most of it is getting the psychology right - then the behavior can follow.