Skip to content

Commit 7b610fb

Browse files
committed
update the deployment.yml: add jar creation and pushing docker image
1 parent ee8d644 commit 7b610fb

File tree

1 file changed

+82
-56
lines changed

1 file changed

+82
-56
lines changed

.github/workflows/main.yml

Lines changed: 82 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,85 @@
1+
name: Java CI/CD with Docker
12
on:
2-
push:
3-
branches:
4-
- main
5-
pull_request:
6-
branches:
7-
- main
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
87

98
jobs:
10-
test:
11-
runs-on: ubuntu-latest
12-
steps:
13-
- uses: actions/checkout@v4
14-
15-
- name: Setup JDK 21
16-
uses: actions/setup-java@v4
17-
with:
18-
distribution: temurin
19-
java-version: "21"
20-
cache: maven
21-
22-
- name: Run tests
23-
run: mvn test
24-
25-
build:
26-
runs-on: ubuntu-latest
27-
needs: test
28-
steps:
29-
- uses: actions/checkout@v4
30-
31-
- name: Setup JDK 21
32-
uses: actions/setup-java@v4
33-
with:
34-
distribution: temurin
35-
java-version: "21"
36-
cache: maven
37-
38-
- name: Build JAR
39-
run: mvn package
40-
41-
build-docker-image:
42-
runs-on: ubuntu-latest
43-
needs: [build]
44-
steps:
45-
- uses: actions/checkout@v4
46-
47-
- name: Log in to Docker Hub
48-
uses: docker/login-action@v3
49-
with:
50-
username: ${{ secrets.DOCKER_HUB_USERNAME }}
51-
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN}}
52-
53-
- name: Build and push Docker image
54-
uses: docker/build-push-action@v5
55-
with:
56-
context: .
57-
file: ./Dockerfile
58-
push: true
59-
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/aws-integration:latest
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Set up JDK 21
15+
uses: actions/setup-java@v4
16+
with:
17+
distribution: temurin
18+
java-version: "21"
19+
cache: maven
20+
21+
- name: Run unit tests
22+
run: mvn test
23+
24+
build:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Set up JDK 21
30+
uses: actions/setup-java@v4
31+
with:
32+
distribution: temurin
33+
java-version: "21"
34+
cache: maven
35+
36+
- name: Compile project
37+
run: mvn compile
38+
39+
package-jar:
40+
runs-on: ubuntu-latest
41+
needs: [test, build]
42+
steps:
43+
- uses: actions/checkout@v4
44+
45+
- name: Set up JDK 21
46+
uses: actions/setup-java@v4
47+
with:
48+
distribution: temurin
49+
java-version: "21"
50+
cache: maven
51+
52+
- name: Package JAR
53+
run: mvn package -DskipTests
54+
55+
- name: Upload build artifact
56+
uses: actions/upload-artifact@v4
57+
with:
58+
name: app-jar
59+
path: target/aws-integration-0.0.1-SNAPSHOT.jar
60+
61+
build-docker-image:
62+
runs-on: ubuntu-latest
63+
needs: [package-jar]
64+
steps:
65+
- uses: actions/checkout@v4
66+
67+
- name: Download built jar
68+
uses: actions/download-artifact@v4
69+
with:
70+
name: app-jar
71+
path: target
72+
73+
- name: Log in to Docker Hub
74+
uses: docker/login-action@v3
75+
with:
76+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
77+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
78+
79+
- name: Build Docker image
80+
uses: docker/build-push-action@v5
81+
with:
82+
context: .
83+
file: ./Dockerfile
84+
push: true
85+
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/aws-integration:latest

0 commit comments

Comments
 (0)