Deploying Java Projects with CelerBuild Using the Spring Boot Framework Example
This guide demonstrates how to deploy a Java Spring Boot application using CelerBuild Standard Edition, including branch deployment, tag deployment, and tag version rollback operations.
Prerequisites
Important Note:
- For this tutorial, Java and Maven installation is required on the target server
- Local Java and Maven installation is recommended depending on your build strategy:
- If building locally and uploading to remote server: both local and remote installation needed
- If building only on remote server: only remote installation needed
- The System Service Setup must be configured on the target deployment server
1. System Prerequisites
Complete all Prerequisites setup steps.
2. Java Environment Setup
Installing Java and Maven
macOS
# Using Homebrew
brew install openjdk@17
brew install maven
# Create system Java symlink
sudo ln -sfn /usr/local/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk
# Add to ~/.zshrc
echo 'export PATH="/usr/local/opt/openjdk@17/bin:$PATH"' >> ~/.zshrc
echo 'export JAVA_HOME="/usr/local/opt/openjdk@17"' >> ~/.zshrc
# Verify installation
java --version
mvn --version
Ubuntu/Debian
# Update package list
sudo apt update
# Install Java and Maven
sudo apt install openjdk-17-jdk maven
# Verify installation
java --version
mvn --version
CentOS/RHEL
# Install Java and Maven
sudo yum install java-17-openjdk-devel maven
# Verify installation
java --version
mvn --version
3. System Service Setup
On the target deployment server, create a systemd service file for managing the Spring Boot application. This step is required for proper application management and auto-restart capabilities.
Important: This setup must be performed on each target deployment server.
sudo vim /etc/systemd/system/celerbuild-example-java.service
Add the following content:
[Unit]
Description=CelerBuild Example Java Application
After=network.target
[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu/celerbuild-example-java
Environment=SPRING_PROFILES_ACTIVE=dev
ExecStart=java -jar app.jar --spring.profiles.active=${SPRING_PROFILES_ACTIVE}
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
Configuration Notes:
- User:
- Change
ubuntu
to your actual service user- Ensure the user has proper permissions to run the application
- Example:
User=deploy
if using a deploy user- WorkingDirectory:
- Adjust
/home/ubuntu/...
to match your user's home directory- Must be an absolute path
- Example:
/home/deploy/celerbuild-example-java
for deploy user- Environment:
- Set
SPRING_PROFILES_ACTIVE=dev
for development environment- Set
SPRING_PROFILES_ACTIVE=prod
for production environment- This value determines which Spring profile to use
- ExecStart:
- The path to Java executable should be accessible to the service user
- The jar file name should match your actual application jar
- Example:
ExecStart=/usr/bin/java -jar app.jar
Branch Deployment (Development Environment)
1. Create Server Infrastructure
Create Server Cluster
- Navigate to
Global/Server Clusters
- Create a cluster named "example-java-server-cluster(dev)"
Add Server
- Navigate to the
Global/Servers
section or go to theActions
menu of the newly createdexample-java-server-cluster(dev)
and select "Servers" - Select cluster "example-java-server-cluster(dev)"
- Fill in:
- Server Name
- Server IP
- SSH Port (default: 22)
2. Import Project Template
Download Template
- Download project template: celerbuild-example-java-dev.yaml
- Template source: celerbuild-example-java dev template (opens in a new tab)
Import Template
- Navigate to
Projects/Projects
- Click "Import YAML"
- Upload the downloaded template
Create Project
- Review and confirm project settings
- Click "Create Project" to finish
Note: This example uses Ubuntu system with
ubuntu
user. Please adjust the Deployment Configuration (Target Deployment Path, Target Repository Path, Deployment User, etc.) according to your actual environment.
3. Initiating Deployment
- Go to
Operations/Applications
- Select project "celerbuild-example-java-dev"
- Fill in Title and Description
- Click sync icon next to "Branch" and select latest dev branch
- Click "Submit Application"
4. Executing Deployment
- In
Operations/Tasks
, find your project task - Click "Deploy" button
- On the task page, click "Start Deploy"
- Monitor Server Status and Operation Logs
- If issues occur, check error messages and retry deployment after fixing
5. Verification
Access http://server:8083/version
(replace "server" with your server address)
# Example command
➜ ~ curl http://server:8083/version
# Expected response
{"version":"1.0.0"}
Note:
- Replace "server" with your actual server IP address
- A response similar to
{"version":"1.0.0"}
indicates successful deployment- If you cannot access the endpoint, check:
- Server firewall settings
- Port 8083 accessibility
- Application running status using
sudo systemctl status springboot-app
Tag Deployment (Production Environment)
1. Create Server Infrastructure
Create Server Cluster
- Navigate to
Global/Server Clusters
- Create a cluster named "example-java-server-cluster(prod)"
Add Server
- Navigate to the
Global/Servers
section - Select cluster "example-java-server-cluster(prod)"
- Fill in:
- Server Name
- Server IP
- SSH Port (default: 22)
2. Import Project Template
Download Template
- Download project template: celerbuild-example-java-prod.yaml
- Template source: celerbuild-example-java prod template (opens in a new tab)
Import Template
- Navigate to
Projects/Projects
- Click "Import YAML"
- Upload the downloaded template
Create Project
- Review and confirm project settings
- Click "Create Project" to finish
Note: This example uses Ubuntu system with
ubuntu
user. Please adjust the Deployment Configuration (Target Deployment Path, Target Repository Path, Deployment User, etc.) according to your actual environment.
3. Initiating Deployment
- Go to
Operations/Applications
- Select project "celerbuild-example-java-prod"
- Fill in deployment information:
- Title: "Deploy v1.0.0"
- Description: "Initial deployment of v1.0.0"
- Click sync icon next to "Tag" and select "v1.0.0"
- Click "Submit Application"
4. Executing Deployment
Follow the same steps as branch deployment execution.
5. Verification
curl http://server:8083/version
{"version":"1.0.0"}
Rollback Operations
Note: Branch deployment rollback is not demonstrated here because the system only maintains the latest committed version. We'll demonstrate rollback using tag deployments instead.
Tag Deployment Rollback Example
1. Initial Deployment (v1.0.0)
For detailed deployment steps, refer to:
Verify deployment:
curl http://server:8080/version
{"version":"1.0.0"}
2. Upgrade to v1.0.1
For detailed deployment steps, refer to:
- Go to
Operations/Applications
- Create new deployment
- Fill in deployment information:
- Title: "Upgrade to v1.0.1"
- Description: "Upgrading from v1.0.0 to v1.0.1"
- Select tag "v1.0.1"
- Submit and execute deployment
- Verify upgrade:
curl http://server:8083/version
{"version":"1.0.1"}
3. Rollback to v1.0.0
- In
Operations/Applications
, find your project - Click Actions (three dots) and select "Apply Rollback"
- Fill in rollback information:
- Title: "Rollback to v1.0.0"
- Description: "Rolling back from v1.0.1 to v1.0.0"
- Click sync icon next to "Select Rollback Tag"
- Select "v1.0.0" from the available tags
- Click "Submit Rollback"
4. Execute Rollback
- Go to
Operations/Tasks
- Find your rollback task
- Click "Rollback" in Actions
- Click "Start Rollback" on the task page
- Monitor Server Status and Operation Logs
- Verify rollback success:
curl http://server:8083/version
{"version":"1.0.0"}
For detailed rollback instructions, see:
Additional Notes
Application Logs
View application logs using systemd:
# View all logs
sudo journalctl -u celerbuild-example-java
# View recent logs
sudo journalctl -u celerbuild-example-java -n 100
# Follow logs in real-time
sudo journalctl -u celerbuild-example-java -f
Service Management
Common systemd commands for managing the application:
# Check service status
sudo systemctl status celerbuild-example-java
# Start service
sudo systemctl start celerbuild-example-java
# Stop service
sudo systemctl stop celerbuild-example-java
# Restart service
sudo systemctl restart celerbuild-example-java
Congratulations! You have successfully learned how to deploy Spring Boot Framework using CelerBuild Standard Edition, including branch deployment, tag deployment, and tag version rollback operations! 🎉