为什么我的AWS CodeBuild命令没有运行?

时间:2017-02-16 22:20:00

标签: docker aws-codebuild

我正在尝试将AWS CodeBuild用于我的项目。我的版本在aws/codebuild/docker:1.12.1图片上运行。这是我的buildspec.yml,取自AWS Docker Sample

version: 0.1

phases:
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - $(aws ecr get-login --region $AWS_DEFAULT_REGION)
  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...          
      - docker build -t $IMAGE_REPO_NAME .
  post-build:
    commands:
      - echo Build completed on `date`
      - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
      - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG

所有环境变量都在构建配置中定义。但这是我的CodeBuild日志输出:

[Container] 2017/02/16 22:04:24 Waiting for agent
[Container] 2017/02/16 22:04:33 Phase is DOWNLOAD_SOURCE
[Container] 2017/02/16 22:04:34 Source is located at /tmp/src733484785/src
[Container] 2017/02/16 22:04:34 YAML location is /tmp/src733484785/src/buildspec.yml
[Container] 2017/02/16 22:04:34 Registering with agent
[Container] 2017/02/16 22:04:34 Phases found in YAML: 3
[Container] 2017/02/16 22:04:34 PRE_BUILD: 2 commands
[Container] 2017/02/16 22:04:34 BUILD: 3 commands
[Container] 2017/02/16 22:04:34 POST-BUILD: 3 commands
[Container] 2017/02/16 22:04:34 Phase complete: DOWNLOAD_SOURCE Success: true
[Container] 2017/02/16 22:04:34 Phase context status code: Message: 
[Container] 2017/02/16 22:04:34 Processing plaintext environment variables
[Container] 2017/02/16 22:04:34 Processing build-level environment variables
[Container] 2017/02/16 22:57:53 {"AWS_DEFAULT_REGION":"<censored>","AWS_ACCOUNT_ID":"<censored>","IMAGE_TAG":"<censored>","IMAGE_REPO_NAME":"<censored>"}
[Container] 2017/02/16 22:57:53 AWS_DEFAULT_REGION = <censored>
[Container] 2017/02/16 22:57:53 AWS_ACCOUNT_ID = <censored>
[Container] 2017/02/16 22:57:53 IMAGE_TAG = <censored>
[Container] 2017/02/16 22:57:53 IMAGE_REPO_NAME = <censored>
[Container] 2017/02/16 22:04:34 Processing builtin environment variables
[Container] 2017/02/16 22:04:34 Moving to directory /tmp/src733484785/src
[Container] 2017/02/16 22:04:34 Preparing to copy artifacts
[Container] 2017/02/16 22:04:34 No artifact files specified

CodeBuild会看到我的命令,但它不会运行它们!构建标记为成功。有谁知道我在这里做错了什么?

更新:我需要将post-build更改为post_build。构建现在拉取maven图像来构建jar,然后docker构建图像。这样,我的jar不包含源代码,并且图像不包含maven和jdk。这是我的工作buildspec.yml

version: 0.1

phases:
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - $(aws ecr get-login --region $AWS_DEFAULT_REGION)
      - echo Pulling maven image...
      - docker pull maven:3.3-jdk-8
  build:
    commands:
      - echo Build started on `date`
      - echo Building jar...
      - docker run -i --rm -w /opt/maven -v $PWD:/opt/maven -v $HOME/.m2:/root/.m2 maven:3.3-jdk-8 mvn clean install
      - echo Building Docker Image...
      - docker build -t $IMAGE_REPO_NAME .
      - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing Docker image...
      - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG

0 个答案:

没有答案