codebuild/local-builds fails due to buildspec.yml not found (volume not mounted?)

0

I have a docker-compose with roughly this fragment:

  web-application:
    image: public.ecr.aws/codebuild/local-builds:latest
    privileged: true
    environment:
      DOCKER_HOST: unix:///var/run/docker.sock
      SOURCE: "."
      ARTIFACTS: "./tests/output"
      IMAGE_NAME: "public.ecr.aws/codebuild/amazonlinux2-x86_64-standard:corretto11"
      ... (other stuff) ...
    volumes: 
      - /var/run/docker.sock:/var/run/docker.sock 
      # tried this, also didn't work: - .:/LocalBuild/input

It fails with:

web-application-1  | agent-1  | [Container] 2025/04/06 02:55:50.824414 Waiting for DOWNLOAD_SOURCE                                                                      
web-application-1  | agent-1  | [Container] 2025/04/06 02:55:50.825131 Phase is DOWNLOAD_SOURCE                                                                         
web-application-1  | agent-1  | [Container] 2025/04/06 02:55:50.827039 CODEBUILD_SRC_DIR=/codebuild/output/src1547048547/src                                            
web-application-1  | agent-1  | [Container] 2025/04/06 02:55:50.829171 Phase complete: DOWNLOAD_SOURCE State: FAILED                                                    
web-application-1  | agent-1  | [Container] 2025/04/06 02:55:50.829245 Phase context status code: YAML_FILE_ERROR Message: YAML file does not exist                     
web-application-1  | agent-1  | [Container] 2025/04/06 02:55:50.938044 Runtime error (*clienterr.PhaseContextError: YAML file does not exist)

What causes this? The buildspec.yml is right there in the current directory.

asked a month ago98 views
1 Answer
0

The error you're encountering suggests that CodeBuild is unable to locate the buildspec.yml file in the expected directory. This issue is likely caused by the source code not being properly mounted or accessible within the CodeBuild local build container.

To resolve this, you need to ensure that your project directory (containing the buildspec.yml file) is correctly mounted into the CodeBuild local build container. In your docker-compose configuration, you should add a volume mount that maps your local project directory to the expected source directory inside the container.

Try modifying your docker-compose file to include a volume mount like this:

volumes:
  - /var/run/docker.sock:/var/run/docker.sock
  - .:/codebuild/input

This will mount your current directory (where docker-compose is run from) to /codebuild/input inside the container.

Additionally, you should set the SOURCE environment variable to point to this mounted directory:

environment:
  SOURCE: "/codebuild/input"

These changes should allow the CodeBuild local build container to access your project files, including the buildspec.yml.

If you're still encountering issues, double-check that:

  1. The buildspec.yml file is indeed in the root of your project directory.
  2. The file permissions allow the container to read the buildspec.yml file.
  3. There are no typos in the filename (it should be exactly buildspec.yml).

Remember that when using CodeBuild local builds, you need to replicate the directory structure and file locations that CodeBuild expects in a normal cloud-based build environment.
Sources
'Publish Docker image to an Amazon ECR image repository' sample for CodeBuild - AWS CodeBuild
Getting started with CodeBuild - AWS CodeBuild

profile picture
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions