2017-02-16 146 views
2

我正在嘗試爲我的項目使用AWS CodeBuild。我的版本在aws/codebuild/docker:1.12.1圖片上運行。這是我的buildspec.yml,這是從AWS Docker Sample爲什麼我的AWS CodeBuild命令不能運行?

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

我不知道我做了什麼,但它開始工作。有誰知道薄片的來源可能是什麼?你找到了你爲什麼得到這個工作的 – zalpha314

+0

?我想我有同樣的問題 – cdimitroulas

+0

@cdimitroulas,不,但我認爲它必須與列表的縮進和間距。 YAML對此非常挑剔。 – zalpha314

回答

相關問題