docker: Fix DockerHub auth when using ECR
The code was written to not do any authentication to DockerHub when using Amazon Elastic Container Registry. This causes pipeline to fail due to ratelimiting on DockerHub.
Restructure the code to always authenticate to DockerHub, even if we are going to push the image to Amazon ECR.