[WIP] Refactor artifacts

This extracts the script for installing artifacts to a template, extracts environment as well as validation related logic to separate classes.

Don't merge. I need to port the `:header` stage from the stages pull request.