We present evidence that a magnetic flux rope was formed before a coronal mass ejection (CME) and its associated long-duration flare during a pair of preceding confined eruptions and associated impulsive flares in a compound event in NOAA Active Region 12371. Extreme-ultraviolet images and the extrapolated nonlinear force-free field show that the first two, impulsive flares, SOL2015-06-21T01:42, result from the confined eruption of highly sheared low-lying flux, presumably a seed flux rope. The eruption spawns a vertical current sheet, where magnetic reconnection creates flare ribbons and loops, a nonthermal microwave source, and a sigmoidal hot channel which can only be interpreted as a magnetic flux rope. Until the subsequent long-duration flare, SOL2015-06-21T02:36, the sigmoids elbows expand, while its center remains stationary, suggesting non-equilibrium but not yet instability. The flare reconnection during the confined eruptions acts like tether-cutting reconnection whose flux feeding of the rope leads to instability. The subsequent full eruption is seen as an accelerated rise of the entire hot channel, seamlessly evolving into the fast halo CME. Both the confined and ejective eruptions are consistent with the onset of the torus instability in the dipped decay index profile which results from the regions two-scale magnetic structure. We suggest that the formation or enhancement of a non-equilibrium but stable flux rope by confined eruptions is a generic process occurring prior to many CMEs.