Developer Docs

Building and Deploying SpringBot

Building

Client-Side

When the client-side is built, the transpiled files are placed inside of the directory they are to be served from.

Perform the following steps to build your client-side.

  1. Open a terminal in the clientside directory projectName/clientside
  2. Install dependencies, enter: npm install
  3. Run the build step, enter: npx ng build --prod --optimization=false Note: We are currently temporarily disabling optimization due to some small issues that it causes.

You will now have all the build artefacts for the client-side in serverside/src/main/resources/static.

Server-Side

Before bundling your application, ensure that all properties are set in the relevant profiles, found at
projectName/serverside/src/main/resources/application.properties.

To avoid adding sensitive URLs and passwords to the git repo, we recommend reading them from environment variables. You can do so by adding properties like the following snippet.

spring.datasource.url=${DATA_SOURCE_URL:jdbc:postgresql://localhost:5432/postgres}
spring.datasource.username=${DATA_SOURCE_USERNAME:user}
spring.datasource.password=${DATA_SOURCE_PASSWORD:}
spring.datasource.platform=postgres
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=${HIBERNATE_DDL:update}

This properties file tries to read environment variables named DATA_SOURCE_URL, DATA_SOURCE_USERNAME, DATA_SOURCE_PASSWORD, and HIBERNATE_DDL. The text that follows the environment variable name and colon : is the default value which is used if the environment variable has not been set when the serverside is run. E.g. user will be the default username if DATA_SOURCE_USERNAME has not been set as an environment variable.

To complete this process for deployment, follow the instructions to build the server-side. This will cause the client-side and server-side to be bundled together.

For Windows, use gradlew.bat in place of gradlew in all commands.

You have the option to build two different types of artifacts. A JAR or a WAR.

JAR

Go to server-side folder

Linux/Mac
./gradlew bootJar

Windows
./gradlew.bat bootJar

WAR

Go to server-side folder

Linux/Mac
./gradlew bootWar

Windows
./gradlew.bat bootWar

Both artefacts can be found in /build/libs.

Running the Complete Application

For development, it is suggested to run both sides separately to take advantage of the tooling available for both technologies.

  1. Setup environment (See Setting Up Your Development Environment: Linux for details).
  2. Build Client-side (See above)
  3. Build Server-side (See above)
  4. Export any environment variables required for your environment (test, dev, prod)

Eg.

export SPRING_PROFILES_ACTIVE=dev
export DATA_SOURCE_USERNAME=codebots
export DATA_SOURCE_PASSWORD=bots

If you intend on running the application with the same configuration on the same computer or virtual machine, you may want to create a script to repeat this step every time you launch.

  1. Create a file named properties.sh containing the environment variables you wish to set
  2. Before running the server, run source properties.sh
  3. Run java -jar ${artifact-name}.jar (this could also be a WAR).

Unlike running the server-side and client-side individually running the JAR and WAR files use the port 8080. Go to localhost:8080

If you wish to run the application using the production profile, you will need to set up https and create an SSL certificate. This can be done with apache2 using a reverse proxy to redirect to localhost:8080.

Was this article helpful?

Thanks for your feedback!

If you would like to tell us more, please click on the link below to send us a message with more details.

Tool:

Generate

Iterate

Bot:

C#Bot

SpringBot

On this page

New to Codebots?

We know our software can be complicated, so we are always happy to have a chat if you have any questions.