Skip to content
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

(cdk): Ability to create a Docker volume #20601

Open
2 tasks
SamStephens opened this issue Jun 3, 2022 · 0 comments · May be fixed by #32832
Open
2 tasks

(cdk): Ability to create a Docker volume #20601

SamStephens opened this issue Jun 3, 2022 · 0 comments · May be fixed by #32832
Labels
@aws-cdk/custom-resources Related to AWS CDK Custom Resources effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@SamStephens
Copy link
Contributor

SamStephens commented Jun 3, 2022

Describe the feature

The CDK currently provides DockerVolume, provides us the ability to create a bind mount, exposing a file or directory on the host to Docker, in my scenario to a Docker based Lamdba build.

However Docker also provides volumes, which are completely managed by Docker, and independent of the host OS and file system. For any build scenario where there's value in caching assets, a Docker volume is going to be a better, more robust, and more platform independent option than a bind mount.

Use Case

I'm using Gradle to manage builds for my Java Lambdas. I'd like to be able to provide a persistent volume to the Docker based build as /root/.gradle that each build can cache information to, for use by future builds.

I've tried doing this using DockerVolume, which as I understand Docker terminology actually provides us the ability to create a bind mount. The problem I face is the Java 11 bundling image, like most Docker images, runs as root.

So if I try using a bind mount the files written back to the host operating system are owned by root. Having files written to user home directories that are owned by root is a surprising and bad side effect of running a cdk build. And having a build write files to subdirectories of /root also seems surprising and wrong.

Being able to use a Docker named volume is the perfect solution to this caching issue, and any other scenario where caching might be wanted across multiple Docker based builds.

Proposed Solution

It's kind of messy, because the name DockerVolume is already being used for a Bind Mount. Otherwise I'd suggest a new class called DockerVolume.

However as DockerVolume is already defined, I think the cleanest thing would be for the DockerVolume constructor to provide a new parameter, volume_name. host_path and volume_name would be mutually exclusive. If you provide host_path, you get the existing behavior where you get a bind mount. If you provide volume_name, you get a named volume mounted, using the Docker default options.

Docker volumes have a lot of options this suggestion doesn't expose. However once this is implemented, it would be an simple extension to then allow setting of those options, possibly by exposing a volume_options parameter on the DockerVolume constructor.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.26.0

Environment details (OS name and version, etc.)

Ubuntu 20.04 on WSL 2 within Windows 10.0.19044

@SamStephens SamStephens added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jun 3, 2022
@github-actions github-actions bot added the @aws-cdk/custom-resources Related to AWS CDK Custom Resources label Jun 3, 2022
@rix0rrr rix0rrr added effort/medium Medium work item – several days of effort p2 and removed needs-triage This issue or PR still needs to be triaged. labels Jul 7, 2022
@rix0rrr rix0rrr removed their assignment Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/custom-resources Related to AWS CDK Custom Resources effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants