From cae0902b58f2f021e332c7cd7636ad66c2cea885 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Fri, 1 Mar 2024 10:32:02 +0100 Subject: [PATCH 1/2] wip! feat(symphony-ws): Add Dockerfile --- symphony-ws/Dockerfile | 42 +++++++++++++++++++++ symphony-ws/startWithPostgres.sh | 65 ++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 symphony-ws/Dockerfile create mode 100644 symphony-ws/startWithPostgres.sh diff --git a/symphony-ws/Dockerfile b/symphony-ws/Dockerfile new file mode 100644 index 00000000..65f1460b --- /dev/null +++ b/symphony-ws/Dockerfile @@ -0,0 +1,42 @@ +FROM maven:3.9.6-eclipse-temurin-17 as build + +WORKDIR /app + +COPY . . + +RUN mvn package -DskipTests + +FROM quay.io/wildfly/wildfly:26.1.2.Final-jdk17 as production + +ENV WILDFLY_HOME /opt/jboss/wildfly +ENV DEPLOY_DIR ${WILDFLY_HOME}/standalone/deployments/ + +ENV DATASOURCE_NAME ApplicationDS +ENV DATASOURCE_JNDI java:/SymphonyDS + +ENV DB_HOST database +ENV DB_PORT 5432 +ENV DB_USER user +ENV DB_PASS password +ENV DB_NAME symphony + +# create temporary deployment dir, because wars can deploy after the datasource is created +USER jboss +RUN mkdir /tmp/deploments +ENV DEPLOY_DIR /tmp/deploments + +RUN mkdir /tmp/jboss-cli +ENV CLI_DIR /tmp/jboss-cli + +COPY startWithPostgres.sh $WILDFLY_HOME/bin + +USER root +RUN chown jboss:jboss $WILDFLY_HOME/bin/startWithPostgres.sh +RUN chmod 755 $WILDFLY_HOME/bin/startWithPostgres.sh +USER jboss + +RUN wget -O /tmp/postgresql-42.2.28.jar https://jdbc.postgresql.org/download/postgresql-42.2.28.jre7.jar + +COPY --from=build /app/target/symphony-ws-1.19.0-SNAPSHOT.war /tmp/deployments/ + +ENTRYPOINT $WILDFLY_HOME/bin/startWithPostgres.sh diff --git a/symphony-ws/startWithPostgres.sh b/symphony-ws/startWithPostgres.sh new file mode 100644 index 00000000..00fba75e --- /dev/null +++ b/symphony-ws/startWithPostgres.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +echo "=> Who Am I?" +whoami + +if [ ! -f wildfly.started ]; then +JBOSS_CLI=$WILDFLY_HOME/bin/jboss-cli.sh + +function wait_for_server() { + until `$JBOSS_CLI -c "ls /deployment" &> /dev/null`; do + echo "Waiting" + sleep 1 + done +} + +echo "=> Starting WildFly server" +$WILDFLY_HOME/bin/standalone.sh -b=0.0.0.0 -c standalone.xml > /dev/null & + +echo "=> Waiting for the server to boot" +wait_for_server + +echo "=> Setup Datasource" +$JBOSS_CLI -c << EOF +batch + +# Add PostgreSQL driver +module add --name=org.postgres --resources=/tmp/postgresql-42.2.28.jar --dependencies=javax.api,javax.transaction.api +/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver) + +# Add the datasource +data-source add \ + --jndi-name=$DATASOURCE_JNDI \ + --name=$DATASOURCE_NAME \ + --connection-url=jdbc:postgresql://$DB_HOST:$DB_PORT/$DB_NAME \ + --driver-name=postgres \ + --user-name=$DB_USER \ + --password=$DB_PASS \ + --check-valid-connection-sql="SELECT 1" \ + --background-validation=true \ + --background-validation-millis=60000 \ + --flush-strategy=IdleConnections \ + --min-pool-size=10 --max-pool-size=100 --pool-prefill=false + +# Execute the batch +run-batch +EOF + +FILES=$CLI_DIR/*.cli +for f in $FILES +do + echo "Processing $f file..." + $JBOSS_CLI -c --file=$f +done + +echo "=> Shutdown Wildfly" +$JBOSS_CLI -c ":shutdown" + +echo "=> DEPLOY WARs" +cp ${DEPLOY_DIR}/* ${WILDFLY_HOME}/standalone/deployments/ + +touch wildfly.started +fi + +echo "=> Start Wildfly" +$WILDFLY_HOME/bin/standalone.sh -b=0.0.0.0 -c standalone.xml From 4a321f41cd61a69bc2ba25cf52251f8e79767ea3 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Mon, 4 Mar 2024 15:03:08 +0100 Subject: [PATCH 2/2] fixup! wip! feat(symphony-ws): Add Dockerfile --- symphony-ws/Dockerfile | 7 ++++--- symphony-ws/startWithPostgres.sh | 14 ++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/symphony-ws/Dockerfile b/symphony-ws/Dockerfile index 65f1460b..a26791ff 100644 --- a/symphony-ws/Dockerfile +++ b/symphony-ws/Dockerfile @@ -6,10 +6,10 @@ COPY . . RUN mvn package -DskipTests +# Based on https://github.com/tonda100/wildfly-postgresql FROM quay.io/wildfly/wildfly:26.1.2.Final-jdk17 as production ENV WILDFLY_HOME /opt/jboss/wildfly -ENV DEPLOY_DIR ${WILDFLY_HOME}/standalone/deployments/ ENV DATASOURCE_NAME ApplicationDS ENV DATASOURCE_JNDI java:/SymphonyDS @@ -22,8 +22,8 @@ ENV DB_NAME symphony # create temporary deployment dir, because wars can deploy after the datasource is created USER jboss -RUN mkdir /tmp/deploments -ENV DEPLOY_DIR /tmp/deploments +RUN mkdir /tmp/deployments +ENV DEPLOY_DIR /tmp/deployments RUN mkdir /tmp/jboss-cli ENV CLI_DIR /tmp/jboss-cli @@ -32,6 +32,7 @@ COPY startWithPostgres.sh $WILDFLY_HOME/bin USER root RUN chown jboss:jboss $WILDFLY_HOME/bin/startWithPostgres.sh +# RUN chown -R jboss:jboss $CLI_DIR RUN chmod 755 $WILDFLY_HOME/bin/startWithPostgres.sh USER jboss diff --git a/symphony-ws/startWithPostgres.sh b/symphony-ws/startWithPostgres.sh index 00fba75e..806f580e 100644 --- a/symphony-ws/startWithPostgres.sh +++ b/symphony-ws/startWithPostgres.sh @@ -1,9 +1,12 @@ #!/bin/bash -echo "=> Who Am I?" -whoami +set -e # Exit the script on error + +if [[ -f wildfly/wildfly.started ]]; then + echo "=> Wildfly has already been started" + exit 1 +fi -if [ ! -f wildfly.started ]; then JBOSS_CLI=$WILDFLY_HOME/bin/jboss-cli.sh function wait_for_server() { @@ -45,7 +48,7 @@ data-source add \ run-batch EOF -FILES=$CLI_DIR/*.cli +FILES=$(find "$CLI_DIR" -iname '*.cli') for f in $FILES do echo "Processing $f file..." @@ -58,8 +61,7 @@ $JBOSS_CLI -c ":shutdown" echo "=> DEPLOY WARs" cp ${DEPLOY_DIR}/* ${WILDFLY_HOME}/standalone/deployments/ -touch wildfly.started -fi +touch wildfly/wildfly.started echo "=> Start Wildfly" $WILDFLY_HOME/bin/standalone.sh -b=0.0.0.0 -c standalone.xml