Skip to content

Commit 696f719

Browse files
ajitpdevopsajitpdevops
andauthored
Merged a coupon app changes to main (#13)
* Github actions #3 * Sonaqube analysis in Actions * Docker Image Push Workflow * spring-boot-starter version update * docker run steps * docker run steps changed * docker run steps corrected * pr process sorted for coupon app --------- Co-authored-by: ajitpdevops <ajitp.devops@gmail.com>
1 parent 343e252 commit 696f719

File tree

7 files changed

+197
-54
lines changed

7 files changed

+197
-54
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 0
13+
14+
- name: Set up JDK 17
15+
uses: actions/setup-java@v4
16+
with:
17+
distribution: 'adopt'
18+
java-version: '17'
19+
server-id: github
20+
settings-path: ${{ github.workspace }}
21+
22+
- name: Run Commands
23+
run: |
24+
java -version
25+
mvn -version
26+
docker --version
27+
terraform --version
28+
echo "PWD: ${pwd}"
29+
echo "GITHUB_WORKSPACE: ${GITHUB_WORKSPACE}"
30+
31+
- name: Start PostgreSQL
32+
run: docker compose -f compose.yml up -d web-db
33+
working-directory: src
34+
35+
- name: Cache SonarCloud packages
36+
uses: actions/cache@v3
37+
with:
38+
path: ~/.sonar/cache
39+
key: ${{ runner.os }}-sonar
40+
restore-keys: ${{ runner.os }}-sonar
41+
42+
- name: Cache Maven packages
43+
uses: actions/cache@v3
44+
with:
45+
path: ~/.m2
46+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
47+
restore-keys: ${{ runner.os }}-m2
48+
49+
- name: Build with Maven
50+
run: mvn -B clean install
51+
working-directory: src/couponservice
52+
53+
- name: Run Tests
54+
run: mvn test
55+
working-directory: src/couponservice
56+
57+
# Run SonarCloud analysis
58+
- name: Build and analyze with SonarCloud
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
62+
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=cyberlysafe_java-springboot-microservices
63+
working-directory: src/couponservice
64+
65+
build-image:
66+
name: Build Docker Image
67+
runs-on: ubuntu-latest
68+
needs: build
69+
70+
steps:
71+
- uses: actions/checkout@v4
72+
with:
73+
fetch-depth: 0
74+
75+
- name: Set up JDK 17
76+
uses: actions/setup-java@v4
77+
with:
78+
distribution: 'adopt'
79+
java-version: '17'
80+
server-id: github
81+
settings-path: ${{ github.workspace }}
82+
83+
- name: Set version to latest commit
84+
# append the short SHA to the project version in POM file
85+
run: |
86+
BASE_VERSION=$(cat base-version.txt)
87+
COMMIT_SHA=$(git rev-parse --short HEAD)
88+
NEW_VERSION="$BASE_VERSION-$COMMIT_SHA"
89+
echo "New version: $NEW_VERSION"
90+
echo "version=$NEW_VERSION" >> $GITHUB_ENV
91+
working-directory: src/couponservice
92+
93+
- name: Run Docker Maven Build
94+
run: |
95+
docker compose -f compose.yml up -d mvn-coupon
96+
docker wait mvn-coupon
97+
working-directory: src
98+
99+
- name: Print Docker Images and Containers
100+
run: |
101+
docker images
102+
docker ps -a
103+
pwd
104+
ls -la
105+
working-directory: src
106+
107+
- name: Run Docker App
108+
run: |
109+
docker compose ps
110+
docker compose -f compose.yml up -d coupon-app
111+
working-directory: src
112+
113+
- name: Tag Docker Image
114+
run: |
115+
docker tag src-coupon-app:latest whoajitpatil/couponservice:latest
116+
docker tag src-coupon-app:latest whoajitpatil/couponservice:${{ env.version }}
117+
working-directory: src
118+
119+
- name: Docker login
120+
uses: docker/login-action@v3
121+
with:
122+
username: whoajitpatil
123+
password: ${{ secrets.DOCKER_PASSWORD }}
124+
125+
- name: Push Docker Image
126+
run: |
127+
docker push whoajitpatil/couponservice:latest
128+
docker push whoajitpatil/couponservice:${{ env.version }}
129+
working-directory: src

.github/workflows/coupon-ci-pr.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- main
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 0
13+
14+
- name: Set up JDK 17
15+
uses: actions/setup-java@v4
16+
with:
17+
distribution: 'adopt'
18+
java-version: '17'
19+
server-id: github
20+
settings-path: ${{ github.workspace }}
21+
22+
- name: Run Commands
23+
run: |
24+
java -version
25+
mvn -version
26+
docker --version
27+
terraform --version
28+
echo "PWD: ${pwd}"
29+
echo "GITHUB_WORKSPACE: ${GITHUB_WORKSPACE}"
30+
31+
- name: Start PostgreSQL
32+
run: docker compose -f compose.yml up -d web-db
33+
working-directory: src
34+
35+
- name: Cache SonarCloud packages
36+
uses: actions/cache@v3
37+
with:
38+
path: ~/.sonar/cache
39+
key: ${{ runner.os }}-sonar
40+
restore-keys: ${{ runner.os }}-sonar
41+
42+
- name: Cache Maven packages
43+
uses: actions/cache@v3
44+
with:
45+
path: ~/.m2
46+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
47+
restore-keys: ${{ runner.os }}-m2
48+
49+
- name: Build with Maven
50+
run: mvn -B clean install
51+
working-directory: src/couponservice
52+
53+
- name: Run Tests
54+
run: mvn test
55+
working-directory: src/couponservice
56+
57+
# Run SonarCloud analysis
58+
- name: Build and analyze with SonarCloud
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
62+
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=cyberlysafe_java-springboot-microservices
63+
working-directory: src/couponservice

.github/workflows/coupon-ci.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/couponservice/base-version.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.0

src/couponservice/docker/service/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN mkdir /app && \
1010

1111
USER 1000
1212

13-
COPY --chown=1000:1000 couponservice/target/couponservice-0.0.1-SNAPSHOT.jar /app/app.jar
13+
COPY --chown=1000:1000 couponservice/target/couponservice-4.1.0-SNAPSHOT.jar /app/app.jar
1414
WORKDIR /app
1515

1616
EXPOSE 8090

src/couponservice/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
</parent>
1111
<groupId>com.ideas.springcloud</groupId>
1212
<artifactId>couponservice</artifactId>
13-
<version>0.0.1-SNAPSHOT</version>
13+
<version>4.1.0-SNAPSHOT</version>
1414
<name>couponservice</name>
15-
<description>Demo project for Spring Boot</description>
15+
<description>Coupon project for Spring Boot</description>
1616
<properties>
1717
<java.version>17</java.version>
1818
<sonar.organization>cyberlysafe</sonar.organization>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.0

0 commit comments

Comments
 (0)