-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Add support for pointing to tarball contexts in the 'build' parameter. #1209
Comments
It seems reasonable to me that |
Seems like this change belongs in docker-py. |
@aanand I think it belongs in both compose and docker-py, actually. It would certainly be possible to just change docker-py so that it automatically detects when the context being passed is already compressed (instead of relying on the combination-of-parameters logic that it uses today). My grip with this approach would be that it involves moving validation and conditional behavior too far down to the library level. As a principle there's always value in keeping validation and detection of user intent as close as possible to surface code and not deep in libraries. Libraries should provide a set of tailored, focused operations that each do one thing with as little conditional logic as possible, specially with regard to the input parameters (they certainly need a lot of conditional logic to deal with failures on the underlying resource level and such). That arrangement makes it easier both to fail early and to optimize for efficiency where relevant. So, if docker-py is changed the right way it would not solve this particular problem, because the right way would be to have docker-py offer a more fine grained interface for its So, either both compose and docker-py could be changed in tandem (the 'right way', probably unrealistic, I don't know) or compose could be changed first, to call docker-py's build method with the right combination of arguments when the As it's currently implemented, compose implicitly assumes the value of In services.py: def build(self, no_cache=False):
log.info('Building %s...' % self.name)
"""
- Here it should be determined what kind of resource self.options['build'] points to.
- If it's a tarball, the call to self.client.build should look something like:
build_output = self.client.build(
fileobj=open(self.options['build'], 'rb'),
custom_context=True,
encoding='gzip',
tag=self.full_name,
stream=True,
rm=True,
nocache=no_cache,
)
- If it's a directory, use the already existing call:
"""
build_output = self.client.build(
self.options['build'],
tag=self.full_name,
stream=True,
rm=True,
nocache=no_cache,
) Then, when docker-py is improved to move away from the combination-of-parameters approach, the implementation in |
OK, I'd mistakenly believed the docker client would smartly determine whether the argument passed to it was a directory or a tarball, but it looks like they go different routes (stdin for tarball or single Dockerfile vs. argument for directory). In that case, I think it's fine for that logic to live in Compose: we should check whether the path passed to |
@aanand If build command could accept tarball as a regular arg, then it would benefit other compose tools too. When I look in the source code of We just have to peek the input file, and check if Existing tarball handling (the stdin): https://github.com/docker/docker/blob/master/api/client/build.go#L74-90 Where to add new tarball handling (as regular argument): https://github.com/docker/docker/blob/master/api/client/build.go#L94-95 Where the https://github.com/docker/docker/blob/master/api/client/build.go#L206-214 |
Oh right… I also seem to have forgotten that compose actually doesn't use the CLI client, but directly calls the API instead. (where in the API, tarball is always sent across the same way). |
Would it be ok to add backports.lzma as a requirement? Python2's tarfile module doesn't support lzma compression natively. Since the docker daemon accepts xz I think compose should support it too. |
In two different projects, we have a custom build scripts to achieve a couple of things... In one project we use I was going to open a new ticket to discuss support for pre and post build scripts, so that you could alter the build directory as required before and after a build. But I thought I'd chime in here instead... having the ability to point to a tarball would suffice I suppose. The ability to run a pre-build script would be fantastic to generate the tarball, but you could get around this by a custom script that generates a tarball and then executes |
@smebberson I have a working implementation of this feature in the PR referenced above. My scenario is more or less the same as yours. We have a staging directory with a bunch of maven generated tar archives with Dockerfiles inside them. When someone finishes a project build, the archive is shipped to this staging area. New uploads are detected by an |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Please don't close Would love to be able to do something similar to this: tar -czf - ./srcDirOne ./srcDirTwo ./srcDirThree \
| docker build -t acme/widget -f widget/Dockerfile - |
This issue has been automatically marked as not stale anymore due to the recent activity. |
Is this feature getting anywhere? It looks to me that docker-py already supports building from tar:
|
Relatively easy implementation (unless I'm missing something). Submitted PR. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
can #7283 be merged? this would be very useful. |
This issue has been automatically marked as not stale anymore due to the recent activity. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Looks like a small and easy PR, can it be merged? |
This issue has been automatically marked as not stale anymore due to the recent activity. |
Looking for the same feature. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it had not recent activity during the stale period. |
Since the docker client used by compose (docker-py) supports receiving externally generated tarballs as a parameter for its build() method, this alternative should be available in the project configuration file. i.e.:
The contents within the compressed file should pass the same level of validation as the currently supported directory paths (for example, 'there must be a Dockerfile at the root inside the tar archive'). Aside from that, the general idea is that the archive is some kind of externally validated artifact, auto-generated by a continuous integration stack, so there should be no need for parsing .dockerignore.
If this sounds like a good idea I can start working on a PR (I already have an working prototype).
The text was updated successfully, but these errors were encountered: