question

Tri avatar image
Tri asked Erick Ramirez edited

week6: how to test the java backend in the docker image?

Hi,

The getting-started-with-astra-java code is working OK. Astra connection info has been initialized correctly in SessionManager.java and the Java code is tested OK with mvn spring-boot:run and Swagger on http://localhost:5000/.

The ./target/getting-started-with-astra-java-1.0.0-SNAPSHOT.jar has been successfully built by mvn clean install

After working out the issue building the docker image of getting-started-with-astra-java as mentioned in the post week6 mvn dockerfile:build failed

I'd like to test that the java backend (using Astra) is working Ok.

$ docker run astra-backend:my-image -p 5000:5000

The console output seems to indicate that the Java backend is running

___        _
  / _ \      | |
 / /_\ \ ___ | |_  _ __   __ _
 |  _  |/ __|| __|| '__| / _` |
 | | | |\__ \| |_ | |   | (_| |
 \_| |_/|___/ \__||_|    \__,_|

 Getting Started with Astra


03:54:40.565 INFO  com.datastax.astra.GettingStartedWithAstra    : Starting GettingStartedWithAstra v1.0.0-SNAPSHOT on 559b69bdfe58 with PID 1 (/app.jar started by root in /)
03:54:40.572 INFO  com.datastax.astra.GettingStartedWithAstra    : No active profile set, falling back to default profiles: default
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (jar:file:/app.jar!/BOOT-INF/lib/groovy-2.5.7-indy.jar!/) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
03:54:43.594 INFO  com.datastax.astra.controller.CorsController  : Allowing CORS
03:54:44.793 INFO  com.datastax.astra.GettingStartedWithAstra    : Started GettingStartedWithAstra in 5.057 seconds (JVM running for 5.748)
03:54:44.801 INFO  com.datastax.astra.GettingStartedWithAstra    : Environment variable 'USE_ASTRA' not found defaulting to 'true'
{PATH=/usr/local/openjdk-11/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin, HOSTNAME=559b69bdfe58, JAVA_HOME=/usr/local/openjdk-11, JAVA_VERSION=11.0.8, LANG=C.UTF-8, HOME=/root}

On another terminal, I'd like to see if the java backend is serving on port 5000

$ curl http://localhost:5000
curl: (7) Failed to connect to localhost port 5000: Connection refused

$ curl http://localhost:5000/api/credentials
curl: (7) Failed to connect to localhost port 5000: Connection refused

QUESTION: Can you please suggest a way to test that the JAR in the docker image is working?

1263-docker-run-astajava-backend.png

workshop
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

bettina.swynnerton avatar image
bettina.swynnerton answered bettina.swynnerton commented

Hi @Tri,

I am not sure what contributes to the refused connection here, other than perhaps that your docker image is not defaulting to port 5000.

Try to build the docker image as advised with this command:

mvn clean package dockerfile:build

Then run the container for example like here:

docker run -e USE_ASTRA='true' -p 5000:5000 astra-backend:my-image

On a fresh pull of the github code, this works well and now serves the swagger UI at

http://localhost:5000

Note, we made some changes yesterday to change the default port from 8080 to 5000, so make sure that your code is up to date before you build, and please use the above build command.

Let us know how it goes.

2 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tri avatar image Tri commented ·

Thanks @bettina.swynnerton this is the -e USE_ASTRA='true' that fixes it. Strange, I thought the code would default to true. But now I have enough clues to move forward for a proper fix. When everything is working OK, I'll make a PR. Thanks

0 Likes 0 ·
bettina.swynnerton avatar image bettina.swynnerton ♦♦ Tri commented ·

yes, I thought this would default to 'true', and it says so in the output.

03:54:44.801 INFO  com.datastax.astra.GettingStartedWithAstra    : Environment variable 'USE_ASTRA' not found defaulting to 'true'

looking forward to that PR.

0 Likes 0 ·