Setup Guide
This guide walks you through setting up the Agritech application for development or production environments. The application is built with Spring Boot, uses Docker for containerization, and GraalVM for generating native images for optimal performance.
Prerequisites
Before starting, ensure you have the following installed:
-
Java Development Kit (JDK 23 or later)
Install JDK compatible with GraalVM:sudo apt update
sudo apt install openjdk-23-jdk -
GraalVM
Download and install GraalVM Community Edition:curl -L -o graalvm.tar.gz https://github.com/graalvm/graalvm-ce-builds/releases/download/<version>/graalvm-ce-java23-linux-amd64-<version>.tar.gz
tar -xvf graalvm.tar.gz
sudo mv graalvm-ce-java23-<version> /usr/lib/graalvm
export PATH=/usr/lib/graalvm/bin:$PATHValidate installation:
java -version -
Docker
Install Docker to run containers:sudo apt update
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker -
Maven
Ensure Maven is installed for building the project:sudo apt install maven -
Git
Clone the repository:sudo apt install git
git clone <repository-url>
cd <repository-directory>
Development Setup
-
Clone the Repository
git clone <repository-url>
cd <repository-directory> -
Configure Docker Navigate to
infrastructure/dockerand start the containers e.gdocker compose -f postgres.yml up|docker compose -f redis.yml up -
Configure Application Properties Update
*.ymlwith your local configurations (e.g., database credentials). -
Start the Application Run the application locally using Maven:
mvn spring-boot:run -
Access the Application
- Default port:
http://localhost:8080
- Default port:
Building a Native Image
The native images are built using docker, this allows flexibility to generate images for any platform without requiring to install too many dependencies on the image building host machine.
Ubuntu 20.04
-
Create docker image
docker build -f ./docker/Dockerfile20-04 -t graalvm-native-ubuntu-20-04 . -
Generate native image
docker run -v $(pwd):/app -w /app graalvm-native-ubuntu-20-04 bash -c "mvn package -Pnative -DskipTests"
Ubuntu 22.04
-
Create docker image
docker build -f ./docker/Dockerfile22-04 -t graalvm-native-ubuntu-22-04 . -
Generate native image
docker run -v $(pwd):/app -w /app graalvm-native-ubuntu-22-04 bash -c "mvn package -Pnative -DskipTests"
Native image
The generated native image is located at target/Agritech
Production Setup
Environment Variables
Ensure sensitive configurations are provided as environment variables (e.g., database URLs, API keys):
export DATABASE_URL=<your-database-url>
export API_KEY=<your-api-key>
Native image
In ubuntu setup systemd to automate app running
- Copy the native image to production host e.g
cp target/Agritech ~/apps/Agritech - Setup systemd
sudo touch /etc/systemd/system/Agritech.service
sudo nano /etc/systemd/system/Agritech.service
Paste this script in above Agritech.service
[Unit]
Description=Agritech App
After=network.target
[Service]
ExecStart=~/apps/Agritech
WorkingDirectory=~/apps
Restart=always
User=root
[Install]
WantedBy=multi-user.target
Then allow the Agritech app in systemd
sudo systemctl daemon-reload
sudo systemctl start Agritech
sudo systemctl enable Agritech
Monitoring and Logging
- Use tools like Prometheus or ELK Stack for monitoring and logging.
- Ensure logs are written to
stdoutfor easy access in containerized environments.
Troubleshooting
-
Port Conflicts: If port 8080 is already in use, modify the port in
application.properties:server:
port: 9090 -
Docker Issues: Verify Docker service is running:
sudo systemctl status docker -
Native Image Errors: Ensure all dependencies are compatible with GraalVM and resolve unsupported reflection warnings.
With this setup guide, you are now ready to run the Agritech application in development or production environments. For further assistance, refer to the official Spring Boot documentation or contact the team.