A robust method for producing half-cycle-few-cycle attosecond pulses in the extreme ultraviolet spectral range is proposed. It is based on coherent undulator radiation of relativistic ultrathin electron layers (nanobunches), which are produced by nanobunching of ultrashort electron bunches by a 10-TW power laser in a modulator undulator. Our numerical calculations predict the generation of nanobunches shorter than 10 nm. By using these electron nanobunches the production of carrier-envelope-phase stable attosecond pulses with up to a few tens of nJ energy and down to 10 nm wavelength and 35 as duration is predicted.