Skip to content

Commit

Permalink
Merge pull request #3 from Cervest/docker-login-aws-profile
Browse files Browse the repository at this point in the history
use aws iam role name as profile in aws ecr get login, else use default
  • Loading branch information
raids authored May 18, 2021
2 parents 18c9ad7 + e2d2768 commit 90cd8f7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 4 additions & 3 deletions build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ const setAWSAssumeRoleProfile = (
console.log("AWS assume role profile added to ~/.aws/config")
}

const dockerECRLogin = (awsAccountId: string) => {
const loginPassword = shell("aws ecr get-login-password").trim()
const dockerECRLogin = (awsAccountId: string, awsIamRoleName?: string) => {
const awsProfile = awsIamRoleName || "default"
const loginPassword = shell(
`aws ecr get-login-password --profile ${awsProfile}`
).trim()
const loginResult = shell(
`docker login -u AWS -p ${loginPassword} https://${awsAccountId}.dkr.ecr.eu-west-1.amazonaws.com`
)
Expand Down Expand Up @@ -114,7 +117,7 @@ const main = () => {
if (awsIamRoleName) {
setAWSAssumeRoleProfile(awsIamRoleName, awsAccountId)
}
dockerECRLogin(awsAccountId)
dockerECRLogin(awsAccountId, awsIamRoleName)
setKubernetesConfig(awsAccountId, encodedKubeConfig, cluster)
}

Expand Down

0 comments on commit 90cd8f7

Please sign in to comment.