A relative Calabi-Yau structure for the Chekanov-Eliashberg algebra and applications