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

Recursive TAR copy for docker context #313

Merged
merged 1 commit into from
Apr 14, 2017
Merged

Conversation

rnorth
Copy link
Member

@rnorth rnorth commented Mar 12, 2017

To address #285

@rnorth rnorth added this to the 1.3.0 milestone Mar 12, 2017

@Override
public int getFileMode() {
return DEFAULT_FILE_MODE | (Files.isExecutable(filePath) ? 0755 : 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make sure that we don't lose executable flags

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep - this is important. My implementation is in MountableFile - do you see any issues with it? I've not yet tested this on Windows, which is something I need to do.


performChecks(mountableFile);

assertTrue("The resolved path contains the original space", mountableFile.getResolvedPath().contains(" "));assertFalse("The resolved path does not contain an escaped space", mountableFile.getResolvedPath().contains("\\ "));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a new line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, no idea how that happened - will fix.


@Test
public void forClasspathResourceFromJar() throws Exception {
final MountableFile mountableFile = MountableFile.forClasspathResource("docker-java.properties");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use some other file to avoid the situation when they change docker-java.properties to something else? Some `META-INF/MANIFEST.MD" IMO is better

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. I wanted to make it be something that's specific and ~ only present in one/few JARs so that we can be sure that the full classpath is searched. i.e. it felt like searching for a resource that's trivially findable in any JAR might not be all that thorough. I used docker-java.properties but this is admittedly a fairly lazy choice 🙉

I guess the real non-lazy solution would be to create a synthetic JAR with some interesting resources in it for testing purposes (maybe published with jitpack or as a local system scoped dependency). WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not MANIFEST.MD? It's a part of JAR spec, and when we run the tests, our classpath will not contain such because it's not a JAR file. Sounds bulletproof for me :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a synthetic JAR so that we can be sure we're picking up JARs we're really interested in!

private final String resolvedPath = resolvePath();

@Getter(lazy = true)
private final String resolvedPathWithShellEscaping = resolvePathWithShellEscaping();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI about lazy=true:

Since resolvePathWithShellEscaping is a one-liner, you can put it here without extracting a method. Of course, we can keep a separate method, just saying that it's not a must.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extremely good point! Actually I think resolvedPathWithShellEscaping can be removed altogether - will try.

/**
* Logger to be used specifically for tracking even
*/
public class AuditLogger {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bleurgh, didn't mean to commit this - will remove.

final String results = toString.toUtf8String();

// ExternalResource.class is known to exist in a subdirectory of /org/junit so should be successfully copied in
assertTrue("The container has a file that was copied in via a recursive copy from a JAR resource", results.contains("ExternalResource.class"));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably another opportunity for the improvement described here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

This encapsulates all the complexity of generating a path that the Docker daemon is about to create a volume mount for.

This should resolve a general problem with spaces in paths, which was seen in one particular form as #263.

Use recursive copy for docker context TAR to allow contents of directories to be used in Dockerfiles and Docker Compose contexts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants