-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
SAM CDK -> sam build -> DockerImageCode.from_image_asset: Unable to set parent folder as the DockerContext #4059
Comments
@dunika Please see our docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-build.html#build-container-image You can do this by providing additional Metadata on the resources. |
@jfuss thanks for your reply I am aware of the As far as I can tell, I am unable to add these properties to the I have tried to do so using some of the methods outlined here, but they don't seem to work with If I manually add the
It still does not work, although it will if I remove the Manually editing the template file that is generated from As mentioned above, running This is what my
I've also mentioned above where that translation takes place. So in summary; when using the |
This is the logic we do to convert what CDK provides: https://github.com/aws/aws-sam-cli/blob/develop/samcli/lib/samlib/resource_metadata_normalizer.py#L187 Looking at the built template could give a hint here too. It will at least (should) show the paths we resolved too. The issue here is probably related to how the paths are defined in you CDK app. |
@jfuss so looking at the code responsible for the conversion:
From what I can see, EDIT: As mentioned above, my built template looks something similar to the following:
|
I thought we wrote out the Metadata too, which would have helped here.
So I thought this was supported. Re-looking at the docs and code, you are correct that the Dockerfile needs to be in the CodeUri directory. This is a restriction within all builders and not specific to Docker building. So the solution here is to place the Dockerfile inside the CodeUri directory. |
@jfuss thanks for looking into this.
Sorry, I did leave some stuff out that I didn't think was relevant. In case it helps, the full Metadata for the lambda resource looks like this:
So it does work if I remove the CDK metadata and simply make it look like this:
So it is actually possible to manually set the I think the main problem is that the current CDK implementation is a bit misleading. I would have assumed that the It seems like being able to set the What do you think? |
@i18n-tribe Thanks for your contribution! As this change will likely change the existing behaviour, we will need some deeper discussion before we can approve the contribution! |
Changes have been released with SAM CLI v1.62.0 |
Description:
I am having trouble with the following setup.
I have the following folder structure:
I need to set
/root
as theDockerContext
and/root/project/runtime/DockerFile
as the path to theDockerfile
If I create a
DockerImageCode
instance and use it to create aDockerImageFunction
like so:cdk synth >| template.yaml
will output a template and anAWS:Serverless:Function
resource with the following metadata:My
DockerFile
contains the following:To facilitate local development, I need to run
sam build
. When I do so, I get the following error:Upon inspecting
.aws-sam/build.toml
, it would seem that theDockerContext
is being set to/filesystem_path/root/project/runtime
, the folder in which theDockerFile
resides.I would have assumed that the
DockerContext
would correspond to thedirectory
parameter that gets passed intoDockerImageCode.from_image_asset
? (Which corresponds toaws: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 theDockerFile
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
The text was updated successfully, but these errors were encountered: