I have a problem with Gitlab CI/CD, where I have a runner that tries to authorize into AWS ECR. The .gitlab-ci.yaml file looks like this
stages:
- build
- deploy
build_and_push_docker:
stage: build
image: docker:19.03.12
script:
- docker build -t repo-image .
- docker tag ata-repo-image:latest $AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/repo:latest
- echo $AWS_ACCESS_KEY_ID | docker login -u AWS --password-stdin https://$AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com
- docker push $AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/repo:latest
download_signed_files_from_ecr:
stage: deploy
image: amazon/aws-cli:latest
entrypoint: ["/bin/sh", "-c"]
script:
- aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
- aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
- aws configure set default.region us-east-1
- docker pull $AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/repo:latest
- docker run --rm -v $(pwd):/downloads $AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/repo:latest cp /var/www/html/signed/*.deb /downloads/
artifacts:
paths:
- /downloads
only:
- master
I get this error when I tried to run it
$ docker tag ata-repo-image:latest $AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/repo:latest
$ aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com
/bin/sh: eval: line 139: aws: not found
Error: Cannot perform an interactive login from a non TTY device
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1
Login and AWS Policy look okay. Authorization via the terminal was performed without any issue so I suppose there might be a problem with the runner configuration or something like that.
You can try adding something like the following in your build stage:
This should add needed libraries and install AWS CLI which is missing in the
docker
image you are using for yourbuild stage
.It is not shown in the
.gitlab-ci.yaml
example you provided with your question, but in your posted error response, a second line:indicates that you are trying to authorize using AWS CLI, for which it printed an error
aws: not found
.