-
Notifications
You must be signed in to change notification settings - Fork 4k
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
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
@@ -96,6 +106,7 @@ export class DockerImageAsset extends Construct implements assets.IAsset { | |||
directoryName: staging.stagedPath, | |||
dockerBuildArgs: props.buildArgs, | |||
dockerBuildTarget: props.target, | |||
dockerFile: file, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think props.file
would just work here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Dockerfile
in the relevant asset constructs.Those are:
DockerImageAsset
AssetImage
Things to note
The
file
property is assumed to be a relative path inside the asset directory. While its possible to specify aDockerfile
outside 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
Dockerfile
as the default. This happens in the constructor ofDockerImageAsset
.Resolving and validating the
Dockerfile
is done as soon as possible --> in the constructor. I didn't want the resolving logic to appear twice, so theprepareContainerAsset
function simply adds the--file
option 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