Rearrange vm-slug build-app into functions

Separated individual steps and made use of locals
to make it easier to reuse or rewrite sections later.

Change-Id: I67fb581b370f1a6a79ddd575f58265c46811cd70
Merge "Rearrange vm-slug build-app into functions"