CircleCIで以下のエラーが出た時にめちゃめちゃ悩みました。
#!/bin/bash -eo pipefail
# get-login-password returns a password that we pipe to the docker login command
aws ecr get-login-password --region $AWS_DEFAULT_REGION --profile default | docker login --username AWS --password-stdin $AWS_ECR_ACCOUNT_URL
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
aws: error: argument operation: Invalid choice, valid choices are:
batch-check-layer-availability | batch-delete-image
batch-get-image | complete-layer-upload
create-repository | delete-repository
delete-repository-policy | describe-images
describe-repositories | get-authorization-token
get-download-url-for-layer | get-repository-policy
initiate-layer-upload | list-images
put-image | set-repository-policy
upload-layer-part | get-login
help
Error: Cannot perform an interactive login from a non TTY device
Exited with code exit status 1
CircleCI received exit code 1
その時の設定は以下の感じです。
orbs:
aws-cli: circleci/aws-cli@2.0.3
aws-ecr: circleci/aws-ecr@7.0.0
commands:
build_and_push:
parameters:
dockerfile: { type: string }
repo: { type: string }
build_args: { type: string, default: "" }
steps:
- aws-cli/install
- checkout
- run: echo "export DATE_TAG=`date +%Y%m%d%H%M%S`" >> $BASH_ENV
- aws-ecr/build-and-push-image:
checkout: false
region: AWS_DEFAULT_REGION
dockerfile: << parameters.dockerfile >>
extra-build-args: << parameters.build_args >>
repo: << parameters.repo >>
tag: latest
- aws-ecr/build-and-push-image:
checkout: false
region: AWS_DEFAULT_REGION
dockerfile: << parameters.dockerfile >>
extra-build-args: << parameters.build_args >>
repo: << parameters.repo >>
tag: ${DATE_TAG}
原因
- 原因は、最初の
aws-cli/install
でバージョン2系を使っているのに、既に1系がインストールされていて、aws ecr get-login-password
というコマンドが存在しないことでした。
1系がインストール済みで2系のインストールがスキップされていることのスクショ
対応
- 以下のようにして回避しました。
- aws-cli/install:
override-installed: true