question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Got weird error while referencing from Codebuild source = buildspec.yml

See original GitHub issue

❓ General Issue

The Question

I try to use codebuild with compose docker in docker and deploy to ECR hub.

While using buildSpec: BuildSpec.fromSourceFilename I encountered this error:

If the Project's source is NoSource, you need to provide a concrete buildSpec

xxxProject/node_modules/constructs/lib/construct.ts:407
        throw new Error(`Validation failed with the following errors:\n  ${errorList}`);
              ^
Error: Validation failed with the following errors:
  [Bob-Pipeline-dev] Stage 'Build' must have at least one action

If I use buildSpec: BuildSpec.fromObject, it works @@, no idea

Environment

  • CDK CLI Version: 1.32.1
  • OS: : OSX Catalina
  • Language: Typescript

Sample code with buildspec.yml

File structure: image

File: pipeline.ts


    const pipeline = new Pipeline(
      this,
      `Pipeline-${environment.ENV}`,
      {
        pipelineName: `pipeline-${environment.ENV}`,
      },
    )

    const sourceStage = pipeline.addStage({
      stageName: 'Source',
    })

    const buildStage = pipeline.addStage({
      stageName: 'Build',
      placement: {
        justAfter: sourceStage,
      },
    })

    const sourceOutput = new Artifact()

    const sourceAction = new GitHubSourceAction({
      actionName: `codebuild-action-${environment.ENV}`,
      owner: 'xxx,
      repo: 'xxx',
      oauthToken: cdk.SecretValue.secretsManager('tGitHubToken'),
      output: sourceOutput,
      branch: `${environment.branch}`,
      trigger: GitHubTrigger.WEBHOOK,
    })

    sourceStage.addAction(sourceAction)

const buildRole = new iam.Role(
      this,
      `IamRole-${environment.ENV}`,
      {
        assumedBy: new iam.ServicePrincipal('codebuild.amazonaws.com'),
      },
    )

    const codeBuild = new Project(
      this,
      `CodeBuildProject-${environment.ENV}`,
      {
        role: buildRole,
        environment: {
          buildImage: LinuxBuildImage.fromDockerRegistry('docker:dind')
        },
        buildSpec: BuildSpec.fromSourceFilename('./buidspec.yml')

    const buildAction = new CodeBuildAction({
      actionName: 'Build',
      input: sourceOutput,
      project: codeBuild,
    })

    buildStage.addAction(buildAction)
  }

File: buildspec.yml

version: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 12
      python: 3.8
    commands:
      - apk add --no-cache python py-pip jq
      - pip install awscli
      - echo $AWS_ACCESS_KEY_ID
      - echo $AWS_SECRET_ACCESS_KEY

  build:
    commands:
      - $(aws ecr get-login --no-include-email --region ${AWS_REGION_ECR})
      - |
        for dir in `find packages -type d -mindepth 1 -maxdepth 1 -not -name utils -not -name types -exec basename {} \;`;
        do
          docker build -f Dockerfile.${dir} -t ${REPOSITORY_URL}:${dir} .
          docker push ${REPOSITORY_URL}:${dir}
        done
  
  post_build:
    commands:
      - i=1
      - CURRENT_SERVICE_COUNT=`aws ecs list-services --region ${AWS_REGION_ECS} --cluster ${CLUSTER_NAME} | jq --raw-output ".serviceArns" | jq length`
      - CURRENT_SERVICES=`aws ecs list-services --region ${AWS_REGION_ECS} --cluster ${CLUSTER_NAME} | jq --raw-output ".serviceArns"`
      - |
      while [ "$i" -le "$CURRENT_SERVICE_COUNT" ]; do
        SERVICE=`echo $CURRENT_SERVICES | jq --raw-output ".[$i-1]"`
        aws ecs update-service --region ${AWS_REGION_ECS} --service ${SERVICE} --cluster ${CLUSTER_NAME} --force-new-deployment
        i=$(( i + 1 ))
      done

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

7reactions
skinny85commented, Apr 14, 2020

Hey @ookangzheng ,

change Project to PipelineProject in your code, and everything will work again.

Thanks, Adam

1reaction
ookangzhengcommented, Apr 17, 2020

Actually I realized that I split CDK and my code into 2 different separate Github Repositories. While I use codebuild.BuildSpec. fromSourceFilename('buildspec.yml'), I have to put buildspec.yml under my code repo.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting AWS CodeBuild
Apache Maven builds reference artifacts from the wrong repository. Issue: When you use Maven with an AWS CodeBuild-provided Java build environment, ...
Read more >
git - AWS CodePipeline, build failed & getting error as ...
The YAML file being referenced is the buildspec.yml file required by CodeBuild. More information can be found at ...
Read more >
All the AWS CodeBuild You Can Stomach in 45 Minutes
GitHub project: https://github.com/krimple/ptw-2020- codebuild -sample (slides are in the presentation-slides.pdf file).OK, let's face it.
Read more >
Fixed a Strange Error 'script.sh: 4: Login: not found' in AWS ...
Used AWS CodeBuild to build docker image and upload into elastic container registry, got an error '/codebuild/output/tmp/script.sh: 4: ...
Read more >
How-to: debug and trace problems in AWS CodeBuild
Remark: the CodeBuild policy mentioned above only needs S3 permissions if using Amazon S3 to store your logs. In case it's missing you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found