In the seventh aliyah Moshe writes down the song and then encourages Yehoshua to be strong and brave.
Then the Torah says that Moshe finished writing the Torah to the very end, and then he gave orders that the Torah he wrote should be placed by the side of the ark of the luchos (tablets).
K'siva V'Chasima Tova