flapdoodle-oss / de.flapdoodle.embed.mongo

...will provide a platform neutral way for running mongodb in unittests.
Apache License 2.0
907 stars 161 forks source link

Could not input stream with proxy optional #480

Closed zakaria-hajjaji closed 1 year ago

zakaria-hajjaji commented 1 year ago

Hi when a run mvn integration-test the download pass successfully But in the phase of mvn release:prepare it broks I working of gitlab CI for running jobs

michaelmosmann commented 1 year ago

@zakaria-hajjaji do you have any error message, stack trace?

zakaria-hajjaji commented 1 year ago

yeah i deploy a container on gke this is the error Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'investUserSettingsFilter' defined in URL [jar:file:/usr/share/myservice/iac.jar!/BOOT- .......(some long errors) nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [de.flapdoodle.embed.mongo.MongodExecutable]: Factory method 'embeddedMongoServer' threw exception; nested exception is de.flapdoodle.embed.process.exceptions.DistributionException: java.io.IOException: Could not open inputStream for https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.5.5.tgz with proxy Optional.empty

zakaria-hajjaji commented 1 year ago

for info when i run mvn test and integration-test it pass

michaelmosmann commented 1 year ago

@zakaria-hajjaji .. the main issue: i guess that the deployed container can not access https://fastdl.mongodb.org (i guess there is a firewall rule for that) so the download fails.. a second issue: i guess you are using a older version of this library .. there are spring integrations for spring 2.5.x, 2.6.x, 2.7.x, 3.0.x and 3.1.x .. these do not solve the firewall issue, but uses the latest version of this library.

https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/tree/spring-2.5.x https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring

zakaria-hajjaji commented 1 year ago

is there any way to like bypass the firewall or setting a proxy cause i have some proxy things in the project

michaelmosmann commented 1 year ago

@zakaria-hajjaji an important function of an firewall is: you can not bypass them.. if a proxy can provide access to the internet you must use this proxy on the CI system..

Here you can find some information how to configure a proxy: https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/blob/main/docs/Howto.md#customize-proxy-for-download .. and how to apply this customization with spring: https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/blob/main/HowTo.md#customize-mongod

zakaria-hajjaji commented 1 year ago

ahh yes i mean by setting a proxy,okay where exactly i can place the proxy custumize file in the project and which name i willl give

michaelmosmann commented 1 year ago

@zakaria-hajjaji is your project on a public git repo? which spring version do you use?

zakaria-hajjaji commented 1 year ago

No is not public springboot 2.7.9 and java 17

michaelmosmann commented 1 year ago

@zakaria-hajjaji put this:

@Bean
  BeanPostProcessor customizeMongod() {
    return TypedBeanPostProcessor.applyBeforeInitialization(Mongod.class, src -> {
      return Mongod.builder()
        .from(src)
        .downloadPackage(DownloadPackage.withDefaults()
           .withProxyFactory(new HttpProxyFactory("server", 1234)))
        .build();
    });
  }

beside your other bean definitions.. and replace servername and port.

zakaria-hajjaji commented 1 year ago

i'll try it now

zakaria-hajjaji commented 1 year ago

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedMongoServer' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Invocation of init method failed; nested exception is java.io.IOException: Cannot run program "/tmp/extract-d4ea2568-e1c9-4a28-a4e5-0bef11220a46extractmongod": error=2, No such file or directory

zakaria-hajjaji commented 1 year ago

for info the issue is fixed by adding system.setproperty(proxyhost,....) and port

zakaria-hajjaji commented 1 year ago

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedMongoServer' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Invocation of init method failed; nested exception is java.io.IOException: Cannot run program "/tmp/extract-d4ea2568-e1c9-4a28-a4e5-0bef11220a46extractmongod": error=2, No such file or directory

FOR THIS delete the alpine form based image

michaelmosmann commented 1 year ago

@zakaria-hajjaji you should use this newer integration: https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/tree/spring-2.7.x .. which should give a better error message bc i suspect that this will work on an alpine based image.

zakaria-hajjaji commented 1 year ago

okey thank you