rafabene / devops-demo

MIT License
70 stars 62 forks source link

Painless WildFly datasources in Docker #5

Open sfcoy opened 6 years ago

sfcoy commented 6 years ago

There is no need to start WildFly up in order to set up a data source.

Create a cli script named install-ds.cli similar to:

# Execute offline
embed-server --server-config=standalone.xml

deploy postgresql-42.1.1.jre7.jar

# Add the application datasource
data-source add \
    --name=BloggoDS \
    --driver-name=postgresql-42.1.1.jre7.jar \
    --connection-url=jdbc:postgresql://bloggodb:5432/bloggodb \
    --jndi-name=java:jboss/datasources/BloggoDS \
    --user-name=bloggo \
    --password=password \
    --use-ccm=false \
    --min-pool-size=10 \
    --max-pool-size=25 \
    --pool-prefill=true \
    --blocking-timeout-wait-millis=5000 \
    --new-connection-sql="set datestyle = ISO, European;"

and add the following fragment to your Dockerfile:

RUN curl -L -O https://repo1.maven.org/maven2/org/postgresql/postgresql/42.1.1.jre7/postgresql-42.1.1.jre7.jar
COPY install-ds.cli bin/
RUN bin/jboss-cli.sh --file="bin/install-ds.cli" && rm postgresql-42.1.1.jre7.jar

Adjust for the version of the driver and actual datasource names that you want. I don't bother with adding a module for the driver because it adds unnecessary complexity.

Cheers,

@sfcoy

rmpestano commented 6 years ago

Hi @sfcoy, (I'm not the owner of this project, I'm just watching it)

is it possible tu use env or system properties in password and connection-url with this approach?

sfcoy commented 6 years ago

I know that WildFly does support ${username} style variable expansion, but I've not tried the ${env.USERNAME} approach.