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

Code reloading for ./pants run src/docker/hw/Dockerfile through mounts #15925

Open
ptrhck opened this issue Jun 24, 2022 · 5 comments
Open

Code reloading for ./pants run src/docker/hw/Dockerfile through mounts #15925

ptrhck opened this issue Jun 24, 2022 · 5 comments
Labels
backend: Docker Docker backend-related issues enhancement

Comments

@ptrhck
Copy link

ptrhck commented Jun 24, 2022

Is your feature request related to a problem? Please describe.
Here pantsbuild/example-docker#6 it was discussed that the current implementation of running a Docker container with pants and restartable=True does not feature a great developer experience for developing/debugging purposes as it will rebuild the container on every code change.

Describe the solution you'd like
I am not sure if there are use cases for the current setup that are not covered by the following solution, so I am not certain if the current implementation should be replaced or extended. I would like ./pants run src/docker/hw/Dockerfile to do:

  • Build the image if not yet available
  • Mount the build artifact, e.g. PEX-file to the container
  • On file change, rebuild that artifact and due to the container mount it will be available in that environment without recreating the container or rebuilding the image
  • If you have changed the Dockerfile, a --build flag could be added to the ./pants run command, similiar to docker-compose up --build serviceA
  • Or if you do not wish to re-use that container set --force-recreate

So basically re-use the container.

Describe alternatives you've considered
To a certain extend, i.e. user code but not third party/user dependencies, it is possible for the AWS Lambda case as here the PEX will be unzipped: ./pants run --docker-run-args="-v ./lambda_example.py:/app/lambda_example.py" project:my_image

Additional context
The same would be benefical for running tests in a container (#13682) as you would not want the container to be rebuild for eacht test run.

@kaos
Copy link
Member

kaos commented Jun 24, 2022

@stuhood for this, I'm considering we could add a runtime_dependencies field to docker_image for stuff we want to volume mount into the container when we run the image.
The question is how to wire up restartable so that we rebuild those runtime dependencies, but doesn't actually restart the container, on changes to the runtime dependencies sources. Or is --loop more suitable in this scenario? Thoughts?

@stuhood
Copy link
Member

stuhood commented Jun 24, 2022

Having a long-lived docker process which stayed up through multiple iterations would require some mutable state passed into the engine invokes, most likely (and then torn down at the end). In that regard, --loop would probably make more sense, because there is actually already a loop running in that case (which could manage some state, and then tear it down at the end).

It's possible that a cleaner implementation though would be to add native docker support to Pants (via a rust side CommandRunner), and then let that runner manage pooling processes. It would be similar to the way that the nailgun CommandRunner pools processes. That relates to #13682.

@kaos
Copy link
Member

kaos commented Jun 24, 2022

Makes sense, thanks.
Is the CommandRunner the proper way in to have generic docker support for executing in docker in a similar manner as for remote execution?

@stuhood
Copy link
Member

stuhood commented Jun 24, 2022

That's right.

@ptrhck
Copy link
Author

ptrhck commented Jul 2, 2022

Just adding another thought to this discussion. I have another usecase that goes a little further. I am not using pants to run that container, but use it for building/publishing the image and then deploy it to localstack. Now I would like to specify to hot reload the pants artifact in the container that is now run by localstack.

@thejcannon thejcannon added the backend: Docker Docker backend-related issues label Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: Docker Docker backend-related issues enhancement
Projects
None yet
Development

No branches or pull requests

4 participants