Upgrade attack first but try to keep upgrading at least something all or almost all the time. This is usually important when you have to wait for some big armory upgrade to finish and do not want to raid the map until this is done.

The more gaps in upgrade you have the later you will get to XP 56, which unlocks HQ 22.  Also at higher level (starting from about Armory 15-16) it makes a lot of sense to instant finish the Armory (once you raided enough resources for it) and then immediately schedule some expensive upgrade in it. 

Good luck with the game.

Community content is available under CC-BY-SA unless otherwise noted.