-
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
fix(cdk-assets): context path not honored by Docker asset build #6957
Conversation
0283d4b
to
ca318e3
Compare
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 |
ca318e3
to
3d0247b
Compare
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Prior v1.29.0, the context passed to the docker build command was always the current working directory. In v1.29.0, this was changed to be the directory the user passed when instantiating the asset. However, docker doesn't respect the context passed to the build command when the `--file` argument is also passed. This broke assets for users passing the `file` prop when constructing a `DockerImageAsset`. This is fixed by changing the current working directory of the `docker build` command and passing that context as '.'. Then docker uses the current working directory as the context and correctly finds the image definition file from the `file` prop. An existing integration test in the framework covers this case, but does not fail unless the stack is deployed fresh since the asset isn't rebuilt when the hash is not changed. Fix: aws#6954 aws#6814
3d0247b
to
70f984e
Compare
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
]; | ||
await this.execute(buildCommand); | ||
await this.execute(buildCommand, { cwd: options.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.
lgtm fwiw. The below alternative patch also worked for me if for some reason the reviewers wanted to avoid setting cwd (I don't know why that would be an issue):
--- cdk-assets/lib/private/handlers/container-images.js.orig 2020-03-24 06:03:56.670862836 +0000
+++ cdk-assets/lib/private/handlers/container-images.js 2020-03-24 05:58:01.971071483 +0000
@@ -51,7 +51,7 @@
tag: this.localTagName,
buildArgs: source.dockerBuildArgs,
target: source.dockerBuildTarget,
- file: source.dockerFile,
+ file: path.resolve(fullPath, source.dockerFile),
});
}
}
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.
Fix the commit title to all lower case. For fixes, the commit title should summarize the issue it is fixing.
Remember to use mergify's '##Commit Message' in the description so mergify picks up the updated title.
An existing integration test in the framework covers this case,
but does not fail unless the stack is deployed fresh since the asset isn't
rebuilt when the hash is not changed.
Can we correct this test, or add a better one?
DockerImageAsset
DockerImageAsset
done
yep, it's currently failing right now, but I'll address it's flakiness in a follow-up PR once we've mitigated the p0 |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
@MrArnoldPalmer wrote:
Thats not accurate. To my understanding, in both in docker build --tag 942768376061.dkr.ecr.eu-central-1.amazonaws.com/aws-cdk/assets:xxx --target production --file cdk.out/asset.xxx/services/admin/Dockerfile cdk.out/asset.xxx The context here is cdk.out/asset.xxx, which is the asset directory, relative to the cdk working directory (the app directory). in docker build --tag cdkasset-xxx --file services/backend/Dockerfile /Volumes/Projects/whatever/build/cdk/cdk.out/asset.xxx The context here is /Volumes/Projects/whatever/build/cdk/cdk.out/asset.xxx, which is the same thing, except now its absolute. This is ok, the problem is that in From https://docs.docker.com/engine/reference/commandline/build/
this just doesn't seem to be true. Docker always looks up the So the fix is basically to always have the context directory be the current working directory when running |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Prior v1.29.0, the context passed to the docker build command was always the current working directory. In v1.29.0, this was changed to be the directory the user passed when instantiating the asset. However, docker doesn't respect the context passed to the build command when the `--file` argument is also passed. This broke assets for users passing the `file` prop when constructing a `DockerImageAsset`. This is fixed by changing the current working directory of the `docker build` command and passing that context as `.`. Then docker uses the current working directory as the context and correctly finds the image definition file from the `file` prop. An existing integration test in the framework covers this case, but does not fail unless the stack is deployed fresh since the asset isn't rebuilt when the hash is not changed. Fix: #6954 #6814
Commit Message
fix(cdk-assets): context path not honored by Docker asset build (#6957)
Prior v1.29.0, the context passed to the docker build command was always
the current working directory. In v1.29.0, this was changed to be the
directory the user passed when instantiating the asset. However, docker
doesn't respect the context passed to the build command when the
--file
argument is also passed. This broke assets for users passingthe
file
prop when constructing aDockerImageAsset
.This is fixed by changing the current working directory of the
docker build
command and passing that context as
.
. Then docker uses the current workingdirectory as the context and correctly finds the image definition file from the
file
prop. An existing integration test in the framework covers this case,but does not fail unless the stack is deployed fresh since the asset isn't
rebuilt when the hash is not changed.
Fix: #6954 #6814
End Commit Message
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license