You're pretty much there with your code. You just need to set the SR on the map

    ras= "my_layer.tif"
    sr=arcpy.Describe(ras).spatialReference
    
    p = arcpy.mp.ArcGISProject(r"\\ptemplate\project.aprx)
    m = p.listMaps()[0]
    m.spatialReference = sr
    p.saveACopy(r"\\my_projects\project_out.aprx)