From e1b3f429d6a18e19ab3563d5b3be0cbb58de31a9 Mon Sep 17 00:00:00 2001 From: Oliver Bertuch Date: Mon, 26 Nov 2018 13:07:33 +0100 Subject: [PATCH] Create JDBC connection from glassfish-resources.xml This commit is a first test to apply database configuration and credentials to the application server without using a config on domain level but on application level. Most certainly, this is only compatible with Payara 5.x as Glassfish 5.x is unknown to support system properties in config files and it certainly does not support password aliases. The JNDI names have been changed to be conform with Java EE 7. See https://github.com/javaee-samples/javaee7-samples/tree/master/jpa/datasourcedefinition-applicationxml-pu and others for working examples. (Staying with the old name was not successfull.) --- conf/docker/app/Dockerfile | 4 +++- conf/docker/app/init_2_configure.sh | 17 +++++++++++++++++ pom.xml | 6 +++++- src/main/resources/META-INF/persistence.xml | 2 +- src/main/webapp/WEB-INF/glassfish-resources.xml | 17 +++++++++++++++++ 5 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 conf/docker/app/init_2_configure.sh create mode 100644 src/main/webapp/WEB-INF/glassfish-resources.xml diff --git a/conf/docker/app/Dockerfile b/conf/docker/app/Dockerfile index 2dfa6f3dbe4..359a4bd8377 100644 --- a/conf/docker/app/Dockerfile +++ b/conf/docker/app/Dockerfile @@ -7,4 +7,6 @@ ARG LIB_PATH="${PAYARA_DIR}/glassfish/domains/${DOMAIN_NAME}/lib/" COPY --chown=payara maven/lib/* ${LIB_PATH} -COPY maven/${project.build.finalName}.war ${DEPLOY_DIR} \ No newline at end of file +COPY maven/${project.build.finalName}.war ${DEPLOY_DIR} + +COPY --chown=payara init_2_configure.sh ${SCRIPT_DIR} \ No newline at end of file diff --git a/conf/docker/app/init_2_configure.sh b/conf/docker/app/init_2_configure.sh new file mode 100644 index 00000000000..35d1d0a1cf4 --- /dev/null +++ b/conf/docker/app/init_2_configure.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +# TEST FOR POSTBOOT: THIS WILL NEED TO BE ENHANCED WITH A) ENV VARS +# AND B) SECRETS FILE... + +echo "AS_ADMIN_ALIASPASSWORD=test1234" > ${PAYARA_DIR}/dbpass + +cat > ${POSTBOOT_COMMANDS}.tmp << 'EOF' +create-system-properties "postgres.host=postgres" +create-system-properties "postgres.port=5432" +create-system-properties "postgres.database=dataverse +create-system-properties "postgres.user=dataverse" +create-password-alias "postgres-pass" --passwordfile ${PAYARA_DIR}/dbpass +EOF + +echo "$(cat ${POSTBOOT_COMMANDS}.tmp | cat - ${POSTBOOT_COMMANDS} )" > ${POSTBOOT_COMMANDS} +cat ${POSTBOOT_COMMANDS} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3f20d00c0b0..8be16a6dc24 100644 --- a/pom.xml +++ b/pom.xml @@ -706,7 +706,11 @@ + the installer a tiny bit simpler and make distribution easier. + Needs testing. See also: + https://github.com/eclipse-ee4j/glassfish/issues/19451 + https://github.com/eclipse-ee4j/glassfish/issues/20944 + --> org.postgresql postgresql diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml index 8b4e33858ac..85da2f1c4d6 100644 --- a/src/main/resources/META-INF/persistence.xml +++ b/src/main/resources/META-INF/persistence.xml @@ -3,7 +3,7 @@ org.eclipse.persistence.jpa.PersistenceProvider - jdbc/VDCNetDS + java:app/DV/VDCNetDS diff --git a/src/main/webapp/WEB-INF/glassfish-resources.xml b/src/main/webapp/WEB-INF/glassfish-resources.xml new file mode 100644 index 00000000000..d5286b3c609 --- /dev/null +++ b/src/main/webapp/WEB-INF/glassfish-resources.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + \ No newline at end of file