SAM CDK -> sam build -> DockerImageCode.from_image_asset: Unable to set parent folder as the DockerContext
See original GitHub issueDescription:
I am having trouble with the following setup.
I have the following folder structure:
/root
.Pipfile
/shared_dependencies
/project
/runtime
DockerFile
I need to set /root
as the DockerContext
and /root/project/runtime/DockerFile
as the path to the Dockerfile
If I create a DockerImageCode
instance and use it to create a DockerImageFunction
like so:
code = DockerImageCode.from_image_asset(
directory="/filesystem_path/root",
file="/project/runtime/DockerFile",
)
DockerImageFunction(
code=code,
)
cdk synth >| template.yaml
will output a template and an AWS:Serverless:Function
resource with the following metadata:
Metadata:
aws:asset:path: /filesystem_path/root
aws:asset:dockerfile-path: /project/runtime/DockerFile
My DockerFile
contains the following:
COPY Pipfile .
To facilitate local development, I need to run sam build
. When I do so, I get the following error:
COPY failed: file not found in build context or excluded by .dockerignore:
stat Pipfile: file does not exist
Upon inspecting .aws-sam/build.toml
, it would seem that the DockerContext
is being set to /filesystem_path/root/project/runtime
, the folder in which the DockerFile
resides.
I would have assumed that the DockerContext
would correspond to the directory
parameter that gets passed into DockerImageCode.from_image_asset
? (Which corresponds to aws:asset:path
in the template)
As far as I can tell, there is no way of setting the DockerContext
to any folder that is not the folder in which the DockerFile
resides.
This pull request added the mapping logic for cdk image asset metadata -> sam build params
.
Looking at the changes in this file, it would seem that the DockerContext
will always be equal to the folder in which the DockerFile resides.
Is there a way of setting the DockerContext
that I am not aware of? Or is it currently impossible?
I came across this issue which is now closed but does not offer a satisfactory resolution to this problem.
Additional environment details:
OS: Mac
sam --version -> SAM CLI, version 1.53.0
Issue Analytics
- State:
- Created a year ago
- Comments:9 (6 by maintainers)
Changes have been released with SAM CLI v1.62.0
@jfuss I’ve submitted a PR to address this issue.
The code in the PR makes
sam-cli
behaviour consistent with how thecdk
is working.