@@ -32,6 +32,7 @@ Available flags and environment variables:
3232
3333 * Amazon Web Services:
3434 - "--aws-secret-access-key" flag or "AWS_SECRET_ACCESS_KEY" environment variable: Amazon Web Services IAM account key (string value)
35+ - "--aws-region" flag or "AWS_REGION" environment variable: Region of the container repository
3536
3637 * Azure Services:
3738 - "--aks-tenant-id" flag or "AKS_TENANT_ID" environment variable: Azure Services tenant id
@@ -47,6 +48,7 @@ Available flags and environment variables:
4748 imageRepoPass , _ := cmd .Flags ().GetString ("image-repo-pass" )
4849 gcpKeyJson , _ := cmd .Flags ().GetString ("gcp-key-json" )
4950 awsSecretAccessKey , _ := cmd .Flags ().GetString ("aws-secret-access-key" )
51+ awsRegion , _ := cmd .Flags ().GetString ("aws-region" )
5052 aksTenantID , _ := cmd .Flags ().GetString ("aks-tenant-id" )
5153 aksSPAppID , _ := cmd .Flags ().GetString ("aks-sp-app-id" )
5254 aksSPPass , _ := cmd .Flags ().GetString ("aks-sp-password" )
@@ -62,6 +64,9 @@ Available flags and environment variables:
6264 if len (awsSecretAccessKey ) == 0 {
6365 awsSecretAccessKey = os .Getenv ("AWS_SECRET_ACCESS_KEY" )
6466 }
67+ if len (awsRegion ) == 0 {
68+ awsRegion = os .Getenv ("AWS_REGION" )
69+ }
6570 if len (imageRepoHost ) == 0 {
6671 imageRepoHost = os .Getenv ("IMAGE_REPO_HOST" )
6772 }
@@ -93,6 +98,7 @@ Available flags and environment variables:
9398 fmt .Println ("IMAGE_REPO_PASS:" , imageRepoPass )
9499 fmt .Println ("GCLOUD_KEY_JSON:" , gcpKeyJson )
95100 fmt .Println ("AWS_SECRET_ACCESS_KEY:" , awsSecretAccessKey )
101+ fmt .Println ("AWS_REGION:" , awsRegion )
96102 fmt .Println ("AKS_TENANT_ID:" , aksTenantID )
97103 fmt .Println ("AKS_SP_APP_ID:" , aksSPAppID )
98104 fmt .Println ("AKS_SP_PASSWORD:" , aksSPPass )
@@ -121,8 +127,15 @@ Available flags and environment variables:
121127 command = fmt .Sprintf ("echo %q | docker login --username %q --password-stdin %s" , gcpKeyJson , "_json_key" , imageRepoHost )
122128
123129 } else if awsSecretAccessKey != "" {
130+ //Get AWS Account ID
131+ awsAccountId , err := exec .Command ("bash" , "-c" , "aws sts get-caller-identity --query \" Account\" --output text --no-cli-pager" ).CombinedOutput ()
132+ if err != nil {
133+ log .Fatal ("Error:" , err )
134+ }
135+ //Remove newline
136+ awsAccountId = []byte (strings .TrimSuffix (string (awsAccountId ), "\n " ))
124137 // ECR login
125- command = fmt .Sprintf ("aws ecr get-login --no-include-email | bash" )
138+ command = fmt .Sprintf ("aws ecr get-login-password --region %s | docker login --username AWS --password-stdin %s.dkr.ecr.%s.amazonaws.com" , awsRegion , awsAccountId , awsRegion )
126139 // TODO: use aws cli v2
127140 // command = fmt.Sprintf("echo %q | docker login --username AWS --password-stdin %s", awsSecretAccessKey, imageRepoHost)
128141
@@ -155,6 +168,7 @@ func init() {
155168 ciImageLoginCmd .Flags ().String ("image-repo-pass" , "" , "(Docker) container image repository password" )
156169 ciImageLoginCmd .Flags ().String ("gcp-key-json" , "" , "Google Cloud service account key (plaintext, json)" )
157170 ciImageLoginCmd .Flags ().String ("aws-secret-access-key" , "" , "Amazon Web Services IAM account key (string value)" )
171+ ciImageLoginCmd .Flags ().String ("aws-region" , "" , "Elastic Container Registry region (string value)" )
158172 ciImageLoginCmd .Flags ().String ("aks-tenant-id" , "" , "Azure Services tenant id" )
159173 ciImageLoginCmd .Flags ().String ("aks-sp-app-id" , "" , "Azure Services servicePrincipal app id" )
160174 ciImageLoginCmd .Flags ().String ("aks-sp-password" , "" , "Azure Services servicePrincipal password" )
0 commit comments