In her judgment, high court judge Dame Elizabeth Butler-Sloss said Luke had multiple heart defects, chronic respiratory failure, severe development delay, epilepsy and severe problems in feeding.
He had suffered two cardiac arrests and many respiratory arrests during his time in hospital in Bangor, north Wales, and at Alder Hey children's hospital, Liverpool.
His condition was incurable, but his mother, Ruth Winston-Jones, described him as a fighter who was clinging on to life and defying the odds by staying alive.
She wanted his life to be dignified and comfortable and wanted him to die in dignity and comfort in his own time. She was anxious he should not suffer pain and distress, but believed the medical profession was giving up on Luke too soon.
Dame Elizabeth, who is president of the high court family division, said the mother clearly had a close relationship with Luke "who, despite all his medical problems, responds to her, lies happily in her arms while she cuddles him and goes peacefully to sleep".
Referring to Luke's "best interests", the judge said there was a strong presumption in favour of preserving life, but not if the treatment would be futile.
The judge ruled that mechanical ventilation, an aggressive procedure, would not be in the baby's best interests.
The anaesthetic carried great risks, and there was a risk of his becoming dependent on a ventilator, which would deprive him of his close cuddling relationship with his mother during the last weeks or months of his life.
His life "would not be worth living", the judge said.
Dame Elizabeth said the doctors, who had originally been against cardiac massage, were now not ruling it out, although it would be a matter for their clinical judgment as to when and whether to use it.
The procedure involved pressing two fingers on the baby's chest, to a depth of approximately one and a half inches, to massage the heart through the skin. This would be done for up to 100 times per minute over several minutes.
The method had been used on Luke twice "and I consider it should remain an option", the judge said.
Doctors would not use the method if, in their judgment, it would prove futile.
Luke suffers from Edwards syndrome, which severely affects most organs of the body. Few babies survive beyond a year.
The case followed a judge's ruling earlier this month giving doctors permission not to ventilate tiny premature baby Charlotte Wyatt if her breathing stops. Charlotte reached her first birthday yesterday.
The court heard that Ms Winston-Jones had agreed a palliative care plan aimed at allowing Luke to return home, and had been training in heart massage and resuscitation techniques.