0

我正在为简单的 Spring Boot 项目准备 AWS CodePipeline。

下面是 buildspec.yml 的内容。

AWS_DEFAULT_REGION = eu-central-1

CONTAINER_NAME=cicd-1-app

REPOSITORY_URI = xxxxx.dkr.ecr.eu-central-1.amazonaws.com/cicd-1-app

version: 0.2
phases:
  install:
    runtime-versions:
      java: corretto11
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - aws --version
      - TAG="$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 8)"
      - IMAGE_URI=${REPOSITORY_URI}:${TAG}
  build:
    commands:
      - echo Build started on `date`
      - echo $IMAGE_URI
      - mvn clean package -Ddockerfile.skip
      - docker build --tag $IMAGE_URI .
  post_build:
    commands:
      - printenv
      - echo Build completed on `date`
      - echo $(docker images)
      - echo Pushing docker image
      - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin xxxxxxx.dkr.ecr.eu-central-1.amazonaws.com
      - docker push $IMAGE_URI
      - echo push completed
      - printf '[{"name":"%s","imageUri":"%s"}]' $CONTAINER_NAME $IMAGE_URI > imagedefinitions.json
artifacts:
  files:
    - imagedefinitions.json

在构建阶段,即使 docker login 成功,我仍然会收到错误消息。

[Container] 2022/01/05 22:17:32 Running command aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin xxxxxxxx.dkr.ecr.eu-central-1.amazonaws.com
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

[Container] 2022/01/05 22:17:32 Running command docker push $IMAGE_URI
The push refers to repository [xxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/cicd-1-app]
d92c296d04c3: Preparing
fe6c1ddaab26: Preparing
d4dfab969171: Preparing
no basic auth credentials

[Container] 2022/01/05 22:17:33 Command did not exit successfully docker push $IMAGE_URI exit status 1
[Container] 2022/01/05 22:17:33 Phase complete: POST_BUILD State: FAILED
[Container] 2022/01/05 22:17:33 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker push $IMAGE_URI. Reason: exit status 1

我该如何解决这个错误?

如何在 docker login 后运行 docker push 以避免此错误?

此致

4

0 回答 0