Start modelling your app today.

Get started for free

What's this?

Building and Deploying SpringBot

Learn how to compile SpringBot into a JAR/WAR so that it can be deployed in a production environment.


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 artifacts 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 artifacts 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.

  • Create a file named properties.sh containing the environment variables you wish to set
  • Before running the server, run source properties.sh
  1. 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.


Start modelling your app today.