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.
- Open a terminal in the clientside directory
projectName/clientside
- Install dependencies, enter:
npm install
- 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.
- Setup environment (See Setting Up Your Development Environment: Linux for details).
- Build Client-side (See above)
- Build Server-side (See above)
- 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
- 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?