我正在尝试设置Bitbucket管道以部署到ECS,如下所示:https://confluence.atlassian.com/bitbucket/deploy-to-amazon-ecs-892623902.html
这些说明说明如何推送到Docker中心,但我想将图像推送到亚马逊的图像仓库。我在我的Bitbucket参数列表中设置了AWS_SECRET_ACCESS_KEY和AWS_ACCESS_KEY_ID,我可以在本地运行这些命令而没有任何问题(在〜/ .aws / credentials中定义的键)。但是,我不断收到错误'no basic auth credentials'。我想知道它是不是以某种方式识别变量。这里的文档:http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html说:
AWS CLI使用提供商链在许多不同的位置查找AWS凭证,包括系统或用户环境变量和本地AWS配置文件。所以我不确定为什么它不起作用。我的bitbucket管道配置如此(我没有包含任何不必要的东西):
- export IMAGE_NAME=$AWS_REPO_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/my/repo-name:$BITBUCKET_COMMIT
# build the Docker image (this will use the Dockerfile in the root of the repo)
- docker build -t $IMAGE_NAME .
# authenticate with the AWS repo (this gets and runs the docker login command)
- eval $(aws ecr get-login --region $AWS_DEFAULT_REGION)
# push the new Docker image to the repo
- docker push $IMAGE_NAME
有没有办法指定要使用的aws ecr get-login的凭据?我甚至试过这个,但它不起作用:
- mkdir -p ~/.aws
- echo -e "[default]\n" > ~/.aws/credentials
- echo -e "aws_access_key_id = $AWS_ACCESS_KEY_ID\n" >> ~/.aws/credentials
- echo -e "aws_secret_access_key = $AWS_SECRET_ACCESS_KEY\n" >> ~/.aws/credentials
由于
答案 0 :(得分:0)
试试这个:
<强>到位桶-pipeline.yml 强>
pipelines:
custom:
example-image-builder:
- step:
image: python:3
script:
- export CLONE_ROOT=${BITBUCKET_CLONE_DIR}/../example
- export IMAGE_LOCATION=<ENTER IMAGE LOCATION HERE>
- export BUILD_CONTEXT=${BITBUCKET_CLONE_DIR}/build/example-image-builder/dockerfile
- pip install awscli
- aws s3 cp s3://example-deployment-bucket/deploy-keys/bitbucket-read-key .
- chmod 0400 bitbucket-read-key
- ssh-agent bash -c 'ssh-add bitbucket-read-key; git clone --depth 1 git@bitbucket.org:example.git -b master ${CLONE_ROOT}'
- cp ${CLONE_ROOT}/requirements.txt ${BUILD_CONTEXT}/requirements.txt
- eval $(aws ecr get-login --region us-east-1 --no-include-email)
- docker build --no-cache --file=${BUILD_CONTEXT}/dockerfile --build-arg AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} --build-arg AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} --tag=${IMAGE_LOCATION} ${BUILD_CONTEXT}
- docker push ${IMAGE_LOCATION}
options:
docker: true
<强> dockerfile 强>
FROM python:3
MAINTAINER Me <me@me.me>
COPY requirements.txt requirements.txt
ENV DEBIAN_FRONTEND noninteractive
ARG AWS_ACCESS_KEY_ID
ARG AWS_SECRET_ACCESS_KEY
RUN apt-get update && apt-get -y install stuff
ENTRYPOINT ["/bin/bash"]
我的时间不多了,所以现在我不仅包括你问题的答案。但这将是一个足够好的模板。如果有任何你不理解的行,请在评论中提问,我会编辑答案。
答案 1 :(得分:0)
您需要在Bitbucket中设置Environnment变量
对您的管道进行细微更改
image:Docker-Image-With-awscli