Skip to content

Commit 734f2e9

Browse files
committed
updated README
1 parent 1c370dc commit 734f2e9

2 files changed

Lines changed: 75 additions & 10 deletions

File tree

.github/workflows/ci-cd-pipeline.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ jobs:
8383
uses: webfactory/ssh-agent@v0.9.0
8484
with:
8585
ssh-private-key: ${{ secrets.EC2_PRIVATE_KEY }}
86-
- name: Remove any existing app (Kill process on port 8080 on remote host)
87-
run: ssh -o StrictHostKeyChecking=no ubuntu@${{ secrets.EC2_HOST }} "fuser -k 8080/tcp || true"
86+
- name: Ensure Java is installed on remote server
87+
run: ssh -o StrictHostKeyChecking=no ubuntu@${{ secrets.EC2_HOST }} \
88+
"sudo apt update && sudo apt install -y openjdk-17-jre"
8889

8990
- name: Deploy JAR to EC2 server
9091
run: scp -o StrictHostKeyChecking=no staging/*.jar ubuntu@${{ secrets.EC2_HOST }}:/home/ubuntu/
91-
92-
- name: Ensure Java is installed on remote
93-
run: ssh -o StrictHostKeyChecking=no ubuntu@${{ secrets.EC2_HOST }} \
94-
"sudo apt update && sudo apt install -y openjdk-17-jre"
92+
93+
- name: Remove any existing app (Kill process on port 8080 on remote host)
94+
run: ssh -o StrictHostKeyChecking=no ubuntu@${{ secrets.EC2_HOST }} "fuser -k 8080/tcp || true"
9595

9696
- name: Start Java App Spring PetClinic on EC2 instance
9797
# Restart the java app on EC2 and redirect both standard output and standard error from the Java application to the app.log file and runs the application in the background

README.md

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,77 @@
1+
# CI-CD for a Standalone Java App
2+
Deploy the [Spring PetClinic Application](https://github.com/spring-projects/spring-petclinic) on Amazon Cloud using Github Actions Workflow.
3+
14
## Run Petclinic locally
25

36
Spring Petclinic is a [Spring Boot](https://spring.io/guides/gs/spring-boot) application built using [Maven](https://spring.io/guides/gs/maven/) or [Gradle](https://spring.io/guides/gs/gradle/). You can build a jar file and run it from the command line (it should work just as well with Java 17 or newer):
47

8+
Create fork of the repository: https://github.com/spring-projects/spring-petclinic.git
59
```bash
6-
git clone https://github.com/spring-projects/spring-petclinic.git
10+
git clone <your-repository>
711
cd spring-petclinic
8-
./mvnw package
9-
java -jar target/*.jar
12+
chmod +x mvnw
13+
./mvnw package (to build, test and generate artifacts)
14+
java -jar target/*.jar (starts the application)
15+
```
16+
You can then access the Petclinic at <http://localhost:8080/>
17+
</br>
18+
19+
```bash
20+
cd target
21+
ls
22+
.nvmw test (for running unit tests)
1023
```
24+
Run Sonarqube analysis locally on java code and check results on Sonarqube dashboard ```http://<IP-address>:9000```
25+
26+
```bash
27+
mvn clean verify sonar:sonar \
28+
-Dsonar.projectKey=<sonarqube-project-name> \
29+
-Dsonar.projectName='<sonarqube-project-name>' \
30+
-Dsonar.host.url=<sonarqube-host-url> \
31+
-Dsonar.token=<your-sonarqube-project-token>
32+
```
33+
---
34+
Now proceed with CI-CD using Githb Actions.
35+
36+
## Steps:
37+
- Running the Petclinic App locally to ensure it works as expected (optional)
38+
- Setting up a Continuous Integration (CI) pipeline using GitHub Actions to build and test the code using Maven
39+
- Integrating SonarQube for code quality analysis
40+
- Packaging and storing artifacts (JAR files)
41+
- Deploying the JAR file to an AWS EC2 instance
42+
</br>
43+
44+
### Continuous Integration
45+
- Check out the code
46+
- Build the code using Maven (wrapper included)
47+
- Run tests
48+
- Analyze code quality using SonarQube
49+
- Archive the JAR file as an artifact for later use
50+
51+
### Continuous Deployment
52+
The second part of the pipeline (the deploy job) runs after the build job if it’s successful
53+
- Download the JAR artifact from the previous build
54+
- Securely copy (scp) the new JAR to /home/ubuntu on the EC2 instance
55+
- Ensure Java is installed (```sudo apt update && sudo apt install -y openjdk-17-jre```)
56+
- SSH into the EC2 machine, killing any process that might already be running on port 8080
57+
- Start Spring PetClinic in the background using ```nohup```
58+
59+
**Important Notes**: Make sure your EC2 instance’s security group allows inbound traffic on port 8080 so that you can reach the PetClinic app in a browser. </br>
60+
In your GitHub repository settings, under “Secrets and variables” → “Actions”, add: </br>
61+
SONAR_HOST_URL, SONAR_TOKEN, EC2_HOST, EC2_PRIVATE_KEY
62+
63+
### Verification
64+
After the pipeline finishes, visit:
65+
66+
```
67+
http://<EC2_PUBLIC_IP_OR_DNS>:8080
68+
```
69+
You should see the Spring PetClinic landing page. Additionally, log into your SonarQube server ```http://<sonarqube-EC2-instance-public-ip-or-host>:9000``` and verify that the Spring-PetClinic analysis is present.
70+
71+
### Troubleshooting
72+
SSH into your EC2 instance manually: ```ssh -i <your-private-key> <user>@<IP adress>```
1173

12-
You can then access the Petclinic at <http://localhost:8080/>
74+
1. Verify Java is installed and JAR file exists: ```java -version``` and ```ls -l /home/ubuntu/app.jar```
75+
2. Run the nohup java -jar command manually: ```nohup java -jar /home/ubuntu/spring-petclinic-*.jar > app.log 2>&1 &```
76+
3. Verify Application running: ```curl localhost:8080``` or ```ps aux | grep java```
77+
4. If not, check the app.log file for any error messages: ```tail app.log```

0 commit comments

Comments
 (0)