aws-codebuild-docker-images
aws-codebuild-docker-images copied to clipboard
Specify a buildspec override results in "no such file or directory"
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:
- Create a valid alternative build spec file EXAMPLE:
buildspec-test.yml
---
version: 0.2
phases:
build:
commands:
- echo "Hello World"
- 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
- 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)