There's another option: joining the EU, which is also a military alliance these days. And it's possible to join without controlling all of your internationally recognized territory, as the example of Cyprus has shown. Unfortunately, joining the EU is more complicated than joining NATO and would take a decade or more.
RE: How can Ukraine win the war with Russia?