Nic
Nic

Reputation: 21

Mounting files into quarkus Dev Services for Database

I'm using quarkus and the DevServices to start a postgresql database. I want to initilize this database with a csv file. To do so I want to mount a csv file into the container of postgresql which is started with DevServices, so that I can initalize my database with "COPY ... FROM" in the init script.

I follow the quarkus documentation for database dev services:

I've tried to add the following to my project in the application properties:

quarkus.datasource.devservices.volumes."/resources/init/"=/container/resources/

or

quarkus.datasource.devservices.volumes."src/main/resources/init/"=/container/resources/

The problem is that my csv file isn't mounted correctly: The path /container/resources is in the postgres container but the resources folder is empty. It should contain the csv-file titanic.csv.

What path do I need to provide?

Upvotes: 2

Views: 737

Answers (2)

yrodiere
yrodiere

Reputation: 9977

The example in the documentation explains it well, I think:

# Using a filesystem volume:
quarkus.datasource.devservices.volumes."/path/from"=/container/to 
# Using a classpath volume:
quarkus.datasource.devservices.volumes."classpath:./file"=/container/to 

Your attempts are wrong for several reasons:

  1. Your file is in your application resources and thus will be available in the classpath, so you probably should use the classpath: variant instead of the filesystem variant you're using.
  2. Your first attempt uses "/resources/init/", which is an absolute path and probably doesn't match anything (unless you have a resources directory at the root of your filesystem and an init directory inside it, but I doubt that).
  3. Your second attempt uses src/main/resources/init/ assuming paths are relative to your project's root directory, but I doubt they are. More likely they're relative to whatever directory you start your application from (and in the case of tests with Maven, that's probably ./target).

In your case I'd try this instead?

quarkus.datasource.devservices.volumes."classpath:./init/"=/container/resources/

Upvotes: 0

Jose Carvajal
Jose Carvajal

Reputation: 151

You need to provide an absolute path where your resource is located. However, since you want to bind a resource that is in your classpath already, you can use:

quarkus.datasource.devservices.volumes."classpath:./init"=/container/resources

Where "." stands for the path at either "src/test/resources" if exists or "src/main/resources".

I hope it helps!

Upvotes: 0

Related Questions