Skip to content

Latest commit

 

History

History
107 lines (89 loc) · 5.54 KB

File metadata and controls

107 lines (89 loc) · 5.54 KB
authorms.servicems.devlangms.topicms.datems.author
cephalin
azure-app-service
java
include
11/05/2024
cephalin
  1. Put your JBoss CLI commands into a file named jboss-cli-commands.cli. The JBoss commands must add the module and register it as a data source. The following example shows the JBoss CLI commands for creating a PostgreSQL data source with the JNDI name java:jboss/datasources/postgresDS.

    module add --name=org.postgresql --resources=/home/site/libs/postgresql-42.7.4.jar /subsystem=datasources/jdbc-driver=postgresql:add(driver-name="postgresql",driver-module-name="org.postgresql",driver-class-name="org.postgresql.Driver",driver-xa-datasource-class-name="org.postgresql.xa.PGXADataSource") data-source add --name=postgresql --driver-name="postgresql" --jndi-name="java:jboss/datasources/postgresDS" --connection-url="jdbc:postgresql://\${env.DB_HOST}:5432/postgres" --user-name="\${env.DB_USERNAME}" --password="\${env.DB_PASSWORD}" --enabled=true --use-java-context=true

    Note that the module add command uses three environment variables (DB_HOST, DB_USERNAME, and DB_PASSWORD), which you must add in App Service as app settings. The script adds them without the --resolve-parameter-values flag so that JBoss doesn't save their values in plaintext.

  2. Create a startup script, startup.sh, that calls the JBoss CLI commands. The following example shows how to call your jboss-cli-commands.cli. Later, you'll configure App Service to run this script when the container starts.

    $JBOSS_HOME/bin/jboss-cli.sh --connect --file=/home/site/scripts/jboss_cli_commands.cli
  3. Using a deployment option of your choice, upload your JDBC driver, jboss-cli-commands.cli, and startup.sh to the paths specified in the respective scripts. Especially, upload startup.sh as a startup file. For example:

    export RESOURCE_GROUP_NAME=<resource-group-name> export APP_NAME=<app-name> # The lib type uploads to /home/site/libs by default. az webapp deploy --resource-group $RESOURCE_GROUP_NAME --name $APP_NAME --src-path postgresql-42.7.4.jar --target-path postgresql-42.7.4.jar --type lib az webapp deploy --resource-group $RESOURCE_GROUP_NAME --name $APP_NAME --src-path jboss_cli_commands.cli --target-path /home/site/scripts/jboss_cli_commands.cli --type static # The startup type uploads to /home/site/scripts/startup.sh by default. az webapp deploy --resource-group $RESOURCE_GROUP_NAME --name $APP_NAME --src-path startup.sh --type startup 

    For more information, see Deploy files to App Service.

    <deployment> <resources> <resource> <!-- The lib type uploads to /home/site/libs by default. --> <type>lib</type> <directory>${project.build.directory}/${project.artifactId}/META-INF/lib</directory> <!-- Assume driver is part of POM dependencies. --> <includes> <include>postgresql-42.7.4.jar</include> </includes> </resource> <resource> <!-- The script type uploads to /home/site/scripts by default. --> <type>script</type> <directory>${project.scriptSourceDirectory}</directory> <!-- Assume script is in src/main/scripts. --> <includes> <include>jboss_cli_commands.cli</include> </includes> </resource> <resource> <!-- The startup type uploads to /home/site/scripts by default. --> <type>startup</type> <directory>${project.scriptSourceDirectory}</directory> <!-- Assume script is in src/main/scripts. --> <includes> <include>startup.sh</include> </includes> </resource> ... </resources> </deployment>
    variables: # Set <subscription-id>, <resource-group-name>, <app-name> for your environment - name: SUBSCRIPTION_IDvalue: <subscription-id> - name: RESOURCE_GROUP_NAMEvalue: <resource-group-name> - name: APP_NAMEvalue: <app-name>steps: - task: AzureCLI@2displayName: Azure CLIinputs: azureSubscription: $(SUBSCRIPTION_ID)scriptType: bashscriptLocation: inlineScriptinlineScript: | # The lib type uploads to /home/site/libs by default. az webapp deploy --resource-group $(RESOURCE_GROUP_NAME) --name $(APP_NAME) --src-path postgresql-42.7.4.jar --target-path postgresql-42.7.4.jar --type lib az webapp deploy --resource-group $(RESOURCE_GROUP_NAME) --name $(APP_NAME) --src-path jboss_cli_commands.cli --target-path /home/site/scripts/jboss_cli_commands.cli --type static # The startup type uploads to /home/site/scripts/startup.sh by default. az webapp deploy --resource-group $(RESOURCE_GROUP_NAME) --name $(APP_NAME) --src-path startup.sh --type startup

To confirm that the data source was added to the JBoss server, SSH into your webapp and run $JBOSS_HOME/bin/jboss-cli.sh --connect. Once you're connected to JBoss, run the /subsystem=datasources:read-resource to print a list of the data sources.

As defined by jboss-cli-commands.cli previously, you can access the PostgreSQL connection using the JNDI name java:jboss/datasources/postgresDS.

close