Deployment Overview
Relevant source files
The following files were used as context for generating this wiki page:This document provides a technical overview of the build and deployment processes for the gs-rest-service project. The project is a RESTful web service built with Spring Boot, designed to be packaged as an executable JAR and deployed to various environments, including local machines and cloud platforms like Cloud Foundry.
The deployment strategy involves building the application using either Maven or Gradle, which produces a self-contained JAR file. This artifact can then be run directly or deployed using platform-specific configurations, such as the provided manifest.yml for Cloud Foundry.
Build Process
The application can be built using either Maven or Gradle. Both build systems are configured to produce an executable JAR file containing all necessary dependencies.
Sources: README.adoc, test/run.sh
Build Tools and Commands
The project includes wrapper scripts (mvnw and gradlew) to ensure a consistent build environment without requiring a local installation of Maven or Gradle.
| Build Tool | Command | Description | Source File |
|---|---|---|---|
| Maven | ./mvnw clean package | Cleans the project and packages it into an executable JAR in the target/ directory. | test/run.sh:14 |
| Gradle | ./gradlew build | Builds the project and creates an executable JAR in the build/libs/ directory. | test/run.sh:28 |
The following diagram illustrates the high-level build flow for both Maven and Gradle.
This diagram shows that either Maven or Gradle can be used to process the source code and produce an executable JAR.
Sources: complete/pom.xml, test/run.sh, README.adoc
Maven Configuration
The Maven build is defined in complete/pom.xml. It uses spring-boot-starter-parent and includes the spring-boot-maven-plugin to create the executable JAR.
- Parent POM:
org.springframework.boot:spring-boot-starter-parent:3.3.0 - Artifact ID:
rest-service-complete - Java Version:
17 - Dependencies:
spring-boot-starter-webandspring-boot-starter-test.
Sources: complete/pom.xml:5-30
Application Entry Point
The application is a standard Spring Boot application, launched via the main method in the RestServiceApplication class. The @SpringBootApplication annotation enables auto-configuration and component scanning.
package com.example.restservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class RestServiceApplication {
public static void main(String[] args) {
SpringApplication.run(RestServiceApplication.class, args);
}
}
Sources: complete/src/main/java/com/example/restservice/RestServiceApplication.java:3-14
Deployment Strategies
Local Execution
Once the executable JAR is built, it can be run locally using the java -jar command. The service will start and be accessible at http://localhost:8080.
This flow is described in the project's README.adoc file.
This diagram shows the process of building the JAR and running it locally.
Sources: README.adoc
Cloud Foundry Deployment
The repository includes a manifest.yml file, which specifies the configuration for deploying the application to a Cloud Foundry-based platform.
Sources: complete/manifest.yml
Manifest Configuration
The manifest.yml file defines the application's name, memory allocation, instance count, and the path to the application artifact.
---
applications:
- name: gs-rest-service
memory: 256M
instances: 1
host: rest-service
domain: guides.spring.io
path: build/libs/gs-rest-service-0.1.0.jar
Sources: complete/manifest.yml:1-8
The properties in the manifest are detailed below:
| Property | Value | Description |
|---|---|---|
name | gs-rest-service | The name of the application in Cloud Foundry. |
memory | 256M | The memory limit for each application instance. |
instances | 1 | The number of application instances to run. |
host | rest-service | The hostname (subdomain) for the application's route. |
domain | guides.spring.io | The domain for the application's route. |
path | build/libs/gs-rest-service-0.1.0.jar | The path to the application JAR file, indicating a Gradle build. |
Sources: complete/manifest.yml:1-8
The deployment process to Cloud Foundry using this manifest is visualized below.
This diagram illustrates the cf push command flow for deploying the application to Cloud Foundry.
Sources: complete/manifest.yml
Automated Build and Deployment Script
The test/run.sh script provides a sequence of commands that can be used in a CI/CD pipeline. It demonstrates building the application with both Maven and Gradle.
The script performs the following steps:
- Navigates to the
initialproject directory. - Compiles the project with Maven (
./mvnw clean compile). - Compiles the project with Gradle (
./gradlew compileJava). - Navigates to the
completeproject directory. - Packages the application with Maven (
./mvnw clean package). - Builds the application with Gradle (
./gradlew build).
A commented-out section suggests a deployment step to upload the generated JAR to an AWS S3 bucket.
This flowchart shows the execution steps defined in the run.sh script, including a conditional deployment step.
Sources: test/run.sh:3-34