Push Docker images to ECR

CI uses Docker images from ECR to overcome, rate limit
set by DockerHub.

Change-Id: I6ad56778003f26f1746aad081c13d9079fc86538
Signed-off-by: Saheer Babu <saheer.babu@arm.com>
diff --git a/ci-dockerfiles-deployment/publish.sh b/ci-dockerfiles-deployment/publish.sh
index e196a16..2551872 100644
--- a/ci-dockerfiles-deployment/publish.sh
+++ b/ci-dockerfiles-deployment/publish.sh
@@ -24,7 +24,7 @@
 EOF
     chmod 0600 ${HOME}/.docker/config.json
 }
-
+export AWS_DEFAULT_REGION=eu-west-1
 update_images=$(find -type f -name .docker-tag)
 docker_log_in
 for imagename in ${update_images}; do
@@ -35,9 +35,18 @@
       docker tag ${docker_tag} ${new_tag}
       docker_tag=${new_tag}
     fi
+
     for i in 30 60 120;
     do
-        docker push ${docker_tag} && exit 0 || true
+        # The following code pushes docker images to both DockerHub and PRIVATE_CONTAINER_REGISTRY
+        # PRIVATE_CONTAINER_REGISTRY is used to overcome the DockerHub rate limiting
+        mirror_tag=${PRIVATE_CONTAINER_REGISTRY}/${docker_tag}
+        docker tag ${docker_tag} ${mirror_tag}
+        aws ecr get-login-password | docker login --username AWS --password-stdin ${PRIVATE_CONTAINER_REGISTRY}
+        REPO_NAME=$(echo "$docker_tag" | cut -d: -f1)
+        # create if repository not already present in PRIVATE_CONTAINER_REGISTRY
+        aws ecr describe-repositories --repository-names ${REPO_NAME} || aws ecr create-repository --repository-name ${REPO_NAME}
+        docker push ${docker_tag} && docker push ${mirror_tag} && exit 0 || true
         sleep $i
         docker_log_in
     done