The story
From fair-weather + friend, drawing an analogy between good weather and trouble-free times.
First known use, by meaning
- from early 18th c. One who is friendly, helpful, or available only when it is advantageous or convenient to be so.
Etymology from Wiktionary, CC BY-SA 4.0.