feat(ecr-assets): custom docker files#5652
Conversation
|
@eladb Question: I've changed the way we invoke |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
eladb
left a comment
There was a problem hiding this comment.
Looks great. Minor comments.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
Thank you for contributing! Your pull request is now being automatically merged. |
| directoryName: staging.stagedPath, | ||
| dockerBuildArgs: props.buildArgs, | ||
| dockerBuildTarget: props.target, | ||
| dockerFile: file, |
There was a problem hiding this comment.
This needs to be a relative path since the docker directory is copied into cloud assembly ("staging"). Since we resolve dir above, it results in an absolute path.
There was a problem hiding this comment.
I think props.file would just work here
There was a problem hiding this comment.
This was actually done intentionally. The idea was to do the validation as soon as possible (like the other validations). To validate - I have to join the directory and the file. If I were to pass only the relative path here, it means the cli would have to join again - resulting in duplicate logic. I think its also inline with the notion of letting the framework do the work and keeping the cli as simple as possible.
I think what I missed though is that the final command would look something like:
docker build --file ${props.directory}/${props.file} /generated/path/to/cloudassemby/....Which means the command relies on resources outside the cloudassemly. Is this what you meant by:
needs to be a relative path since the docker directory is copied into cloud assembly ?
There was a problem hiding this comment.
Ok that the validation is done early, but the value passed to "docker build" needs to be relative to the docker directory.
There was a problem hiding this comment.
Actually the value can't be relative because docker will fail - it doesn't assume you pass a relative path to the context when you use --file.
The path passed to docker build --file should be absolute, it just needs to be derived from the asset path inside the cloud assembly. What has to be relative is the property passed to the asset, since otherwise, the manifest in the cloud-assembly will contain an absolute path of the machine the assembly was created on.
|
|
||
| // THEN | ||
| const assetMetadata = stack.node.metadata.find(({ type }) => type === ASSET_METADATA); | ||
| test.deepEqual(assetMetadata && assetMetadata.data.file, path.join(directoryPath, 'Dockerfile.Custom')); |
There was a problem hiding this comment.
This assertion should have just been:
| test.deepEqual(assetMetadata && assetMetadata.data.file, path.join(directoryPath, 'Dockerfile.Custom')); | |
| test.deepEqual(assetMetadata && assetMetadata.data.file, 'Dockerfile.Custom'); |
|
Has anyone been able to use custom dockerfiles since the 1.20 release ? But I am getting this error I have another php image that I build from a |
|
Hi @nalhabash We indeed had an issue regarding this feature in Regarding your specific issue, the error you are getting means that the If possible, can you share your project structure and the contents of your Thanks |
|
Hi ! |
|
Awesome, glad all is well 👍 |
Added ability to provide a custom
Dockerfilein the relevant asset constructs.Those are:
DockerImageAssetAssetImageThings to note
The
fileproperty is assumed to be a relative path inside the asset directory. While its possible to specify aDockerfileoutside the context path, in our case, we want to keep things as self-contained as possible inside the asset directory. If a different need arrises, we will address it then.If the property is not defined, we use
Dockerfileas the default. This happens in the constructor ofDockerImageAsset.Resolving and validating the
Dockerfileis done as soon as possible --> in the constructor. I didn't want the resolving logic to appear twice, so theprepareContainerAssetfunction simply adds the--fileoption to the docker command as is (if given).Prior to this change, users had to have a
Dockerfile(hardcoded) in their asset directory.Closes #3829
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license