Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws ecr login invalid character \r in hostname #18

Open
gpj1 opened this issue Feb 23, 2019 · 5 comments
Open

aws ecr login invalid character \r in hostname #18

gpj1 opened this issue Feb 23, 2019 · 5 comments

Comments

@gpj1
Copy link

gpj1 commented Feb 23, 2019

I'm using this mesosphere/aws-cli container in my CI pipeline for purpose of pushing an docker image to AWS ECR and below is my sh step of Jenkins Pipeline

sh """ alias aws='docker run --rm -t \$(tty &>/dev/null && echo "-i") -e AWS_ACCESS_KEY_ID=xxxxxx -e AWS_SECRET_ACCESS_KEY=xxxxxx -e AWS_DEFAULT_REGION=ap-south-1 -v \$(pwd):/project mesosphere/aws-cli' \$(aws ecr get-login --no-include-email) """

Output of this step during Jenkins build is:

......dmQxNTJrVzBIQVFEa1RESDJQUE0xUFJSbDg3bDFaRU5XMlYxenYzMEEvNUdLVWNDeVRhZGYyS0hoMnkvM3h1aC9Ta1VLdy9sQTcvK3NHYWFRUkUzUGZJRW5XR3c3T010QmErd2hlZFRhL1JLa3ciLCJkYXRha2V5IjoiQVFJQkFIaUhXYVlUblJVV0NibnorN0x2TUcrQVB2VEh6SGxCVVE5RnFFbVYyNkJkd3dHWlp3cW9vVVJTcUFBblNVY1RQdnBYQUFBQWZqQjhCZ2txaGtpRzl3MEJCd2FnYnpCdEFnRUFNR2dHQ1NxR1NJYjNEUUVIQVRBZUJnbGdoa2dCWlFNRUFTNHdFUVFNMG1kV2VuM3VrYXFPNEJyaUFnRVFnRHVPOWdXVVJtTkhEc3JrZC9YSkRWdlQ5Y0JORGpnU1dzbFQxMHpqSzVUV3VabWJpdVFZQThrZGxoeVFBM2xTREsyWlBETHlNVkFVdW12NVJBPT0iLCJ2ZXJzaW9uIjoiMiIsInR5cGUiOiJEQVRBX0tFWSIsImV4cGlyYXRpb24iOjE1NTA5NTE0MDV9 'https://xxxxxxxxxxx.dkr.ecr.ap-south-1.amazonaws.com ' WARNING! Using --password via the CLI is insecure. Use --password-stdin. Error response from daemon: unable to parse server address: parse https://xxxxxxxxxxx.dkr.ecr.ap-south-1.amazonaws.com : invalid character "\r" in host name

@JasonChinsen
Copy link

The issue is that aws ecr get-login is returning with Windows line ending

I ended up solving this with a little bash script where aws is an alias like you have listed above ^^

ECR=$(aws ecr get-login --no-include-email --region ${AWS_REGION})

echo "creating login temp file"
_ECR=$(echo ${ECR} | tr -d '\r')
echo ${_ECR} > ecr.out

echo "login into ecr"
$(cat ecr.out)

echo "pushing image to ecr"
docker push ${URL}

echo "removing temp file"
rm ecr.out```

@leopard627
Copy link

leopard627 commented Nov 26, 2019

ECR=$(docker exec -it guide-aws sh -c 'aws ecr get-login --no-include-email --region ${AWS_REGION}')
echo "creating login temp file"
_ECR=$(echo ${ECR} | tr -d '\r')
echo ${_ECR} > ecr.out

echo 'login into ecr'
$(cat ecr.out)

echo "removing temp file"
rm ecr.out

This command works well in environments without the aws plug-in.

inspired by JasonChinsen 's option :D

@paraker
Copy link

paraker commented Nov 28, 2019

Thanks for the help, much appreciated.
This also works with eval for a shorter script, at least in my case.

LOGIN_WITH_SPACES=$(aws ecr get-login --no-include-email --region ${AWS_REGION})
LOGIN_WITHOUT_SPACES=$(echo ${LOGIN_WITH_SPACES} | tr -d '\r')
eval $LOGIN_WITHOUT_SPACES

@totogo
Copy link

totogo commented Dec 20, 2019

Thanks for the help, much appreciated.
This also works with eval for a shorter script, at least in my case.

LOGIN_WITH_SPACES=$(aws ecr get-login --no-include-email --region ${AWS_REGION})
LOGIN_WITHOUT_SPACES=$(echo ${LOGIN_WITH_SPACES} | tr -d '\r')
eval $LOGIN_WITHOUT_SPACES

Thanks! To make it short in one command:

$(echo $(aws ecr get-login --no-include-email --region cn-north-1) | tr -d '\r')

@bvisonl
Copy link

bvisonl commented Dec 27, 2019

Thanks for this!

btw, without using echo from @totogo answer:

$(aws ecr get-login --no-include-email --region us-east-1 | tr -d '\r')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants