Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify a buildspec override results in "no such file or directory" #585

Open
scottschreckengaust opened this issue Nov 29, 2022 · 0 comments
Labels
CodeBuild-local Tag to track issues and PRs for CodeBuild local Docker image

Comments

@scottschreckengaust
Copy link

Describe the bug
Attempting to use the -b option to specify an override buildspec path results in "no such file or directory". This is even when the -m switch is used. When I changed https://github.com/aws/aws-codebuild-docker-images/blob/master/local_builds/codebuild_build.sh#L134 to docker_command+=" -e \"BUILDSPEC=$buildspec\"" it found the specified path.

To Reproduce
Steps to reproduce the behavior:

  1. Create a valid alternative build spec file EXAMPLE: buildspec-test.yml
---
version: 0.2
phases:
  build:
    commands:
      - echo "Hello World"
  1. Run
 ./codebuild_build.sh -m -b buildspec-test.yml \
    -i public.ecr.aws/codebuild/amazonlinux2-x86_64-standard:4.0 \
    -a ./build \
    -s . \
    -l public.ecr.aws/codebuild/local-builds
  1. See error:
Build Command:

docker run -it -v /var/run/docker.sock:/var/run/docker.sock -e "IMAGE_NAME=public.ecr.aws/codebuild/amazonlinux2-x86_64-standard:4.0" -e "ARTIFACTS=/tmp/test/build" -e "SOURCE=/tmp/test/." -e "BUILDSPEC=/tmp/test/buildspec-test.yml" -e "LOCAL_AGENT_IMAGE_NAME=public.ecr.aws/codebuild/local-builds" -e "MOUNT_SOURCE_DIRECTORY=TRUE" -e "INITIATOR=user" public.ecr.aws/codebuild/local-builds

Removing agent-resources_build_1 ... done
Removing agent-resources_agent_1 ... done
Removing network agent-resources_default
Removing volume agent-resources_source_volume
Removing volume agent-resources_user_volume
Creating network "agent-resources_default" with the default driver
Creating volume "agent-resources_source_volume" with local driver
Creating volume "agent-resources_user_volume" with local driver
Creating agent-resources_agent_1 ... done
Creating agent-resources_build_1 ... done
Attaching to agent-resources_agent_1, agent-resources_build_1
agent_1  | [Container] 2022/11/24 16:03:59 going inside waitForAgent
agent_1  | [Container] 2022/11/24 16:03:59 Waiting for agent ping
agent_1  | [Container] 2022/11/24 16:03:59 Waiting for DOWNLOAD_SOURCE
agent_1  | [Container] 2022/11/24 16:03:59 Phase is DOWNLOAD_SOURCE
agent_1  | [Container] 2022/11/24 16:03:59 finished waitForAgent
agent_1  | [Container] 2022/11/24 16:03:59 inside CopySrc
agent_1  | [Container] 2022/11/24 16:03:59 CODEBUILD_SRC_DIR=/codebuild/output/src579579692/src
agent_1  | [Container] 2022/11/24 16:03:59 finished CopySrc
agent_1  | [Container] 2022/11/24 16:03:59 Phase complete: DOWNLOAD_SOURCE State: FAILED
agent_1  | [Container] 2022/11/24 16:03:59 Phase context status code: YAML_FILE_ERROR Message: stat /tmp/test/buildspec-test.yml: no such file or directory
agent_1  | [Container] 2022/11/24 16:03:59 Runtime error (*clienterr.PhaseContextError: stat /tmp/test/buildspec-test.yml: no such file or directory)
agent-resources_build_1 exited with code 11
Aborting on container exit...

Expected behavior

Build Command:

docker run -it -v /var/run/docker.sock:/var/run/docker.sock -e "IMAGE_NAME=public.ecr.aws/codebuild/amazonlinux2-x86_64-standard:4.0" -e "ARTIFACTS=/tmp/test/build" -e "SOURCE=/tmp/test/." -e "BUILDSPEC=buildspec-test.yml" -e "LOCAL_AGENT_IMAGE_NAME=public.ecr.aws/codebuild/local-builds" -e "MOUNT_SOURCE_DIRECTORY=TRUE" -e "INITIATOR=user" public.ecr.aws/codebuild/local-builds

Removing agent-resources_build_1 ... done
Removing agent-resources_agent_1 ... done
Removing network agent-resources_default
Removing volume agent-resources_source_volume
Removing volume agent-resources_user_volume
Creating network "agent-resources_default" with the default driver
Creating volume "agent-resources_source_volume" with local driver
Creating volume "agent-resources_user_volume" with local driver
Creating agent-resources_agent_1 ... done
Creating agent-resources_build_1 ... done
Attaching to agent-resources_agent_1, agent-resources_build_1
agent_1  | [Container] 2022/11/29 04:27:30 going inside waitForAgent
agent_1  | [Container] 2022/11/29 04:27:30 Waiting for agent ping
agent_1  | [Container] 2022/11/29 04:27:30 Waiting for DOWNLOAD_SOURCE
agent_1  | [Container] 2022/11/29 04:27:31 Phase is DOWNLOAD_SOURCE
agent_1  | [Container] 2022/11/29 04:27:31 finished waitForAgent
agent_1  | [Container] 2022/11/29 04:27:31 inside CopySrc
agent_1  | [Container] 2022/11/29 04:27:31 CODEBUILD_SRC_DIR=/codebuild/output/src366791390/src
agent_1  | [Container] 2022/11/29 04:27:31 finished CopySrc
agent_1  | [Container] 2022/11/29 04:27:31 YAML location is /codebuild/output/srcDownload/src/buildspec-alternative.yml
agent_1  | [Container] 2022/11/29 04:27:31 Processing environment variables
agent_1  | [Container] 2022/11/29 04:27:31 Moving to directory /codebuild/output/src366791390/src
agent_1  | [Container] 2022/11/29 04:27:31 Registering with agent
agent_1  | [Container] 2022/11/29 04:27:31 Phases found in YAML: 1
agent_1  | [Container] 2022/11/29 04:27:31  BUILD: 1 commands
agent_1  | [Container] 2022/11/29 04:27:31 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
agent_1  | [Container] 2022/11/29 04:27:31 Phase context status code:  Message:
agent_1  | [Container] 2022/11/29 04:27:31 Entering execCommands
agent_1  | [Container] 2022/11/29 04:27:31 Entering phase INSTALL
agent_1  | [Container] 2022/11/29 04:27:31 Phase complete: INSTALL State: SUCCEEDED
agent_1  | [Container] 2022/11/29 04:27:31 Phase context status code:  Message:
agent_1  | [Container] 2022/11/29 04:27:31 Entering phase PRE_BUILD
agent_1  | [Container] 2022/11/29 04:27:31 Phase complete: PRE_BUILD State: SUCCEEDED
agent_1  | [Container] 2022/11/29 04:27:31 Phase context status code:  Message:
agent_1  | [Container] 2022/11/29 04:27:31 Entering phase BUILD
agent_1  | [Container] 2022/11/29 04:27:31 Running command echo "Hello World"
agent_1  | Hello World
agent_1  |
agent_1  | [Container] 2022/11/29 04:27:31 Phase complete: BUILD State: SUCCEEDED
agent_1  | [Container] 2022/11/29 04:27:31 Phase context status code:  Message:
agent_1  | [Container] 2022/11/29 04:27:31 Entering phase POST_BUILD
agent_1  | [Container] 2022/11/29 04:27:31 Phase complete: POST_BUILD State: SUCCEEDED
agent_1  | [Container] 2022/11/29 04:27:31 Phase context status code:  Message:
agent-resources_agent_1 exited with code 0
Stopping agent-resources_build_1 ... done
Aborting on container exit...

Logs
If applicable, add log output to help explain your problem.

Platform (please complete the following information):

  • OS: macOS x86 [e.g. Linux x86, Linux ARM, Mac x86, Mac M1, Windows]

Additional context
Notice that the BUILDSPEC environmental variable is relative to the source (not the volume)

@subinataws subinataws added the CodeBuild-local Tag to track issues and PRs for CodeBuild local Docker image label Mar 16, 2023
sha256 added a commit to sha256/aws-codebuild-docker-images that referenced this issue May 14, 2023
The buildspec override file location should be relative to CODEBUILD_SRC_DIR. Currently it's passing an absolute path based on the host.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CodeBuild-local Tag to track issues and PRs for CodeBuild local Docker image
Projects
None yet
Development

No branches or pull requests

2 participants