wcmc-its / ReCiter

ReCiter: an enterprise open source author disambiguation system for academic institutions
Apache License 2.0
46 stars 25 forks source link

Error in running dynamoDb locally in Docker #452

Closed smierz closed 2 years ago

smierz commented 3 years ago

Describe the bug I want to run ReCiter with a local dynamoDb in Docker, but sqlite4java throws an error because it can not find its native-libs (see below)

To Reproduce Steps to reproduce the behavior:

  1. I cloned the repo and changed the following properties: spring.security.enabled=false aws.dynamoDb.local=true aws.dynamoDb.local.dbpath=/app aws.s3.use=false use.scopus.articles=false

  2. After that I did mvn install

  3. docker build + run

  4. See error

com.almworks.sqlite4java.SQLiteException: [-91] cannot load library: com.almworks.sqlite4java.SQLiteException: [-91] sqlite4java cannot find native library at com.almworks.sqlite4java.SQLite.loadLibrary(SQLite.java:97) ~[sqlite4java-1.0.392.jar!/:392] at com.almworks.sqlite4java.SQLiteConnection.open0(SQLiteConnection.java:1441) ~[sqlite4java-1.0.392.jar!/:392] at com.almworks.sqlite4java.SQLiteConnection.open(SQLiteConnection.java:282) ~[sqlite4java-1.0.392.jar!/:392] at com.almworks.sqlite4java.SQLiteConnection.open(SQLiteConnection.java:293) ~[sqlite4java-1.0.392.jar!/:392] at com.almworks.sqlite4java.SQLiteQueue.openConnection(SQLiteQueue.java:464) ~[sqlite4java-1.0.392.jar!/:392] at com.almworks.sqlite4java.SQLiteQueue.queueFunction(SQLiteQueue.java:641) ~[sqlite4java-1.0.392.jar!/:392] at com.almworks.sqlite4java.SQLiteQueue.runQueue(SQLiteQueue.java:623) ~[sqlite4java-1.0.392.jar!/:392] at com.almworks.sqlite4java.SQLiteQueue.access$000(SQLiteQueue.java:77) ~[sqlite4java-1.0.392.jar!/:392] at com.almworks.sqlite4java.SQLiteQueue$1.run(SQLiteQueue.java:205) ~[sqlite4java-1.0.392.jar!/:392] at java.base/java.lang.Thread.run(Unknown Source) ~[na:na] Caused by: com.almworks.sqlite4java.SQLiteException: [-91] sqlite4java cannot find native library at com.almworks.sqlite4java.Internal.loadLibraryX(Internal.java:136) ~[sqlite4java-1.0.392.jar!/:392] at com.almworks.sqlite4java.SQLite.loadLibrary(SQLite.java:95) ~[sqlite4java-1.0.392.jar!/:392] ... 9 common frames omitted

sarbajitdutta commented 3 years ago

@smierz Would you tell us what version of docker you are using? What is the OS you are using and its version? Did you try the application without docker? Also, I should mention we recently updated the master branch to use Java 11 as default. You can try to downgrade to Java 8 if you wish.

smierz commented 3 years ago

I'm using docker version 20.10.2 on Windows 10.

I'm able to run the application without docker ( I have Java 11 installed and used it to compile the application, no errors)

sarbajitdutta commented 3 years ago

@smierz We have designed the dynamodb local to run without docker. The docker version is for production when you want to connect to actual dynamodb service. You can run the application without docker with dyanmodb local. If you absolutely have to use docker you need to use docker-compose to separate the app and the dynamodb local as separate service and modify the file here https://github.com/wcmc-its/ReCiter/blob/a3d5d4665e8692853ca69f2db0caba0eb56f557d/src/main/java/reciter/database/dynamodb/DynamoDbConfig.java#L139 You need to change localhost to match the local DNS docker.for.win.localhost (since you are on Windows) Comment out these lines since its starting up the dynamodb local server using maven -https://github.com/wcmc-its/ReCiter/blob/a3d5d4665e8692853ca69f2db0caba0eb56f557d/src/main/java/reciter/database/dynamodb/DynamoDbConfig.java#L133-L136

You can directly start a dynamodb local container. Go to a directory where you want to mount it to persist local data and run docker run -it --rm -v ${PWD}:/home/dynamodblocal/data -p 8000:8000 amazon/dynamodb-local -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb -dbPath ./data

For docker-compose options see below.

For details you can refer to official dynamodb docs - https://github.com/awsdocs/amazon-dynamodb-developer-guide/blob/master/doc_source/DynamoDBLocal.DownloadingAndRunning.md

https://stackoverflow.com/a/53583725

I have pushed a branch which has the changes including a docker-compose.yaml which has local dynamodb. Update volume section for your own directory for dynamodb - https://github.com/wcmc-its/ReCiter/tree/dynamodb_local

Let me know if that answer your issue.

smierz commented 3 years ago

yes, thank you, this is working for me!

Two notes for documentation:

sarbajitdutta commented 3 years ago

@smierz thank you confirming the fix. I will update the documentation to reflect the host for windows with docker. Are you planning to set it up in AWS?

smierz commented 3 years ago

hm no, I don't think so.

btw if you update the README: since swagger 3.0 the address changed from /swagger-ui.html --> /swagger-ui/ or /swagger-ui/index.html

smierz commented 3 years ago

update: I replaced "docker.for.win.host.internal" in DynamoDbConfig with "http://dynamo", so I'm using the service that is available in the default network of docker-compose (OS-independent)