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

withFileFromClasspath does not work for resources within a jar #213

Closed
hcoles opened this issue Aug 23, 2016 · 1 comment
Closed

withFileFromClasspath does not work for resources within a jar #213

hcoles opened this issue Aug 23, 2016 · 1 comment
Milestone

Comments

@hcoles
Copy link

hcoles commented Aug 23, 2016

As per the title ClasspathTrait.withFileFromClassPath fails with

Can't get size from blah blah blah path/SKYNET-0.7-SNAPSHOT.jar!/com/example/Dockerfile

When it is given a classpath resource within a jar.

For the moment I'm working round this with a transferable that copies the resource to a byte array

  static Transferable fromClasspath(final String resourcePath) {
    URL resource = ClasspathTrait.class.getClassLoader()
        .getResource(resourcePath);

    try (InputStream stream = resource.openStream()) {
      byte[] bytes = IOUtils.toByteArray(stream);

      return new Transferable() {
        @Override
        public long getSize() {
          return bytes.length;
        }

        @Override
        public void transferTo(OutputStream outputStream) {
          try {
            IOUtils.write(bytes, outputStream);
          } catch (IOException e) {
            throw new RuntimeException(
                "Can't transfer resource " + resourcePath, e);
          }
        }
      };
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  };

But it would be preferable for the DSL to support this.

@rnorth
Copy link
Member

rnorth commented Nov 20, 2016

Fix released in 1.1.7 - sorry for the delay in getting this out.

The mounting of classpath resources from JAR files entails copying them out to a temporary folder, from where docker is able to mount it. This is used for loading default MySQL and MariaDB configurations now, so hopefully functions for your use case as well. There's no API change - just use withClasspathResourceMapping on any subclass of GenericContainer.

@rnorth rnorth closed this as completed Nov 20, 2016
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

No branches or pull requests

2 participants